-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjs.go
More file actions
81 lines (65 loc) · 1.35 KB
/
js.go
File metadata and controls
81 lines (65 loc) · 1.35 KB
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
package webview
import (
"embed"
_ "embed"
"fmt"
"net/url"
"strings"
)
//go:embed init.js
var EF embed.FS
func (w *webview) initJSFunc() {
js, _ := EF.ReadFile("init.js")
w.Init(string(js))
w.Bind("open", func(s string) {
if !strings.Contains(s, "http") {
u, err := url.Parse(w.GetUrl())
if err == nil {
s = fmt.Sprintf("%s://%s/%s", u.Scheme, u.Host, s)
}
}
w.Navigate(s)
})
w.Bind("getUrl", func(s string) {
w.data["url"] = s
})
w.Bind("getHtml", func(s string) {
w.data["html"] = s
})
w.Bind("getPageTitle", func(s string) {
w.data["title"] = s
})
w.Bind("move", func(x, y int) {
w.Move(x, y)
})
w.Bind("contentState", func(s string) {
if events.handle_cs != nil {
for _, f := range events.handle_cs {
f(s)
}
}
})
type DResult struct {
Id string `json:"id,omitempty"`
V bool `json:"v,omitempty"`
}
w.Bind("getDraggebleData", func() (res []DResult) {
w.DraggableElements.Range(func(key, value any) bool {
r := DResult{Id: key.(string), V: value.(bool)}
res = append(res, r)
return true
})
return res
})
w.Bind("delDraggebleElement", func(id string) {
w.DraggableElements.Delete(id)
})
w.Bind("getDraggebleElementValue", func(id string) bool {
if v, ok := w.DraggableElements.Load(id); !ok {
return false
} else {
return v.(bool)
}
})
//w.Bind("setCookie")
}