Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
disable hash based functionality when hashListeningEnabled is false F…
Browse files Browse the repository at this point in the history
…ixes #5445
  • Loading branch information
johnbender committed Jan 16, 2013
1 parent d02e044 commit 40fb7d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
13 changes: 11 additions & 2 deletions js/events/navigate.js
Expand Up @@ -17,8 +17,17 @@ define([ "jquery", "./../jquery.mobile.ns", "./../jquery.mobile.support" ], func

originalEventName: undefined,

// If pushstate support is present and push state support is defined to
// be true on the mobile namespace.
isPushStateEnabled: function() {
return $.support.pushState && $.mobile && $.mobile.pushStateEnabled;
return $.support.pushState &&
$.mobile.pushStateEnabled === true &&
this.isHashChangeEnabled();
},

// !! assumes mobile namespace is present
isHashChangeEnabled: function() {
return $.mobile.hashListeningEnabled === true;
},

// TODO a lot of duplication between popstate and hashchange
Expand Down Expand Up @@ -92,7 +101,7 @@ define([ "jquery", "./../jquery.mobile.ns", "./../jquery.mobile.support" ], func
if( self.isPushStateEnabled() ) {
self.originalEventName = "popstate";
$win.bind( "popstate.navigate", self.popstate );
} else {
} else if ( self.isHashChangeEnabled() ){
self.originalEventName = "hashchange";
$win.bind( "hashchange.navigate", self.hashchange );
}
Expand Down
12 changes: 8 additions & 4 deletions js/navigation/navigator.js
Expand Up @@ -239,11 +239,12 @@ define(["jquery",
// TODO add a check here that `hashchange.navigate` is bound already otherwise it's
// broken (exception?)
hashchange: function( event ) {
var history = this.history, hash = path.parseLocation().hash;
var history, hash;

// If pushstate is supported the state will be included in the popstate event
// data and appended to the navigate event. Late check here for late settings (eg tests)
if( $.event.special.navigate.isPushStateEnabled() ) {
// If hashchange listening is explicitly disabled or pushstate is supported
// avoid making use of the hashchange handler.
if(!$.event.special.navigate.isHashChangeEnabled() ||
$.event.special.navigate.isPushStateEnabled() ) {
return;
}

Expand All @@ -255,6 +256,9 @@ define(["jquery",
return;
}

history = this.history;
hash = path.parseLocation().hash;

// If this is a hashchange caused by the back or forward button
// make sure to set the state of our history stack properly
this.history.direct({
Expand Down

0 comments on commit 40fb7d8

Please sign in to comment.