-
Notifications
You must be signed in to change notification settings - Fork 23
/
node.go
116 lines (94 loc) · 3.48 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package godom
// This file implements Node interface
// https://developer.mozilla.org/en-US/docs/Web/API/Node
// Properties
// https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes
func (o *Object) ChildNodes() []*Object {
nodeList := o.Get("childNodes")
length := nodeList.Get("length").Int()
var nodes []*Object
for i := 0; i < length; i++ {
nodes = append(nodes, &Object{nodeList.Call("item", i)})
}
return nodes
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/firstChild
func (o *Object) FirstChild() *Object {
return &Object{o.Get("firstChild")}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/lastChild
func (o *Object) LastChild() *Object {
return &Object{o.Get("lastChild")}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nextSibling
func (o *Object) NextSibling() *Object {
return &Object{o.Get("nextSibling")}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
func (o *Object) NodeType() int {
return o.Get("nodeType").Int()
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue
func (o *Object) NodeValue() string {
return o.Get("nodeValue").String()
}
func (o *Object) SetNodeValue(s string) {
o.Set("nodeValue", s)
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/parentNode
func (o *Object) ParentNode() *Object {
return &Object{o.Get("parentNode")}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
// Returns the textual content of an element and all its descendants.
func (o *Object) TextContent() string {
return o.Get("textContent").String()
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
// Sets the textual content of an element and all its descendants.
func (o *Object) SetTextContent(s string) {
o.Set("textContent", s)
}
// Methods
// https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
func (o *Object) AppendChild(c *Object) *Object {
return &Object{o.Call("appendChild", c)}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/contains
func (o *Object) Contains(n *Object) bool {
return o.Call("contains", n).Bool()
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/hasChildNodes
func (o *Object) HasChildNodes() bool {
return o.Call("hasChildNodes").Bool()
}
// Inserts the first Node given in a parameter immediately before the second,
// child of this element, Node.
// https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
func (o *Object) InsertBefore(newNode, referenceNode *Object) *Object {
return &Object{o.Call("insertBefore", newNode, referenceNode)}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/isEqualNode
func (o *Object) IsEqualNode(n *Object) bool {
return o.Call("isEqualNode", n).Bool()
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/isSameNode
func (o *Object) IsSameNode(n *Object) bool {
return o.Call("isSameNode", n).Bool()
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/lookupPrefix
func (o *Object) LookupPrefix() string {
return o.Call("lookupPrefix").String()
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/normalize
func (o *Object) Normalize() {
o.Call("normalize")
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild
func (o *Object) RemoveChild(c *Object) *Object {
return &Object{o.Call("removeChild", c)}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Node/replaceChild
func (o *Object) ReplaceChild(newChild, oldChild *Object) *Object {
return &Object{o.Call("replaceChild", newChild, oldChild)}
}