Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added hashListeningEnabled global flag. This is meant as a global con…

…fig option for end users to disable hashchange listening (as opposed to urlHistory.listeningEnabled, which is an internal toggle). Unit test included. Fixes #748
commit 3162428558efd9960739ef8f00a7ead0dbf6d3ec 1 parent 3b5b615
scottjehl authored
View
5 js/jquery.mobile.core.js
@@ -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
View
7 js/jquery.mobile.navigation.js
@@ -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; }
View
15 tests/unit/navigation/navigation_core.js
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.