-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.go
105 lines (87 loc) · 3.61 KB
/
js.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
package magic
type AnimateArgs struct {
Keyframes []AnimationKeyframe `json:"keyframes"`
Options AnimateOptions `json:"options,omitempty"`
Duration int `json:"duration,omitempty"`
}
type AnimationKeyframe map[string]string
type AnimateOptions struct {
Delay int `json:"delay,omitempty"`
Direction string `json:"direction,omitempty"`
Duration int `json:"duration,omitempty"`
Easing string `json:"easing,omitempty"`
EndDelay int `json:"endDelay,omitempty"`
Fill string `json:"fill,omitempty"`
IterationStart float64 `json:"iterationStart,omitempty"`
Iterations string `json:"iterations,omitempty"`
Composite string `json:"composite,omitempty"`
IterationComposite string `json:"iterationComposite,omitempty"`
PseudoElement string `json:"pseudoElement,omitempty"`
}
type ScrollIntoViewArgs struct {
Options ScrollIntoViewOptions `json:"options,omitempty"`
AlignToTop bool `json:"alignToTop,omitempty"`
}
type ScrollIntoViewOptions struct {
Behavior string `json:"behavior,omitempty"`
Block string `json:"block,omitempty"`
Inline string `json:"inline,omitempty"`
}
// Sends the reload event to the given socket, the reload is not a full reload, instead its a websocket reconnect
func Reload(s Socket) {
s.DispatchEvent(NavigateEvent, s.Request().URL.String())
}
// Sends a navigation event to the given socket, the navigate is a live navigation
func Navigate(s Socket, location string) {
s.DispatchEvent(NavigateEvent, location)
}
// Calls the reset() function for the given ids (if no id is given it uses the id of the socket)
func Reset(s Socket, ids ...string) {
s.DispatchEvent(ResetEvent, ids)
}
// Calls the click() function for the given ids (if no id is given it uses the id of the socket)
func Click(s Socket, ids ...string) {
s.DispatchEvent(ClickEvent, ids)
}
// Calls the blur() function for the given ids (if no id is given it uses the id of the socket)
func Blur(s Socket, ids ...string) {
s.DispatchEvent(ClickEvent, ids)
}
// Calls the focus() function for the given ids (if no id is given it uses the id of the socket)
func Focus(s Socket, ids ...string) {
s.DispatchEvent(FocusEvent, ids)
}
// Enters the fullscreen mode of the window
func OpenFullscreen(s Socket) {
s.DispatchEvent(OpenFullscreenEvent, nil)
}
// Leaves the fullscreen mode of the window
func CloseFullscreen(s Socket) {
s.DispatchEvent(CloseFullscreenEvent, nil)
}
// Calls the animate(keyframes, options) function for the given ids (if no id is given it uses the id of the socket)
func Animate(s Socket, args AnimateArgs, ids ...string) {
s.DispatchEvent(AnimateEvent, struct {
Args AnimateArgs `json:"args"`
Ids []string `json:"ids"`
}{args, ids})
}
// Calls the scrollIntoView(options) function for the given ids (if no id is given it uses the id of the socket)
func ScrollIntoView(s Socket, args ScrollIntoViewArgs, ids ...string) {
s.DispatchEvent(AnimateEvent, struct {
Args ScrollIntoViewArgs `json:"args"`
Ids []string `json:"ids"`
}{args, ids})
}
// Disconnects the socket from the client side. It wont reconnect afterwards
func Disconnect(s Socket) {
s.DispatchEvent(DisconnectEvent, nil)
}
// UpdateURL changes the clients url to the request url without navigating
func UpdateURL(s Socket) {
s.DispatchEvent(UpdateURLEvent, urlToStringWithoutSchemeAndHost(s.Request().URL))
}
// RefreshFile reloads a img, script, favicon or source element (every element with a "src" attribute)
func RefreshFile(s Socket, ids ...string) {
s.DispatchEvent(RefreshFileEvent, ids)
}