-
Notifications
You must be signed in to change notification settings - Fork 16
/
rackt_history.javascript.txt
87 lines (67 loc) · 6.17 KB
/
rackt_history.javascript.txt
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
RACKT_HISTORY
RACKT-HISTORY ==> ##Version 1.17.0
##Abstracts WINDOW.location|history:
## - for legacy browsers
## - for environment without DOM (e.g. unit testing, native apps)
/=+===============================+=\
/ : : \
)==: BASE :==(
\ :_______________________________: /
\=+===============================+=/
RACKTHISTORY.createHistory([CONF])->RHISTORY ##Base function. CONF must provide:
## - go(INT)
## - getCurrentLocation()->RLOCATION
##Below are children of RACKTHISTORY.createHistory, that uses different implementations.
RACKTHISTORY.createBrowserHistory([CONF]) ##Uses WINDOW.location|history and WINDOW.onpopstate
RACKTHISTORY.createHashHistory([CONF]) ##Uses WINDOW.location.hash and WINDOW.onhashchange
##For legacy browsers.
RACKTHISTORY.createMemoryHistory([CONF]) ##Keeps state in memory.
##Works without DOM (e.g. unit testing, native apps)
##CONF:
## - entries 'PATH'[_ARR]: initial history
ENHANCER(RACKTHISTORY.createHistory) ##Returns createHistory but with some extra features
/=+===============================+=\
/ : : \
)==: HISTORY :==(
\ :_______________________________: /
\=+===============================+=/
RHISTORY.push|replace(RLOCATION|'URL') ##Adds history entry
##Do not do anything if same location
RHISTORY.go(INT) ##
RHISTORY.goBack|Forward() ##
RHISTORY.listen(FUNC(RLOCATION))->unlisten() ##Fired on location change
RHISTORY.listenBefore(FUNC(RLCTON))->unlisten()##Fired before location change
##Return false to prevent change
##Return STR to fire CONF.getUserConfirmation(STR, FUNC(BOOL))
##(def for DOMHistory: FUNC(WINDOW.confirm(STR)))
RHISTORY.listenBeforeUnload ##Wrapper around WINDOW.onbeforeunload
(FUNC()->STR)->unlisten() ##Must use ENHANCER RACKTHISTORY.useBeforeUnload
/=+===============================+=\
/ : : \
)==: LOCATION :==(
\ :_______________________________: /
\=+===============================+=/
RHISTORY.createPath|Href(RLOCATION)->URL ##
RHISTORY.createLocation
('URL'[, STATE])->RLOCATION ##
RLOCATION.key ##ID
RLOCATION.pathname ##'PATH'
RLOCATION.search ##'?...'
RLOCATION.query ##Like RLOCATION.search but as OBJ
##Must use ENHANCER RACKTHISTORY.useQueries
##Can specify CONF:
## - parseQueryString(STR)->OBJ
## - stringifyQuery(OBJ)->STR
##Def use QUERY-STRING module, which is simple (no nesting)
RLOCATION.hash ##'#...'
##To get scrolling behavior, must use ENHANCER from SCROLL-BEHAVIOR (0.3.0) among:
## - useScrollToTop: always to top
## - useSimpleScroll: to top on new location, to hash on back. Does not always work well
## - useStandardScroll: to hash, by listening to scroll changes.
RLOCATION.action ##'PUSH|REPLACE|POP'
RLOCATION.state ##VAL (JSON serializable)
CONF.basename ##Specify a base URL (def: <base href>)
##Must use ENHANCER RACKTHISTORY.useBasename
RLOCATION.basename ##RLOCATION.pathname does not include it