@@ -35,27 +35,27 @@ define(['jquery'], function($) {
35
35
36
36
fn = {
37
37
init : function ( ) {
38
- $ ( document ) . on ( 'click' , '.js-use-pushstate' , handlers . doc_click ) ;
39
- $ ( window ) . on ( 'popstate' , handlers . popstate ) . on ( 'pushstate' , handlers . pushstate ) ;
38
+ $ ( document ) . on ( 'click' , '.js-use-pushstate, .js-simulate-pushstate ' , handlers . doc_click ) ;
39
+ $ ( window ) . on ( 'popstate' , handlers . popstate ) . on ( 'pushstate' , handlers . pushstate ) . on ( 'simulate-pushstate' , handlers . simulate_pushstate ) ;
40
40
o . app . events . on ( 'app.featuresInitialized' , handlers . features_initialized ) ;
41
- fn . statechange ( window . location ) ;
41
+ if ( o . use_hash ) {
42
+ fn . statechange ( window . location . hash ) ;
43
+ } else {
44
+ fn . statechange ( window . location . pathname ) ;
45
+ }
42
46
} ,
43
- statechange : function ( href ) {
47
+ statechange : function ( pathname ) {
44
48
var i , path_components , position ;
45
49
46
- if ( o . use_hash && href . hash ) {
47
- path_components = PushstateHelper . get_path_components ( href . hash ) ;
48
- } else {
49
- path_components = PushstateHelper . get_path_components ( href . pathname ) ;
50
- }
50
+ path_components = PushstateHelper . get_path_components ( pathname ) ;
51
51
52
52
// push the state change to Google Analytics
53
53
if ( window . _gaq ) {
54
- _gaq . push ( [ '_trackPageview' , href ] ) ;
54
+ _gaq . push ( [ '_trackPageview' , pathname ] ) ;
55
55
}
56
56
57
57
o . app . events . trigger ( 'navigationEvent:Pushstate' , {
58
- location : href ,
58
+ path : pathname ,
59
59
components : path_components
60
60
} ) ;
61
61
} ,
@@ -70,31 +70,42 @@ define(['jquery'], function($) {
70
70
//fn.statechange(window.location);
71
71
} ,
72
72
doc_click : function ( e , d ) {
73
+ var _href ;
73
74
e . preventDefault ( ) ;
74
- if ( o . use_hash ) {
75
- window . location . hash = $ ( this ) . attr ( 'HREF' ) ;
75
+ _href = $ ( this ) . attr ( 'HREF' ) ;
76
+ if ( ! $ ( this ) . hasClass ( 'js-simulate-pushstate' ) ) {
77
+ if ( o . use_hash ) {
78
+ window . location . hash = _href ;
79
+ fn . statechange ( window . location . hash ) ;
80
+ } else {
81
+ history . pushState ( null , null , _href ) ;
82
+ fn . statechange ( window . location . pathname ) ;
83
+ }
84
+
76
85
} else {
77
- history . pushState ( null , null , $ ( this ) . attr ( 'HREF' ) ) ;
86
+ fn . statechange ( _href ) ;
78
87
}
79
- fn . statechange ( window . location ) ;
80
88
} ,
81
89
popstate : function ( e , d ) {
82
90
fn . statechange ( window . location ) ;
83
91
} ,
84
92
pushstate : function ( e , d ) {
85
93
if ( o . use_hash ) {
86
- if ( window . location . hash = = d . pathname ) {
87
- return ;
94
+ if ( window . location . hash ! = d . pathname ) {
95
+ window . location . hash = d . pathname ;
88
96
}
89
- window . location . hash = d . pathname ;
90
97
} else {
91
- if ( window . location . pathname = = d . pathname ) {
92
- return ;
98
+ if ( window . location . pathname ! = d . pathname ) {
99
+ history . pushState ( null , null , d . pathname ) ;
93
100
}
94
- history . pushState ( null , null , d . pathname ) ;
95
101
}
96
102
if ( ! d . prevent_propagation ) {
97
- fn . statechange ( d ) ;
103
+ fn . statechange ( d . pathname ) ;
104
+ }
105
+ } ,
106
+ simulate_pushstate : function ( e , d ) {
107
+ if ( ! d . prevent_propagation ) {
108
+ fn . statechange ( d . pathname ) ;
98
109
}
99
110
}
100
111
} ;
0 commit comments