From 851fad0debfbc50deb47d96d6d03de9257aa6756 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Wed, 18 Apr 2012 14:09:52 +0300 Subject: [PATCH 1/2] [navigation] Keep urlHistory in sync with browser history even when moving to/from a #&ui-state=dialog link via Back/Forward buttons --- js/jquery.mobile.navigation.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index fbc119e0e3b..c1a2dd23c38 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -1003,6 +1003,16 @@ define( [ if( fromPage && fromPage[0] === toPage[0] && !settings.allowSamePageTransition ) { isPageTransitioning = false; mpc.trigger( "pagechange", triggerData ); + + // Even if there is no page change to be done, we should keep the urlHistory in sync with the hash changes + if( settings.fromHashChange ) { + urlHistory.directHashChange({ + currentUrl: url, + isBack: function() {}, + isForward: function() {} + }); + } + return; } From 358f7de7d7429fca11b7050e281954bbdbe08559 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Thu, 19 Apr 2012 16:17:12 +0300 Subject: [PATCH 2/2] [navigation] Do not change hash nor add history entry when displaying a dialog at a history entry that already has dialogHashKey -- Fixes: #2656 --- js/jquery.mobile.navigation.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index c1a2dd23c38..23ce0ccbe17 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -1044,6 +1044,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. @@ -1052,6 +1055,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; } @@ -1079,7 +1093,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 ); }