Skip to content
This repository
Browse code

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

… hash key - Fixes: #4423

Conflicts:

	js/jquery.mobile.popup.js
  • Loading branch information...
commit 52745d26bfd25bbe6f30c9ddabefe20338ea9fb6 1 parent 60c83ec
Gabriel "_|Nix|_" Schulhof authored May 28, 2012

Showing 1 changed file with 38 additions and 16 deletions. Show diff stats Hide diff stats

  1. 54  js/jquery.mobile.navigation.js
54  js/jquery.mobile.navigation.js
@@ -307,7 +307,7 @@ define( [
307 307
 			directHashChange: function( opts ) {
308 308
 				var back , forward, newActiveIndex, prev = this.getActive();
309 309
 
310  
-				// check if url isp in history and if it's ahead or behind current page
  310
+				// check if url is in history and if it's ahead or behind current page
311 311
 				$.each( urlHistory.stack, function( i, historyEntry ) {
312 312
 
313 313
 					//if the url is in the stack, it's a forward or a back
@@ -1363,6 +1363,14 @@ define( [
1363 1363
 				//transition is false if it's the first page, undefined otherwise (and may be overridden by default)
1364 1364
 				transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined,
1365 1365
 
  1366
+				originalCondition = ( urlHistory.stack.length > 1 && to.indexOf( $.mobile.dialogHashKey ) > -1 ),
  1367
+				destinationIsFirstPageUrl = ( to === $.mobile.dialogHashKey || to.replace( $.mobile.dialogHashKey, "" ) === ( urlHistory.stack[0] || { url: "" } ).url ),
  1368
+				activeEntryHasHashKey = ( ( urlHistory.getActive() || { url: "" } ).url.indexOf( $.mobile.dialogHashKey ) > -1 ),
  1369
+				activePageIsDialog = ( $.mobile.activePage ? $.mobile.activePage.is( ".ui-dialog" ) : false ),
  1370
+				specialCaseForDialogs = ( urlHistory.activeIndex === 1 && urlHistory.firstVisitedPageHasDialogHash && destinationIsFirstPageUrl )
  1371
+					? ( activeEntryHasHashKey && !activePageIsDialog )
  1372
+					: originalCondition,
  1373
+
1366 1374
 				// default options for the changPage calls made after examining the current state
1367 1375
 				// of the page and the hash
1368 1376
 				changePageOptions = {
@@ -1371,6 +1379,11 @@ define( [
1371 1379
 					fromHashChange: true
1372 1380
 				};
1373 1381
 
  1382
+			// Record the fact that the first visited page has a dialogHashKey
  1383
+			if ( urlHistory.stack.length === 0 && to.indexOf( dialogHashKey ) > -1 ) {
  1384
+				urlHistory.firstVisitedPageHasDialogHash = true;
  1385
+			}
  1386
+
1374 1387
 			//if listening is disabled (either globally or temporarily), or it's a dialog hash
1375 1388
 			if( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) {
1376 1389
 				urlHistory.ignoreNextHashChange = false;
@@ -1378,22 +1391,9 @@ define( [
1378 1391
 			}
1379 1392
 
1380 1393
 			// special case for dialogs
1381  
-			if( urlHistory.stack.length > 1 && to.indexOf( dialogHashKey ) > -1 ) {
  1394
+			if( specialCaseForDialogs ) {
1382 1395
 
1383  
-				// If current active page is not a dialog skip the dialog and continue
1384  
-				// in the same direction
1385  
-				if(!$.mobile.activePage.is( ".ui-dialog" )) {
1386  
-					//determine if we're heading forward or backward and continue accordingly past
1387  
-					//the current dialog
1388  
-					urlHistory.directHashChange({
1389  
-						currentUrl: to,
1390  
-						isBack: function() { window.history.back(); },
1391  
-						isForward: function() { window.history.forward(); }
1392  
-					});
1393  
-
1394  
-					// prevent changePage()
1395  
-					return;
1396  
-				} else {
  1396
+				if( activePageIsDialog ) {
1397 1397
 					// if the current active page is a dialog and we're navigating
1398 1398
 					// to a dialog use the dialog objected saved in the stack
1399 1399
 					urlHistory.directHashChange({
@@ -1416,6 +1416,28 @@ define( [
1416 1416
 						}
1417 1417
 					});
1418 1418
 				}
  1419
+				// If current active page is not a dialog skip the dialog and continue
  1420
+				// in the same direction
  1421
+				else {
  1422
+					//determine if we're heading forward or backward and continue accordingly past
  1423
+					//the current dialog
  1424
+
  1425
+					if ( urlHistory.activeIndex === 1 &&
  1426
+					     urlHistory.firstVisitedPageHasDialogHash &&
  1427
+					     destinationIsFirstPageUrl ) {
  1428
+						urlHistory.activeIndex = 0;
  1429
+					}
  1430
+					else {
  1431
+						urlHistory.directHashChange({
  1432
+							currentUrl: to,
  1433
+							isBack: function() { window.history.back(); },
  1434
+							isForward: function() { window.history.forward(); }
  1435
+						});
  1436
+					}
  1437
+
  1438
+					// prevent changePage()
  1439
+					return;
  1440
+				}
1419 1441
 			}
1420 1442
 
1421 1443
 			//if to is defined, load it

0 notes on commit 52745d2

Please sign in to comment.
Something went wrong with that request. Please try again.