Skip to content
This repository
Browse code

properly handle popups in dialogs, make sure dialog closes on page ch…

…anges
  • Loading branch information...
commit 242cf05850f45f8bf23b7373f6635394d9664f36 1 parent 9226d96
John Bender authored August 23, 2012

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

  1. 25  js/widgets/popup.js
25  js/widgets/popup.js
@@ -585,39 +585,44 @@ define( [ "jquery",
585 585
 
586 586
 
587 587
 		open: function( options ) {
  588
+			var hashkey = $.mobile.dialogHashKey,
  589
+				activePage = $.mobile.activePage;
  590
+
588 591
 			// make sure open is idempotent
589 592
 			if( $.mobile.popup.active ) {
590 593
 				return;
591 594
 			}
592 595
 
593  
-			var self = this, url = $.mobile.activePage.jqmData( "url" ), newUrl;
  596
+			var self = this, url = activePage.jqmData( "url" );
594 597
 
595 598
 			// if the current url has no dialog hash key proceed as normal
596 599
 			// otherwise, if the page is a dialog simply tack on the hash key
597  
-			if ( url.indexOf( $.mobile.dialogHashKey ) == -1 ) {
598  
-				newUrl = url + $.mobile.dialogHashKey;
599  
-			} else if ( $.mobile.activePage.is( ".ui-dialog" ) ) {
600  
-				newUrl = $.mobile.path.parseLocation().hash + $.mobile.dialogHashKey;
  600
+			if ( url.indexOf( hashkey ) == -1 && !activePage.is( ".ui-dialog" ) ){
  601
+				url = url + hashkey;
  602
+			} else {
  603
+				url = $.mobile.path.parseLocation().hash + hashkey;
601 604
 			}
602 605
 
603 606
 			// make sure the popup is displayed
604 607
 			this._open( options );
605 608
 
606  
-			// Gotta love methods with 1mm args :(
607  
-			$.mobile.urlHistory.addNew( newUrl, undefined, undefined, undefined, "dialog" );
608  
-
609 609
 			// swallow the the initial navigation event, and bind for the next
610 610
 			$.mobile.pageContainer.one( "navigate.popup", function( e ) {
611 611
 				e.preventDefault();
612 612
 
613 613
 				// any navigation event after a popup is opened should close the popup
614  
-				$.mobile.pageContainer.one( "navigate.popup", function() {
  614
+				// NOTE the pagebeforechange is bound to catch navigation events that don't
  615
+				//      alter the url (eg, dialogs from popups)
  616
+				$.mobile.pageContainer.one( "navigate.popup pagebeforechange.popup", function() {
615 617
 					self._close();
616 618
 				});
617 619
 			});
618 620
 
  621
+			// Gotta love methods with 1mm args :(
  622
+			$.mobile.urlHistory.addNew( url, undefined, undefined, undefined, "dialog" );
  623
+
619 624
 			// set the new url with (or without) the new dialog hash key
620  
-			$.mobile.path.set( newUrl );
  625
+			$.mobile.path.set( url );
621 626
 		},
622 627
 
623 628
 		close: function() {

0 notes on commit 242cf05

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