-
Notifications
You must be signed in to change notification settings - Fork 0
/
Document.go
54 lines (48 loc) · 1.13 KB
/
Document.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
package pkg
import "syscall/js"
//Represents a Document of Javascript
type DocumentDOM struct {
doc js.Value
}
//Create a new DocumentDOM
// //Example:
// myDocument := NewDocumentDOM()
func NewDocumentDOM() *DocumentDOM {
return &DocumentDOM{
doc: js.Global().Get("document"),
}
}
//Wrapper of document.getElementById() with alias
/*
//Example:
myInfo := Document.GetByID("myInfo")
*/
func (d *DocumentDOM) GetById(id string) *ObjectDOM {
doc := js.Global().Get("document")
body := doc.Call("getElementById", id)
if body.IsNull() || body.IsUndefined() {
return nil
}
p90 := ObjectDOM{
object: body,
}
p90.Listener = NewEventListener(&p90)
return &p90
}
//Wrapper of document.appendChild()
// //Example:
// Document.AppendChild(myObjectDOM)
func (d *DocumentDOM) AppendChild(ele *ObjectDOM) {
d.doc.Get("body").Call("appendChild", ele.object)
}
// Wrapper of document.createElement()
// //Example:
// myInfo := Document.Create(H1)
func (d *DocumentDOM) Create(typeOfElement string) *ObjectDOM {
eleNew := d.doc.Call("createElement", typeOfElement)
P := &ObjectDOM{
object: eleNew,
}
P.Listener = NewEventListener(P)
return P
}