This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
/
navigate.js
66 lines (56 loc) · 1.9 KB
/
navigate.js
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
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: placeholder
//>>label: AJAX Navigation System
//>>group: Navigation
// TODO break out pushstate support test so we don't depend on the whole thing
define([ "jquery",
"./../../jquery.mobile.support" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {
var $win = $( window ), self, history;
$.event.special.navigate = self = {
bound: false,
// TODO use the originalEvent property on the event object
// instead of from
popstate: function( event ) {
var state = event.originalEvent.state;
// NOTE the `|| {}` is there to ensure consistency between
// the popstate navigate event and the hashchange navigate
// event data
$win.trigger( new $.Event( "navigate" ), {
from: "popstate",
state: state || {}
});
},
// TODO use the originalEvent property on the event object
// instead of from
hashchange: function( event, data ) {
// Trigger the hashchange with state provided by the user
// that altered the hash
$win.trigger( new $.Event( "navigate" ), {
from: "hashchange",
// Users that want to fully normalize the two events
// will need to do history management down the stack and
// add the state to the event before this binding is fired
state: event.hashchangeState || {}
});
},
// TODO We really only want to set this up once
// but I'm not clear if there's a beter way to achieve
// this with the jQuery special event structure
setup: function( data, namespaces ) {
if( self.bound ) {
return;
}
self.bound = true;
if( $.support.pushState ) {
$win.bind( "popstate.navigate", self.popstate );
} else {
$win.bind( "hashchange.navigate", self.hashchange );
}
}
};
})( jQuery );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");