Skip to content

Commit c6ef3af

Browse files
committed
Merge pull request jquery-archive#4117 from gabrielschulhof/fix-dialog-double-hash-try2
Fix dialog double hash try2
2 parents c64c1a4 + 358f7de commit c6ef3af

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

js/jquery.mobile.navigation.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,16 @@ define( [
10031003
if( fromPage && fromPage[0] === toPage[0] && !settings.allowSamePageTransition ) {
10041004
isPageTransitioning = false;
10051005
mpc.trigger( "pagechange", triggerData );
1006+
1007+
// Even if there is no page change to be done, we should keep the urlHistory in sync with the hash changes
1008+
if( settings.fromHashChange ) {
1009+
urlHistory.directHashChange({
1010+
currentUrl: url,
1011+
isBack: function() {},
1012+
isForward: function() {}
1013+
});
1014+
}
1015+
10061016
return;
10071017
}
10081018

@@ -1034,6 +1044,9 @@ define( [
10341044
}
10351045
} catch(e) {}
10361046

1047+
// 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
1048+
var alreadyThere = false;
1049+
10371050
// If we're displaying the page as a dialog, we don't want the url
10381051
// for the dialog content to be used in the hash. Instead, we want
10391052
// to append the dialogHashKey to the url of the current page.
@@ -1042,6 +1055,17 @@ define( [
10421055
// be an empty string. Moving the undefined -> empty string back into
10431056
// urlHistory.addNew seemed imprudent given undefined better represents
10441057
// the url state
1058+
1059+
// If we are at a place in history that once belonged to a dialog, reuse
1060+
// this state without adding to urlHistory and without modifying the hash.
1061+
// However, if a dialog is already displayed at this point, and we're
1062+
// about to display another dialog, then we must add another hash and
1063+
// history entry on top so that one may navigate back to the original dialog
1064+
if ( active.url.indexOf( dialogHashKey ) > -1 && !$.mobile.activePage.is( ".ui-dialog" ) ) {
1065+
settings.changeHash = false;
1066+
alreadyThere = true;
1067+
}
1068+
10451069
url = ( active.url || "" ) + dialogHashKey;
10461070
}
10471071

@@ -1069,7 +1093,7 @@ define( [
10691093
|| ( isDialog ? $.mobile.defaultDialogTransition : $.mobile.defaultPageTransition );
10701094

10711095
//add page to history stack if it's not back or forward
1072-
if( !historyDir ) {
1096+
if( !historyDir && !alreadyThere ) {
10731097
urlHistory.addNew( url, settings.transition, pageTitle, pageUrl, settings.role );
10741098
}
10751099

0 commit comments

Comments
 (0)