centralized the hashchange fired flag

This commit is contained in:
scottjehl 2011-08-14 10:20:14 -04:00
parent 854ce44179
commit 0512916e72

View file

@ -27,10 +27,15 @@
dialog = "&ui-state",
// Cache window
$win = $( window );
$win = $( window ),
// Flag for tracking if a Hashchange naturally occurs after each popstate + replace
hashchangeFired = false;
$win.bind( "hashchange replacehash", function( e ) {
hashchangeFired = true;
if( $.support.pushState ){
var hash = location.hash || "#" + initialFilePath,
href = hash.replace( "#", "" );
@ -56,17 +61,13 @@
history.replaceState( e.originalEvent.state, e.originalEvent.state.title, initialFilePath + e.originalEvent.state.hash );
// Urls that reference subpages will fire their own hashchange, so we don't want to trigger 2 in that case.
var fired = false;
$win.bind( "hashchange.popstatetest", function(){
fired = true;
});
hashchangeFired = false;
setTimeout(function(){
$win.unbind( "hashchange.popstatetest" );
if( !fired ) {
if( !hashchangeFired ) {
$win.trigger( "hashchange" );
}
hashchangeFired = false;
}, 0);
}
@ -77,7 +78,7 @@
$win.trigger( "replacehash" );
// Enable pushstate listening *after window onload
// to ignore the initial pop that Chrome calls at onload
// To ignore the initial pop that Chrome calls at onload
$win.load(function(){
setTimeout(function(){
popListeningEnabled = true;