forked from neelance/go-angularjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.go
53 lines (40 loc) · 1.17 KB
/
jquery.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
package angularjs
import "github.com/gopherjs/gopherjs/js"
type JQueryElement struct{
*js.Object `ajs-service:"element"`
}
func ElementById(id string) *JQueryElement {
return &JQueryElement{js.Global.Get("angular").Call("element", js.Global.Get("document").Call("getElementById", id))}
}
func (e *JQueryElement) Text() string {
return e.Call("text").String()
}
func (e *JQueryElement) SetText(val string) {
e.Call("text", val)
}
func (e *JQueryElement) Prop(name string) *js.Object {
return e.Call("prop", name)
}
func (e *JQueryElement) SetProp(name, value interface{}) {
e.Call("prop", name, value)
}
func (e *JQueryElement) On(events string, handler func(*Event)) {
e.Call("on", events, func(e *js.Object) {
handler(&Event{Object: e})
})
}
func (e *JQueryElement) Attr(name string) *js.Object {
return e.Call("attr", name)
}
func (e *JQueryElement) SetAttr(name string, value interface{}) {
e.Call("attr", name, value)
}
func (e *JQueryElement) Val() *js.Object {
return e.Call("val")
}
func (e *JQueryElement) SetVal(value interface{}) {
e.Call("val", value)
}
func (e *JQueryElement) Watch(prop string, cb interface{}) {
e.Call("scope").Call("$watch", prop, cb)
}