This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
routeInfo.go
executable file
·89 lines (74 loc) · 1.99 KB
/
routeInfo.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
package router
import (
"github.com/gascore/gas"
)
func (ctx *Ctx) CustomPush(path string, replace bool) {
if ctx.Settings.GetUserConfirmation != nil && ctx.Settings.GetUserConfirmation() {
return
}
ctx.ChangeRoute(path, replace)
ctx.This.update()
}
func (ctx *Ctx) CustomPushDynamic(name string, params, queries gas.Map, replace bool) {
ctx.CustomPush(ctx.fillPath(name, params, queries), replace)
}
// Push push user to another page
func (ctx *Ctx) Push(path string) {
ctx.CustomPush(path, false)
}
// Replace replace current page
func (ctx *Ctx) Replace(path string) {
ctx.CustomPush(path, true)
}
// PushDynamic push user to another route with params and queries
func (ctx *Ctx) PushDynamic(name string, params, queries gas.Map) {
ctx.CustomPushDynamic(name, params, queries, false)
}
// ReplaceDynamic replace current page with page generated from name, params and queries
func (ctx *Ctx) ReplaceDynamic(name string, params, queries gas.Map) {
ctx.CustomPushDynamic(name, params, queries, true)
}
func (ctx Ctx) link(path string, push func(gas.Event), e gas.External) *gas.Element {
var attrs gas.Map
if e.Attrs == nil {
attrs = make(gas.Map)
} else {
attrs = e.Attrs()
}
attrs["href"] = ctx.Settings.BaseName + path
beforePush := func(event gas.Event) {
push(event)
event.Call("preventDefault")
}
return gas.NE(
&gas.E{
Tag: "a",
Attrs: func() gas.Map {
return attrs
},
Handlers: map[string]gas.Handler{
"click": beforePush,
"keyup.13": beforePush,
"keyup.32": beforePush,
},
},
e.Body...)
}
// Link create link to route
func (ctx *Ctx) Link(to string, e gas.External) *gas.Element {
return ctx.link(
to,
func(e gas.Event) {
ctx.Push(to)
},
e)
}
//LinkWithParams create link to route with queries and params
func (ctx *Ctx) LinkWithParams(name string, params, queries gas.Map, e gas.External) *gas.Element {
return ctx.link(
ctx.fillPath(name, params, queries),
func(e gas.Event) {
ctx.PushDynamic(name, params, queries)
},
e)
}