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
This commit is contained in:
parent
0d0ea3a11e
commit
7b3dcfde20
1 changed files with 14 additions and 0 deletions
|
|
@ -171,8 +171,11 @@ type
|
||||||
nodeType*: NodeType
|
nodeType*: NodeType
|
||||||
nodeValue*: cstring
|
nodeValue*: cstring
|
||||||
parentNode*: Node
|
parentNode*: Node
|
||||||
|
content*: Node
|
||||||
previousSibling*: Node
|
previousSibling*: Node
|
||||||
|
ownerDocument*: Document
|
||||||
innerHTML*: cstring
|
innerHTML*: cstring
|
||||||
|
outerHTML*: cstring
|
||||||
innerText*: cstring
|
innerText*: cstring
|
||||||
textContent*: cstring
|
textContent*: cstring
|
||||||
style*: Style
|
style*: Style
|
||||||
|
|
@ -1042,6 +1045,7 @@ when defined(nodejs):
|
||||||
result = cast[Element](x.childNodes[idx])
|
result = cast[Element](x.childNodes[idx])
|
||||||
|
|
||||||
var document* = Document(nodeType: DocumentNode)
|
var document* = Document(nodeType: DocumentNode)
|
||||||
|
document.ownerDocument = document
|
||||||
|
|
||||||
proc getElem(x: Element; id: cstring): Element =
|
proc getElem(x: Element; id: cstring): Element =
|
||||||
if x.id == id: return x
|
if x.id == id: return x
|
||||||
|
|
@ -1055,6 +1059,7 @@ when defined(nodejs):
|
||||||
|
|
||||||
proc appendChild*(parent, n: Node) =
|
proc appendChild*(parent, n: Node) =
|
||||||
n.parentNode = parent
|
n.parentNode = parent
|
||||||
|
n.ownerDocument = parent.ownerDocument
|
||||||
parent.childNodes.add n
|
parent.childNodes.add n
|
||||||
|
|
||||||
proc replaceChild*(parent, newNode, oldNode: Node) =
|
proc replaceChild*(parent, newNode, oldNode: Node) =
|
||||||
|
|
@ -1101,6 +1106,12 @@ when defined(nodejs):
|
||||||
result.nodeValue = identifier
|
result.nodeValue = identifier
|
||||||
result.nodeType = NodeType.TextNode
|
result.nodeType = NodeType.TextNode
|
||||||
|
|
||||||
|
proc createComment*(d: Document, data: cstring): Node =
|
||||||
|
new(result)
|
||||||
|
result.nodeName = "#comment"
|
||||||
|
result.nodeValue = data
|
||||||
|
result.nodeType = NodeType.CommentNode
|
||||||
|
|
||||||
else:
|
else:
|
||||||
proc len*(x: Node): int {.importcpp: "#.childNodes.length".}
|
proc len*(x: Node): int {.importcpp: "#.childNodes.length".}
|
||||||
proc `[]`*(x: Node; idx: int): Element {.importcpp: "#.childNodes[#]".}
|
proc `[]`*(x: Node; idx: int): Element {.importcpp: "#.childNodes[#]".}
|
||||||
|
|
@ -1112,6 +1123,7 @@ else:
|
||||||
proc getElementById*(d: Document, id: cstring): Element {.importcpp.}
|
proc getElementById*(d: Document, id: cstring): Element {.importcpp.}
|
||||||
proc createElement*(d: Document, identifier: cstring): Element {.importcpp.}
|
proc createElement*(d: Document, identifier: cstring): Element {.importcpp.}
|
||||||
proc createTextNode*(d: Document, identifier: cstring): Node {.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 setTimeout*(action: proc(); ms: int): Timeout {.importc, nodecl.}
|
||||||
proc clearTimeout*(t: 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 scrollIntoView*(n: Node)
|
||||||
proc setAttribute*(n: Node, name, value: cstring)
|
proc setAttribute*(n: Node, name, value: cstring)
|
||||||
proc setAttributeNode*(n: Node, attr: Node)
|
proc setAttributeNode*(n: Node, attr: Node)
|
||||||
|
proc querySelector*(n: Node, selectors: cstring): Element
|
||||||
|
proc querySelectorAll*(n: Node, selectors: cstring): seq[Element]
|
||||||
|
|
||||||
# Document "methods"
|
# Document "methods"
|
||||||
proc captureEvents*(d: Document, eventMask: int) {.deprecated.}
|
proc captureEvents*(d: Document, eventMask: int) {.deprecated.}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue