Skip to content

Commit a7a1167

Browse files
author
Gabriel Schulhof
committed
[navigation] Simplifying the code and adding comments
1 parent e2e7bc5 commit a7a1167

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

js/jquery.mobile.navigation.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,13 +1389,28 @@ define( [
13891389
//transition is false if it's the first page, undefined otherwise (and may be overridden by default)
13901390
transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined,
13911391

1392-
originalCondition = ( urlHistory.stack.length > 1 && to.indexOf( $.mobile.dialogHashKey ) > -1 ),
1393-
destinationIsFirstPageUrl = ( to === $.mobile.dialogHashKey || to.replace( $.mobile.dialogHashKey, "" ) === ( urlHistory.stack[0] || { url: "" } ).url ),
13941392
activeEntryHasHashKey = ( ( urlHistory.getActive() || { url: "" } ).url.indexOf( $.mobile.dialogHashKey ) > -1 ),
13951393
activePageIsDialog = ( $.mobile.activePage ? $.mobile.activePage.is( ".ui-dialog" ) : false ),
1396-
specialCaseForDialogs = ( urlHistory.activeIndex === 1 && urlHistory.firstVisitedPageHasDialogHash && destinationIsFirstPageUrl )
1397-
? ( activeEntryHasHashKey && !activePageIsDialog )
1398-
: originalCondition,
1394+
1395+
// Definition of the corner case where the initial page has a dialog hash key and we're going to it
1396+
dstIsDialogHashInitialPage =
1397+
( urlHistory.activeIndex === 1 &&
1398+
urlHistory.firstVisitedPageHasDialogHash &&
1399+
// Does the hash point to the first page? There are two ways that it can:
1400+
// 1. When the initial page URL has the form:
1401+
// http://domain/path/to/file.html#&ui-state=dialog
1402+
( to === $.mobile.dialogHashKey ||
1403+
// 2. When the initial page URL has the form:
1404+
// http://domain/path/to/file.html#/path/to/another/file.html#&ui-state=dialog
1405+
to.replace( $.mobile.dialogHashKey, "" ) === ( urlHistory.stack[0] || { url: "" } ).url ) ),
1406+
1407+
// Decide whether we need to apply the special logic that deals with dialogs
1408+
specialCaseForDialogs =
1409+
dstIsDialogHashInitialPage
1410+
// Decide for the corner case where the initial page has a dialog hash in the URL
1411+
? ( activeEntryHasHashKey && !activePageIsDialog )
1412+
// Decide for the general case
1413+
: ( urlHistory.stack.length > 1 && to.indexOf( $.mobile.dialogHashKey ) > -1 ),
13991414

14001415
// default options for the changPage calls made after examining the current state
14011416
// of the page and the hash
@@ -1448,9 +1463,7 @@ define( [
14481463
//determine if we're heading forward or backward and continue accordingly past
14491464
//the current dialog
14501465

1451-
if ( urlHistory.activeIndex === 1 &&
1452-
urlHistory.firstVisitedPageHasDialogHash &&
1453-
destinationIsFirstPageUrl ) {
1466+
if ( dstIsDialogHashInitialPage ) {
14541467
urlHistory.activeIndex = 0;
14551468
}
14561469
else {

0 commit comments

Comments
 (0)