-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathelement.go
78 lines (65 loc) · 2.43 KB
/
element.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
package godom
// This file implements Element interface
// https://developer.mozilla.org/en-US/docs/Web/API/Element
// Properties
func (o *Object) ClassList() *DOMTokenList {
return &DOMTokenList{o.Get("classList")}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML
func (o *Object) InnerHTML() string {
return o.Get("innerHTML").String()
}
func (o *Object) SetInnerHTML(html string) {
o.Set("innerHTML", html)
}
// https://developer.mozilla.org/en-US/docs/Web/API/Element/outerHTML
func (o *Object) OuterHTML() string {
return o.Get("outerHTML").String()
}
func (o *Object) SetOuterHTML(html string) {
o.Set("outerHTML", html)
}
// https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName
func (o *Object) TagName() string {
return o.Get("tagName").String()
}
// Methods
// Call HasAttribute to check if the attribute exists or not before using this
// method (GetAttribute). FIXME: Return (string, bool) to indicate the existence
// of the attribute?
// https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute
func (o *Object) GetAttribute(attributeName string) string {
return o.Call("getAttribute", attributeName).String()
}
// https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute
func (o *Object) HasAttribute(attributeName string) bool {
return o.Call("hasAttribute", attributeName).Bool()
}
// https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
func (o *Object) GetBoundingClientRect() *DOMRect {
return &DOMRect{o.Call("getBoundingClientRect")}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagName
func (o *Object) GetElementsByTagName(tagName string) []*Object {
nodeList := o.Call("getElementsByTagName", tagName)
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/Element/querySelector
func (o *Object) QuerySelector(selectors string) *Object {
return &Object{o.Call("querySelector", selectors)}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll
func (o *Object) QuerySelectorAll(selectors string) []*Object {
nodeList := o.Call("querySelectorAll", selectors)
length := nodeList.Get("length").Int()
var nodes []*Object
for i := 0; i < length; i++ {
nodes = append(nodes, &Object{nodeList.Call("item", i)})
}
return nodes
}