Permalink
Browse files

[navigation] Handle corner case where first visited page has a dialog…

… hash key - Fixes: #4423
  • Loading branch information...
1 parent ca698fc commit e6092d82adb79e3f7c77c590955bed8aa3dbba61 @gabrielschulhof gabrielschulhof committed May 28, 2012
Showing with 41 additions and 17 deletions.
  1. +38 −16 js/jquery.mobile.navigation.js
  2. +3 −1 js/jquery.mobile.popup.js
@@ -308,7 +308,7 @@ define( [
directHashChange: function( opts ) {
var back , forward, newActiveIndex, prev = this.getActive();
- // check if url isp in history and if it's ahead or behind current page
+ // check if url is in history and if it's ahead or behind current page
$.each( urlHistory.stack, function( i, historyEntry ) {
//if the url is in the stack, it's a forward or a back
@@ -1389,6 +1389,14 @@ define( [
//transition is false if it's the first page, undefined otherwise (and may be overridden by default)
transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined,
+ originalCondition = ( urlHistory.stack.length > 1 && to.indexOf( $.mobile.dialogHashKey ) > -1 ),
+ destinationIsFirstPageUrl = ( to === $.mobile.dialogHashKey || to.replace( $.mobile.dialogHashKey, "" ) === ( urlHistory.stack[0] || { url: "" } ).url ),
+ activeEntryHasHashKey = ( ( urlHistory.getActive() || { url: "" } ).url.indexOf( $.mobile.dialogHashKey ) > -1 ),
+ activePageIsDialog = ( $.mobile.activePage ? $.mobile.activePage.is( ".ui-dialog" ) : false ),
+ specialCaseForDialogs = ( urlHistory.activeIndex === 1 && urlHistory.firstVisitedPageHasDialogHash && destinationIsFirstPageUrl )
+ ? ( activeEntryHasHashKey && !activePageIsDialog )
+ : originalCondition,
+
// default options for the changPage calls made after examining the current state
// of the page and the hash
changePageOptions = {
@@ -1397,29 +1405,21 @@ define( [
fromHashChange: true
};
+ // Record the fact that the first visited page has a dialogHashKey
+ if ( urlHistory.stack.length === 0 && to.indexOf( dialogHashKey ) > -1 ) {
+ urlHistory.firstVisitedPageHasDialogHash = true;
+ }
+
//if listening is disabled (either globally or temporarily), or it's a dialog hash
if( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) {
urlHistory.ignoreNextHashChange = false;
return;
}
// special case for dialogs
- if( urlHistory.stack.length > 1 && to.indexOf( dialogHashKey ) > -1 ) {
+ if( specialCaseForDialogs ) {
- // If current active page is not a dialog skip the dialog and continue
- // in the same direction
- if(!$.mobile.activePage.is( ".ui-dialog" )) {
- //determine if we're heading forward or backward and continue accordingly past
- //the current dialog
- urlHistory.directHashChange({
- currentUrl: to,
- isBack: function() { window.history.back(); },
- isForward: function() { window.history.forward(); }
- });
-
- // prevent changePage()
- return;
- } else {
+ if( activePageIsDialog ) {
// if the current active page is a dialog and we're navigating
// to a dialog use the dialog objected saved in the stack
urlHistory.directHashChange({
@@ -1442,6 +1442,28 @@ define( [
}
});
}
+ // If current active page is not a dialog skip the dialog and continue
+ // in the same direction
+ else {
+ //determine if we're heading forward or backward and continue accordingly past
+ //the current dialog
+
+ if ( urlHistory.activeIndex === 1 &&
+ urlHistory.firstVisitedPageHasDialogHash &&
+ destinationIsFirstPageUrl ) {
+ urlHistory.activeIndex = 0;
+ }
+ else {
+ urlHistory.directHashChange({
+ currentUrl: to,
+ isBack: function() { window.history.back(); },
+ isForward: function() { window.history.forward(); }
+ });
+ }
+
+ // prevent changePage()
+ return;
+ }
}
//if to is defined, load it
@@ -382,7 +382,9 @@ define( [ "jquery",
});
if ( $.mobile.hashListeningEnabled ) {
var activeEntry = $.mobile.urlHistory.getActive(),
- hasHash = ( activeEntry.url.indexOf( $.mobile.dialogHashKey ) > -1 );
+ hasHash =
+ ( !( $.mobile.urlHistory.firstVisitedPageHasDialogHash && $.mobile.urlHistory.activeIndex === 0 ) ||
+ ( activeEntry.url.indexOf( $.mobile.dialogHashKey ) > -1 ) );
function realInstallListener() {
$( window ).one( "hashchange.popup", function() {

0 comments on commit e6092d8

Please sign in to comment.