mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-27 01:24:41 +00:00
fix the chrome bug and reduce the number of crazy hash juggles we do
This commit is contained in:
parent
328d58b2e9
commit
82cce1fa60
2 changed files with 41 additions and 26 deletions
|
|
@ -275,7 +275,7 @@
|
|||
},
|
||||
|
||||
directHashChange: function( opts ) {
|
||||
var back , forward, newActiveIndex;
|
||||
var back , forward, newActiveIndex, prev = this.getActive();
|
||||
|
||||
// check if url isp in history and if it's ahead or behind current page
|
||||
$.each( urlHistory.stack, function( i, historyEntry ) {
|
||||
|
|
@ -293,9 +293,9 @@
|
|||
this.activeIndex = newActiveIndex !== undefined ? newActiveIndex : this.activeIndex;
|
||||
|
||||
if( back ) {
|
||||
opts.isBack();
|
||||
opts.isBack( prev, back );
|
||||
} else if( forward ) {
|
||||
opts.isForward();
|
||||
opts.isForward( prev, back );
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -1185,12 +1185,17 @@
|
|||
});
|
||||
} );
|
||||
|
||||
//hashchange event handler
|
||||
$window.bind( "hashchange", function( e, triggered ) {
|
||||
$.mobile.handleHashChange = function( hash ) {
|
||||
//find first page via hash
|
||||
var role, to = path.stripHash( location.hash ),
|
||||
var reverse, role, to = path.stripHash( hash ),
|
||||
//transition is false if it's the first page, undefined otherwise (and may be overridden by default)
|
||||
transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined;
|
||||
transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined,
|
||||
|
||||
changePageOptions = {
|
||||
transition: transition,
|
||||
changeHash: false,
|
||||
fromHashChange: true
|
||||
};
|
||||
|
||||
//if listening is disabled (either globally or temporarily), or it's a dialog hash
|
||||
if( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) {
|
||||
|
|
@ -1215,10 +1220,13 @@
|
|||
// prevent changepage
|
||||
return;
|
||||
} else {
|
||||
var setTo = function() {
|
||||
var setTo = function( previousPage, isBack ) {
|
||||
var active = $.mobile.urlHistory.getActive();
|
||||
|
||||
to = active.pageUrl;
|
||||
role = active.role;
|
||||
transition = active.transition;
|
||||
reverse = isBack;
|
||||
};
|
||||
// if the current active page is a dialog and we're navigating
|
||||
// to a dialog use the dialog objected saved in the stack
|
||||
|
|
@ -1229,12 +1237,17 @@
|
|||
//if to is defined, load it
|
||||
if ( to ) {
|
||||
to = ( typeof to === "string" && !path.isPath( to ) ) ? ( '#' + to ) : to;
|
||||
$.mobile.changePage( to, { transition: transition, changeHash: false, fromHashChange: true , role: role} );
|
||||
$.mobile.changePage( to, { transition: transition, changeHash: false, fromHashChange: true , role: role, reverse: reverse } );
|
||||
}
|
||||
//there's no hash, go to the first page in the dom
|
||||
else {
|
||||
$.mobile.changePage( $.mobile.firstPage, { transition: transition, changeHash: false, fromHashChange: true, roll: rolle } );
|
||||
$.mobile.changePage( $.mobile.firstPage, { transition: transition, changeHash: false, fromHashChange: true, roll: roll, reverse: reverse } );
|
||||
}
|
||||
};
|
||||
|
||||
//hashchange event handler
|
||||
$window.bind( "hashchange", function( e, triggered ) {
|
||||
$.mobile.handleHashChange( location.hash );
|
||||
});
|
||||
|
||||
//set page min-heights to be device specific
|
||||
|
|
|
|||
|
|
@ -34,13 +34,20 @@
|
|||
};
|
||||
},
|
||||
|
||||
isSubHashPage: function( page ) {
|
||||
return page.is( "[role='dialog']" ) ||
|
||||
page.jqmData("url").indexOf( $.mobile.subPageUrlKey ) >= 0;
|
||||
},
|
||||
|
||||
resetUIKeys: function( url ) {
|
||||
var dialog = $.mobile.dialogHashKey,
|
||||
subkey = "&" + $.mobile.subPageUrlKey;
|
||||
|
||||
if( url.indexOf( dialog ) > -1 ) {
|
||||
url = url.split( dialog ).join( "#" + dialog );
|
||||
} else if( url.indexOf( subkey ) > -1 ) {
|
||||
var split = url.split( dialog );
|
||||
split.push( "" );
|
||||
url = split[0] + "#" + split.slice( 1, split.length ).join( dialog );
|
||||
} else if( url.indexOf( subkey ) > -1 ) {
|
||||
url = url.split( subkey ).join( "#" + subkey );
|
||||
}
|
||||
|
||||
|
|
@ -74,26 +81,21 @@
|
|||
// on popstate (ie back or forward) we need to replace the hash that was there previously
|
||||
// cleaned up by the additional hash handling
|
||||
onPopState: function( e ) {
|
||||
var poppedState = e.originalEvent.state;
|
||||
var poppedState = e.originalEvent.state, holdnexthashchange = false;
|
||||
|
||||
// if there's no state its not a popstate we care about, ie chrome's initial popstate
|
||||
// or forward popstate
|
||||
if( poppedState ) {
|
||||
// can't test the hash directly because the url has already been altered, possibly to
|
||||
// one without a hash, so we check if the page on display is one that would have
|
||||
// generated a hash
|
||||
if( self.isSubHashPage( $.mobile.activePage ) ){
|
||||
holdnexthashchange = true;
|
||||
}
|
||||
|
||||
// replace the current url with the equivelant hash so that the hashchange binding in vanilla nav
|
||||
// can do its thing one triggered below
|
||||
history.replaceState( poppedState, poppedState.title, poppedState.initialHref + poppedState.hash );
|
||||
$.mobile.handleHashChange( poppedState.hash );
|
||||
|
||||
// Urls that reference subpages will fire their own hashchange, so we don't want to trigger 2 in that case.
|
||||
self.hashchangeFired = false;
|
||||
|
||||
setTimeout(function() {
|
||||
if( !self.hashchangeFired ) {
|
||||
$win.trigger( "hashchange" );
|
||||
}
|
||||
|
||||
self.hashchangeFired = false;
|
||||
}, 0);
|
||||
$.mobile.urlHistory.ignoreNextHashChange = holdnexthashchange;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue