aboutsummaryrefslogtreecommitdiffstats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-04 00:32:41 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-04 00:38:20 +0100
commitb596687086048243728c58c906d680d21fe76d2c (patch)
tree5a3f232bd3660c95c8611625492f439e9f6ef570 /src/html
parentb45f0663bd6f88ceaf7b12ff50d66d4673b7bd0f (diff)
downloadchawan-b596687086048243728c58c906d680d21fe76d2c.tar.gz
dom: misc fixes
* parse XHR URL with document base URL * allow setting XHR responseType * add tagName, nodeName * make hasChildNodes a function * fix horribly broken insertNode
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 0e3b12bc..cce2d684 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -1078,7 +1078,7 @@ func ownerDocument(node: Node): Document {.jsfget.} =
return nil
return node.document
-func hasChildNodes(node: Node): bool {.jsfget.} =
+func hasChildNodes(node: Node): bool {.jsfunc.} =
return node.childList.len > 0
func len(collection: Collection): int =
@@ -1716,6 +1716,32 @@ func names(ctx: JSContext, map: NamedNodeMap): JSPropertyEnumList
func length(characterData: CharacterData): uint32 {.jsfget.} =
return uint32(characterData.data.utf16Len)
+func tagName(element: Element): string {.jsfget.} =
+ if element.namespace == Namespace.HTML:
+ return element.document.toStr(element.localName).toUpperAscii()
+ return element.document.toStr(element.localName)
+
+func nodeName(node: Node): string {.jsfget.} =
+ if node of Element:
+ return Element(node).tagName
+ if node of Attr:
+ let attr = Attr(node)
+ return attr.ownerElement.document.toStr(attr.data.qualifiedName)
+ if node of DocumentType:
+ return DocumentType(node).name
+ if node of CDATASection:
+ return "#cdata-section"
+ if node of Comment:
+ return "#comment"
+ if node of Document:
+ return "#document"
+ if node of DocumentFragment:
+ return "#document-fragment"
+ if node of ProcessingInstruction:
+ return ProcessingInstruction(node).target
+ assert node of Text
+ return "#text"
+
func scriptingEnabled*(document: Document): bool =
if document.window == nil:
return false
@@ -3266,7 +3292,7 @@ proc insertNode(parent, node, before: Node) =
node.index = parent.childList.high
else:
node.index = before.index
- for i in before.index ..< parent.childList.len - 1:
+ for i in countdown(parent.childList.high - 1, node.index):
parent.childList[i + 1] = parent.childList[i]
parent.childList[i + 1].index = i + 1
parent.childList[node.index] = node