mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-17 06:20:26 +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
|
|
@ -29,6 +29,9 @@
|
|||
|
||||
//automatically handle clicks and form submissions through Ajax, when same-domain
|
||||
ajaxEnabled: true,
|
||||
|
||||
//automatically load and show pages based on location.hash
|
||||
hashListeningEnabled: true,
|
||||
|
||||
// TODO: deprecated - remove at 1.0
|
||||
//automatically handle link clicks through Ajax, when possible
|
||||
|
|
@ -187,7 +190,7 @@
|
|||
$.mobile.pageLoading();
|
||||
|
||||
// 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 );
|
||||
}
|
||||
// otherwise, trigger a hashchange to load a deeplink
|
||||
|
|
|
|||
|
|
@ -117,7 +117,8 @@
|
|||
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
|
||||
listeningEnabled: true
|
||||
},
|
||||
|
|
@ -675,8 +676,8 @@
|
|||
//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;
|
||||
|
||||
//if listening is disabled, or it's a dialog hash
|
||||
if( urlHistory.listeningEnabled == false ||
|
||||
//if listening is disabled (either globally or temporarily), or it's a dialog hash
|
||||
if( !$.mobile.hashListeningEnabled || !urlHistory.listeningEnabled ||
|
||||
urlHistory.stack.length > 1 && to.indexOf( dialogHashKey ) > -1 && !$.mobile.activePage.is( ".ui-dialog" )
|
||||
){ return; }
|
||||
|
||||
|
|
|
|||
|
|
@ -147,8 +147,8 @@
|
|||
});
|
||||
|
||||
//url listening
|
||||
asyncTest( "ability to disable our hash change event listening", function(){
|
||||
$.mobile.urlHistory.listeningEnabled = false;
|
||||
function testListening( prop ){
|
||||
prop = false;
|
||||
var stillListening = false;
|
||||
$(document).bind("pagebeforehide", function(){
|
||||
stillListening = true;
|
||||
|
|
@ -156,9 +156,18 @@
|
|||
location.hash = "foozball";
|
||||
setTimeout(function(){
|
||||
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 = "";
|
||||
prop = true;
|
||||
}, 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);
|
||||
Loading…
Reference in a new issue