mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-05-19 12:01:06 +00:00
added hashListeningEnabled global flag. This is meant as a global config option for end users to disable hashchange listening (as opposed to urlHistory.listeningEnabled, which is an internal toggle). Unit test included. Fixes #748
This commit is contained in:
parent
3b5b615451
commit
3162428558
3 changed files with 20 additions and 7 deletions
|
|
@ -30,6 +30,9 @@
|
||||||
//automatically handle clicks and form submissions through Ajax, when same-domain
|
//automatically handle clicks and form submissions through Ajax, when same-domain
|
||||||
ajaxEnabled: true,
|
ajaxEnabled: true,
|
||||||
|
|
||||||
|
//automatically load and show pages based on location.hash
|
||||||
|
hashListeningEnabled: true,
|
||||||
|
|
||||||
// TODO: deprecated - remove at 1.0
|
// TODO: deprecated - remove at 1.0
|
||||||
//automatically handle link clicks through Ajax, when possible
|
//automatically handle link clicks through Ajax, when possible
|
||||||
ajaxLinksEnabled: true,
|
ajaxLinksEnabled: true,
|
||||||
|
|
@ -187,7 +190,7 @@
|
||||||
$.mobile.pageLoading();
|
$.mobile.pageLoading();
|
||||||
|
|
||||||
// if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM
|
// if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM
|
||||||
if( $.mobile.urlHistory.listeningEnabled == false || !$.mobile.path.stripHash( location.hash ) ){
|
if( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ){
|
||||||
$.mobile.changePage( $.mobile.firstPage, false, true, false, true );
|
$.mobile.changePage( $.mobile.firstPage, false, true, false, true );
|
||||||
}
|
}
|
||||||
// otherwise, trigger a hashchange to load a deeplink
|
// otherwise, trigger a hashchange to load a deeplink
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,8 @@
|
||||||
urlHistory.stack = urlHistory.stack.slice( 0, urlHistory.activeIndex + 1 );
|
urlHistory.stack = urlHistory.stack.slice( 0, urlHistory.activeIndex + 1 );
|
||||||
},
|
},
|
||||||
|
|
||||||
//enable/disable hashchange event listener
|
//enable/disable hashchange event listener internally
|
||||||
|
//for use in toggling temporarily, rather than disabling globally
|
||||||
//toggled internally when location.hash is updated to match the url of a successful page load
|
//toggled internally when location.hash is updated to match the url of a successful page load
|
||||||
listeningEnabled: true
|
listeningEnabled: true
|
||||||
},
|
},
|
||||||
|
|
@ -675,8 +676,8 @@
|
||||||
//transition is false if it's the first page, undefined otherwise (and may be overridden by default)
|
//transition is false if it's the first page, undefined otherwise (and may be overridden by default)
|
||||||
transition = $.mobile.urlHistory.stack.length === 0 ? false : undefined;
|
transition = $.mobile.urlHistory.stack.length === 0 ? false : undefined;
|
||||||
|
|
||||||
//if listening is disabled, or it's a dialog hash
|
//if listening is disabled (either globally or temporarily), or it's a dialog hash
|
||||||
if( urlHistory.listeningEnabled == false ||
|
if( !$.mobile.hashListeningEnabled || !urlHistory.listeningEnabled ||
|
||||||
urlHistory.stack.length > 1 && to.indexOf( dialogHashKey ) > -1 && !$.mobile.activePage.is( ".ui-dialog" )
|
urlHistory.stack.length > 1 && to.indexOf( dialogHashKey ) > -1 && !$.mobile.activePage.is( ".ui-dialog" )
|
||||||
){ return; }
|
){ return; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,8 +147,8 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
//url listening
|
//url listening
|
||||||
asyncTest( "ability to disable our hash change event listening", function(){
|
function testListening( prop ){
|
||||||
$.mobile.urlHistory.listeningEnabled = false;
|
prop = false;
|
||||||
var stillListening = false;
|
var stillListening = false;
|
||||||
$(document).bind("pagebeforehide", function(){
|
$(document).bind("pagebeforehide", function(){
|
||||||
stillListening = true;
|
stillListening = true;
|
||||||
|
|
@ -156,9 +156,18 @@
|
||||||
location.hash = "foozball";
|
location.hash = "foozball";
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
start();
|
start();
|
||||||
ok( $.mobile.urlHistory.listeningEnabled == stillListening, "urlHistory.listeningEnabled = false disables default hashchange event handler");
|
ok( prop == stillListening, "urlHistory.listeningEnabled = false disables default hashchange event handler");
|
||||||
location.hash = "";
|
location.hash = "";
|
||||||
|
prop = true;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
asyncTest( "ability to disable our hash change event listening internally", function(){
|
||||||
|
testListening( $.mobile.urlHistory.listeningEnabled );
|
||||||
|
});
|
||||||
|
|
||||||
|
asyncTest( "ability to disable our hash change event listening globally", function(){
|
||||||
|
testListening( $.mobile.hashListeningEnabled );
|
||||||
});
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
Loading…
Reference in a new issue