diff options
author | Mildred Ki'Lya <mildred@users.noreply.github.com> | 2020-05-22 14:34:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 14:34:20 +0200 |
commit | 7b3dcfde20e2cebdf5902a01e71c695ff7f507e8 (patch) | |
tree | 137b0835c8707e79c6ab63bd961519369e70b7ae /lib/js | |
parent | 0d0ea3a11ef0bb7d0d2f5dbd84782dee12810c2c (diff) | |
download | Nim-7b3dcfde20e2cebdf5902a01e71c695ff7f507e8.tar.gz |
Add missing attributes and methods to JavaScript DOM (#14428)
- content attribute to access HTML template element: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content - ownerDocument to access the owning document from a DOM Node: https://developer.mozilla.org/en-US/docs/Web/API/Node/ownerDocument - outerHTML to get/set the outer HTML representation of a Node: https://developer.mozilla.org/en-US/docs/Web/API/Node/ownerDocument - createComment() to create comment Nodes: https://developer.mozilla.org/en-US/docs/Web/API/Document/createComment - querySelector() and querySelectorAll() on Nodes: https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll
Diffstat (limited to 'lib/js')
-rw-r--r-- | lib/js/dom.nim | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/js/dom.nim b/lib/js/dom.nim index 950a5065b..d425b62c5 100644 --- a/lib/js/dom.nim +++ b/lib/js/dom.nim @@ -171,8 +171,11 @@ type nodeType*: NodeType nodeValue*: cstring parentNode*: Node + content*: Node previousSibling*: Node + ownerDocument*: Document innerHTML*: cstring + outerHTML*: cstring innerText*: cstring textContent*: cstring style*: Style @@ -1042,6 +1045,7 @@ when defined(nodejs): result = cast[Element](x.childNodes[idx]) var document* = Document(nodeType: DocumentNode) + document.ownerDocument = document proc getElem(x: Element; id: cstring): Element = if x.id == id: return x @@ -1055,6 +1059,7 @@ when defined(nodejs): proc appendChild*(parent, n: Node) = n.parentNode = parent + n.ownerDocument = parent.ownerDocument parent.childNodes.add n proc replaceChild*(parent, newNode, oldNode: Node) = @@ -1101,6 +1106,12 @@ when defined(nodejs): result.nodeValue = identifier result.nodeType = NodeType.TextNode + proc createComment*(d: Document, data: cstring): Node = + new(result) + result.nodeName = "#comment" + result.nodeValue = data + result.nodeType = NodeType.CommentNode + else: proc len*(x: Node): int {.importcpp: "#.childNodes.length".} proc `[]`*(x: Node; idx: int): Element {.importcpp: "#.childNodes[#]".} @@ -1112,6 +1123,7 @@ else: proc getElementById*(d: Document, id: cstring): Element {.importcpp.} proc createElement*(d: Document, identifier: cstring): Element {.importcpp.} proc createTextNode*(d: Document, identifier: cstring): Node {.importcpp.} + proc createComment*(d: Document, data: cstring): Node {.importcpp.} proc setTimeout*(action: proc(); ms: int): Timeout {.importc, nodecl.} proc clearTimeout*(t: Timeout) {.importc, nodecl.} @@ -1177,6 +1189,8 @@ proc replaceData*(n: Node, start, len: int, text: cstring) proc scrollIntoView*(n: Node) proc setAttribute*(n: Node, name, value: cstring) proc setAttributeNode*(n: Node, attr: Node) +proc querySelector*(n: Node, selectors: cstring): Element +proc querySelectorAll*(n: Node, selectors: cstring): seq[Element] # Document "methods" proc captureEvents*(d: Document, eventMask: int) {.deprecated.} |