Permalink
Browse files

[navigation] Do not change hash nor add history entry when displaying…

… a dialog at a history entry that already has dialogHashKey -- Fixes: #2656
  • Loading branch information...
1 parent 2343bf0 commit 4b2c62d3f05b87faadba08f94c48f24260b38424 @gabrielschulhof gabrielschulhof committed Apr 19, 2012
Showing with 15 additions and 1 deletion.
  1. +15 −1 js/jquery.mobile.navigation.js
@@ -1047,6 +1047,9 @@ define( [
}
} catch(e) {}
+ // Record whether we are at a place in history where a dialog used to be - if so, do not add a new history entry and do not change the hash either
+ var alreadyThere = false;
+
// If we're displaying the page as a dialog, we don't want the url
// for the dialog content to be used in the hash. Instead, we want
// to append the dialogHashKey to the url of the current page.
@@ -1055,6 +1058,17 @@ define( [
// be an empty string. Moving the undefined -> empty string back into
// urlHistory.addNew seemed imprudent given undefined better represents
// the url state
+
+ // If we are at a place in history that once belonged to a dialog, reuse
+ // this state without adding to urlHistory and without modifying the hash.
+ // However, if a dialog is already displayed at this point, and we're
+ // about to display another dialog, then we must add another hash and
+ // history entry on top so that one may navigate back to the original dialog
+ if ( active.url.indexOf( dialogHashKey ) > -1 && !$.mobile.activePage.is( ".ui-dialog" ) ) {
+ settings.changeHash = false;
+ alreadyThere = true;
+ }
+
url = ( active.url || "" ) + dialogHashKey;
}
@@ -1082,7 +1096,7 @@ define( [
|| ( isDialog ? $.mobile.defaultDialogTransition : $.mobile.defaultPageTransition );
//add page to history stack if it's not back or forward
- if( !historyDir ) {
+ if( !historyDir && !alreadyThere ) {
urlHistory.addNew( url, settings.transition, pageTitle, pageUrl, settings.role );
}

0 comments on commit 4b2c62d

Please sign in to comment.