@@ -18,7 +18,7 @@ define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ )
18
18
19
19
$ . extend ( $ . Navigator . prototype , {
20
20
squash : function ( url , data ) {
21
- var state , href ,
21
+ var state , href , self = this ,
22
22
hash = path . isPath ( url ) ? path . stripHash ( url ) : url ;
23
23
24
24
href = path . squash ( url ) ;
@@ -42,6 +42,19 @@ define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ )
42
42
// is not fired.
43
43
window . history . replaceState ( state , state . title || document . title , href ) ;
44
44
45
+
46
+ // If popstate is enabled and the browser triggers `popstate` events when the hash
47
+ // is set (this often happens immediately in browsers like Chrome), then the
48
+ // this flag will be set to false already. If it's a browser that does not trigger
49
+ // a `popstate` on hash assignement or `replaceState` then we need to unlock the
50
+ // At the time of this writing this happens with Opera 12
51
+ // NOTE I hate the fact that we have to do this but it captures all the possible
52
+ // issues with browsers that won't trigger a popstate in either case
53
+ // ie, hash assignment/replaceState
54
+ setTimeout ( function ( ) {
55
+ self . ignoreNextHashChange = false ;
56
+ } , 100 ) ;
57
+
45
58
return state ;
46
59
} ,
47
60
@@ -72,7 +85,7 @@ define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ )
72
85
73
86
// TODO reconsider name
74
87
go : function ( url , data , noEvents ) {
75
- var state , href , hash , popstateEvent ,
88
+ var state , href , hash , popstateEvent ;
76
89
isPopStateEvent = $ . event . special . navigate . isPushStateEnabled ( ) ;
77
90
78
91
// Get the url as it would look squashed on to the current resolution url
@@ -109,6 +122,8 @@ define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ )
109
122
} , data ) ;
110
123
111
124
if ( isPopStateEvent ) {
125
+
126
+
112
127
popstateEvent = new $ . Event ( "popstate" ) ;
113
128
popstateEvent . originalEvent = {
114
129
type : "popstate" ,
@@ -169,15 +184,13 @@ define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ )
169
184
// matches an existing history entry
170
185
if ( ! event . originalEvent . state ) {
171
186
hash = path . parseLocation ( ) . hash ;
172
- closestIndex = this . history . closest ( hash ) ;
173
- var index = this . history . activeIndex ;
174
187
active = this . history . getActive ( ) ;
175
188
176
189
// Avoid adding a history entry in two cases
177
190
// 1) on the initial hashchange
178
191
// 2) when the current history entry hash is identical to the
179
192
// current location hash
180
- if ( this . history . stack . length !== 1 || hash !== this . history . getActive ( ) . hash ) {
193
+ if ( this . history . stack . length !== 1 || hash !== active . hash ) {
181
194
state = $ . navigate . navigator . squash ( hash ) ;
182
195
// TODO it might be better to only add to the history stack
183
196
// when the hash is adjacent to the active history entry
@@ -229,24 +242,10 @@ define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ )
229
242
// with to alter the url to represent the new state do so here
230
243
if ( this . preventNextHashChange ) {
231
244
this . preventNextHashChange = false ;
232
- this . ignoreNextHashChange = false ;
233
245
event . stopImmediatePropagation ( ) ;
234
246
return ;
235
247
}
236
248
237
- // If the hashchange has been explicitly ignored or we have no history at
238
- // this point skip the history managment and the addition of the history
239
- // entry to the event for the `navigate` bindings
240
- if ( this . ignoreNextHashChange ) {
241
- this . ignoreNextHashChange = false ;
242
- }
243
-
244
- // If the stack is empty (it's been reset or some such) don't return,
245
- // we need to record it in the missing callback below.
246
- if ( this . ignoreNextHashChange && this . history . stack . length > 0 ) {
247
- return ;
248
- }
249
-
250
249
// If this is a hashchange caused by the back or forward button
251
250
// make sure to set the state of our history stack properly
252
251
this . history . direct ( {
0 commit comments