Skip to content
This repository
Browse code

[popup] Reuse dialog hash if already present, and tack on another if …

…it is part of the initial hash -- Fixes #4994
  • Loading branch information...
commit 8b52631375b112992c44f8acf4448de6a1c861e2 1 parent 446fed7
Gabriel "_|Nix|_" Schulhof authored September 17, 2012

Showing 1 changed file with 22 additions and 10 deletions. Show diff stats Hide diff stats

  1. 32  js/widgets/popup.js
32  js/widgets/popup.js
@@ -574,7 +574,7 @@ define( [ "jquery",
574 574
 				/* TODO:
575 575
 				The native browser on Android 4.0.X ("Ice Cream Sandwich") suffers from an issue where the popup overlay appears to be z-indexed
576 576
 				above the popup itself when certain other styles exist on the same page -- namely, any element set to `position: fixed` and certain
577  
-				types of input. These issues are reminiscent of previously uncovered bugs in older versions of Androids native browser:
  577
+				types of input. These issues are reminiscent of previously uncovered bugs in older versions of Android's native browser:
578 578
 				https://github.com/scottjehl/Device-Bugs/issues/3
579 579
 
580 580
 				This fix closes the following bugs ( I use "closes" with reluctance, and stress that this issue should be revisited as soon as possible ):
@@ -690,7 +690,7 @@ define( [ "jquery",
690 690
 		// TODO no clear deliniation of what should be here and
691 691
 		// what should be in _open. Seems to be "visual" vs "history" for now
692 692
 		open: function( options ) {
693  
-			var self = this, opts = this.options, url, hashkey, activePage;
  693
+			var self = this, opts = this.options, url, hashkey, activePage, currentIsDialog, hasHash, urlHistory;
694 694
 
695 695
 			// make sure open is idempotent
696 696
 			if( $.mobile.popup.active ) {
@@ -702,7 +702,7 @@ define( [ "jquery",
702 702
 
703 703
 			// if history alteration is disabled close on navigate events
704 704
 			// and leave the url as is
705  
-			if( !opts.history ) {
  705
+			if( !( opts.history && $.mobile.hashListeningEnabled ) ) {
706 706
 				self._open( options );
707 707
 				self._bindContainerClose();
708 708
 
@@ -725,29 +725,41 @@ define( [ "jquery",
725 725
 			// cache some values for min/readability
726 726
 			hashkey = $.mobile.dialogHashKey;
727 727
 			activePage = $.mobile.activePage;
  728
+			currentIsDialog = activePage.is( ".ui-dialog" );
  729
+			url = $.mobile.urlHistory.getActive().url;
  730
+			hasHash = ( url.indexOf( hashkey ) > -1 ) && !currentIsDialog;
  731
+			urlHistory = $.mobile.urlHistory;
728 732
 
729  
-			// NOTE I'm not 100% that this is the right place to get the default url
730  
-			url = activePage.jqmData( "url" );
  733
+			if ( hasHash ) {
  734
+				self._open( options );
  735
+				self._bindContainerClose();
  736
+				return;
  737
+			}
731 738
 
732 739
 			// if the current url has no dialog hash key proceed as normal
733 740
 			// otherwise, if the page is a dialog simply tack on the hash key
734  
-			if ( url.indexOf( hashkey ) === -1 && !activePage.is( ".ui-dialog" ) ){
  741
+			if ( url.indexOf( hashkey ) === -1 && !currentIsDialog ){
735 742
 				url = url + hashkey;
736 743
 			} else {
737 744
 				url = $.mobile.path.parseLocation().hash + hashkey;
738 745
 			}
739 746
 
  747
+			// Tack on an extra hashkey if this is the first page and we've just reconstructed the initial hash
  748
+			if ( urlHistory.activeIndex === 0 && url === urlHistory.initialDst ) {
  749
+				url += hashkey;
  750
+			}
  751
+
740 752
 			// swallow the the initial navigation event, and bind for the next
741 753
 			opts.container.one( opts.navigateEvents, function( e ) {
742 754
 				e.preventDefault();
743  
-				self._bindContainerClose();
744  
-
745  
-				// forward the options on to the visual open
746 755
 				self._open( options );
  756
+				self._bindContainerClose();
747 757
 			});
748 758
 
  759
+			urlHistory.ignoreNextHashChange = currentIsDialog;
  760
+
749 761
 			// Gotta love methods with 1mm args :(
750  
-			$.mobile.urlHistory.addNew( url, undefined, undefined, undefined, "dialog" );
  762
+			urlHistory.addNew( url, undefined, undefined, undefined, "dialog" );
751 763
 
752 764
 			// set the new url with (or without) the new dialog hash key
753 765
 			$.mobile.path.set( url );

0 notes on commit 8b52631

John Bender

I thought we added this in _create, eg

this.options.history = this.options.history && $.mobile.hashListeningEnabled;
John Bender

We should be tacking on an extra dialog hash key in the case where it's a popup opening from a dialog. This looks like it prevents that explicitly.

Gabriel "_|Nix|_" Schulhof

No, because hasHash is false if currentIsDialog is true. Check line 730 above.

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