This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
/
navigate_core.js
76 lines (60 loc) · 1.99 KB
/
navigate_core.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
67
68
69
70
71
72
73
74
75
76
$.testHelper.setPushState();
(function( $ ) {
module( "navigate", {
setup: function() {
location.hash = "";
}
});
asyncTest( "changes to the url trigger a navigate", function() {
$( window ).one( "navigate", function( event, data ) {
ok( true, "navigate called" );
start();
});
location.hash = "foo";
});
asyncTest( "traversing history back fires a navigate", function() {
expect( 2 );
$( window ).one( "navigate", function( event, data ) {
ok( true, "navigate called on hash change" );
$( window ).one( "navigate", function( event, data ) {
ok( true, "navigate called on back button" );
start();
});
window.history.back();
});
location.hash = "foo";
});
asyncTest( "navigation events are marked", function() {
$( window ).one( "navigate", function( event, data ) {
equal( event.originalEvent.type, $.support.pushState ? "popstate" : "hashchange", "tagged as popstate" );
start();
});
location.hash = "foo";
});
if( $.support.pushState ) {
asyncTest( "popstate navigation events contain pushed state", function() {
$( window ).one( "navigate", function( event, data ) {
$( window ).one( "navigate", function( event, data ) {
equal( data.state.foo, "bar", "state provided properly" );
start();
});
window.history.back();
});
window.history.replaceState({ foo: "bar" }, document.title, location.href.replace(/#.*/, "" ) + "#foo");
location.hash = "#foo2";
});
} else {
// Make sure the binding happends before any of the navigate bindings
$( window ).bind( "hashchange", function( event ) {
event.hashchangeState = { foo: "bar" };
});
asyncTest( "hashchange navigation provides for data added in a later binding", function() {
$( window ).one( "navigate", function( event, data ) {
equal( event.originalEvent.type, "hashchange", "event triggered by a hashchange" );
equal( data.state.foo, "bar", "state provided properly" );
start();
});
location.hash = "#foo2";
});
}
})( jQuery );