Skip to content

Commit 82cce1f

Browse files
committed
fix the chrome bug and reduce the number of crazy hash juggles we do
1 parent 328d58b commit 82cce1f

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

js/jquery.mobile.navigation.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
},
276276

277277
directHashChange: function( opts ) {
278-
var back , forward, newActiveIndex;
278+
var back , forward, newActiveIndex, prev = this.getActive();
279279

280280
// check if url isp in history and if it's ahead or behind current page
281281
$.each( urlHistory.stack, function( i, historyEntry ) {
@@ -293,9 +293,9 @@
293293
this.activeIndex = newActiveIndex !== undefined ? newActiveIndex : this.activeIndex;
294294

295295
if( back ) {
296-
opts.isBack();
296+
opts.isBack( prev, back );
297297
} else if( forward ) {
298-
opts.isForward();
298+
opts.isForward( prev, back );
299299
}
300300
},
301301

@@ -1185,12 +1185,17 @@
11851185
});
11861186
} );
11871187

1188-
//hashchange event handler
1189-
$window.bind( "hashchange", function( e, triggered ) {
1188+
$.mobile.handleHashChange = function( hash ) {
11901189
//find first page via hash
1191-
var role, to = path.stripHash( location.hash ),
1190+
var reverse, role, to = path.stripHash( hash ),
11921191
//transition is false if it's the first page, undefined otherwise (and may be overridden by default)
1193-
transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined;
1192+
transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined,
1193+
1194+
changePageOptions = {
1195+
transition: transition,
1196+
changeHash: false,
1197+
fromHashChange: true
1198+
};
11941199

11951200
//if listening is disabled (either globally or temporarily), or it's a dialog hash
11961201
if( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) {
@@ -1215,10 +1220,13 @@
12151220
// prevent changepage
12161221
return;
12171222
} else {
1218-
var setTo = function() {
1223+
var setTo = function( previousPage, isBack ) {
12191224
var active = $.mobile.urlHistory.getActive();
1225+
12201226
to = active.pageUrl;
12211227
role = active.role;
1228+
transition = active.transition;
1229+
reverse = isBack;
12221230
};
12231231
// if the current active page is a dialog and we're navigating
12241232
// to a dialog use the dialog objected saved in the stack
@@ -1229,12 +1237,17 @@
12291237
//if to is defined, load it
12301238
if ( to ) {
12311239
to = ( typeof to === "string" && !path.isPath( to ) ) ? ( '#' + to ) : to;
1232-
$.mobile.changePage( to, { transition: transition, changeHash: false, fromHashChange: true , role: role} );
1240+
$.mobile.changePage( to, { transition: transition, changeHash: false, fromHashChange: true , role: role, reverse: reverse } );
12331241
}
12341242
//there's no hash, go to the first page in the dom
12351243
else {
1236-
$.mobile.changePage( $.mobile.firstPage, { transition: transition, changeHash: false, fromHashChange: true, roll: rolle } );
1244+
$.mobile.changePage( $.mobile.firstPage, { transition: transition, changeHash: false, fromHashChange: true, roll: roll, reverse: reverse } );
12371245
}
1246+
};
1247+
1248+
//hashchange event handler
1249+
$window.bind( "hashchange", function( e, triggered ) {
1250+
$.mobile.handleHashChange( location.hash );
12381251
});
12391252

12401253
//set page min-heights to be device specific

js/jquery.mobile.navigation.pushstate.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,20 @@
3434
};
3535
},
3636

37+
isSubHashPage: function( page ) {
38+
return page.is( "[role='dialog']" ) ||
39+
page.jqmData("url").indexOf( $.mobile.subPageUrlKey ) >= 0;
40+
},
41+
3742
resetUIKeys: function( url ) {
3843
var dialog = $.mobile.dialogHashKey,
3944
subkey = "&" + $.mobile.subPageUrlKey;
4045

4146
if( url.indexOf( dialog ) > -1 ) {
42-
url = url.split( dialog ).join( "#" + dialog );
43-
} else if( url.indexOf( subkey ) > -1 ) {
47+
var split = url.split( dialog );
48+
split.push( "" );
49+
url = split[0] + "#" + split.slice( 1, split.length ).join( dialog );
50+
} else if( url.indexOf( subkey ) > -1 ) {
4451
url = url.split( subkey ).join( "#" + subkey );
4552
}
4653

@@ -74,26 +81,21 @@
7481
// on popstate (ie back or forward) we need to replace the hash that was there previously
7582
// cleaned up by the additional hash handling
7683
onPopState: function( e ) {
77-
var poppedState = e.originalEvent.state;
84+
var poppedState = e.originalEvent.state, holdnexthashchange = false;
7885

7986
// if there's no state its not a popstate we care about, ie chrome's initial popstate
8087
// or forward popstate
8188
if( poppedState ) {
89+
// can't test the hash directly because the url has already been altered, possibly to
90+
// one without a hash, so we check if the page on display is one that would have
91+
// generated a hash
92+
if( self.isSubHashPage( $.mobile.activePage ) ){
93+
holdnexthashchange = true;
94+
}
8295

83-
// replace the current url with the equivelant hash so that the hashchange binding in vanilla nav
84-
// can do its thing one triggered below
85-
history.replaceState( poppedState, poppedState.title, poppedState.initialHref + poppedState.hash );
86-
87-
// Urls that reference subpages will fire their own hashchange, so we don't want to trigger 2 in that case.
88-
self.hashchangeFired = false;
89-
90-
setTimeout(function() {
91-
if( !self.hashchangeFired ) {
92-
$win.trigger( "hashchange" );
93-
}
96+
$.mobile.handleHashChange( poppedState.hash );
9497

95-
self.hashchangeFired = false;
96-
}, 0);
98+
$.mobile.urlHistory.ignoreNextHashChange = holdnexthashchange;
9799
}
98100
},
99101

0 commit comments

Comments
 (0)