mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-05-25 14:33:43 +00:00
removed initial disable for spurious popstate and moved to doc ready init for late inclusion in the document instead of monkey patching
This commit is contained in:
parent
657f6b8c3f
commit
7d68059dd6
1 changed files with 10 additions and 19 deletions
|
|
@ -22,9 +22,6 @@
|
|||
|
||||
initialHref: url.hrefNoHash,
|
||||
|
||||
// Begin with popstate listening disabled, since it fires at onload in chrome
|
||||
popListeningEnabled: false,
|
||||
|
||||
// Flag for tracking if a Hashchange naturally occurs after each popstate + replace
|
||||
hashchangeFired: false,
|
||||
|
||||
|
|
@ -33,7 +30,7 @@
|
|||
hash: location.hash || "#" + self.initialFilePath,
|
||||
title: document.title,
|
||||
|
||||
// persiste across refresh
|
||||
// persist across refresh
|
||||
initialHref: self.initialHref
|
||||
};
|
||||
},
|
||||
|
|
@ -60,8 +57,14 @@
|
|||
|
||||
onPopState: function( e ) {
|
||||
var poppedState = e.originalEvent.state;
|
||||
if( self.popListeningEnabled && poppedState ) {
|
||||
history.replaceState( poppedState, poppedState.title, poppedState.initialHref + poppedState.hash );
|
||||
|
||||
// if there's no state its not a popstate we care about, ie chrome's initial popstate
|
||||
// or forward popstate
|
||||
if( poppedState ) {
|
||||
|
||||
// replace the current url with the equivelant hash so that the hashchange binding in vanilla nav
|
||||
// can load the page
|
||||
history.replaceState( poppedState, poppedState.title, poppedState.initialHref + 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;
|
||||
|
|
@ -86,20 +89,8 @@
|
|||
if ( location.hash === "" ) {
|
||||
history.replaceState( self.state(), document.title, location.href );
|
||||
}
|
||||
|
||||
// Enable pushstate listening *after window onload
|
||||
// To ignore the initial pop that Chrome calls at onload
|
||||
$win.load(function() {
|
||||
setTimeout(function() {
|
||||
self.popListeningEnabled = true;
|
||||
}, 0 );
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$.mobile._registerInternalEvents = function(){
|
||||
// Call previous function
|
||||
oldRegisterInternalEvents();
|
||||
pushStateHandler.init();
|
||||
};
|
||||
$( pushStateHandler.init );
|
||||
})( jQuery, this );
|
||||
Loading…
Reference in a new issue