Skip to content
This repository
Browse code

enable close button when history is disabled

  • Loading branch information...
commit d2361b5424f3fdbd446182267914de55e2432abe 1 parent 45f2492
John Bender authored August 27, 2012
27  js/widgets/popup.js
@@ -49,7 +49,7 @@ define( [ "jquery",
49 49
 			initSelector: ":jqmData(role='popup')",
50 50
 			navigateEvents: "navigate.popup",
51 51
 			closeEvents: "navigate.popup pagebeforechange.popup",
52  
-			history: true
  52
+			history: false
53 53
 		},
54 54
 
55 55
 		_eatEventAndClose: function( e ) {
@@ -552,16 +552,21 @@ define( [ "jquery",
552 552
 		},
553 553
 
554 554
 		_closePrereqsDone: function() {
555  
-			this._ui.container.removeAttr( "tabindex" );
  555
+			var self = this;
  556
+
  557
+			self._ui.container.removeAttr( "tabindex" );
556 558
 
557 559
 			// remove nav bindings if they are still present
558  
-			$.mobile.pageContainer.unbind( this.options.closeEvents );
  560
+			self.options.container.unbind( self.options.closeEvents );
  561
+
  562
+			// unbind click handlers added when history is disabled
  563
+			self.options.container.undelegate( "a:jqmData(rel='back')", "click.popup" );
559 564
 
560 565
 			// remove the global mutex for popups
561 566
 			$.mobile.popup.active = undefined;
562 567
 
563 568
 			// alert users that the popup is closed
564  
-			this._trigger( "afterclose" );
  569
+			self._trigger( "afterclose" );
565 570
 		},
566 571
 
567 572
 		_close: function() {
@@ -632,6 +637,20 @@ define( [ "jquery",
632 637
 			// and leave the url as is
633 638
 			if( !self.options.history ) {
634 639
 				self._bindContainerClose();
  640
+
  641
+				// When histoy is disabled we have to grab the data-rel
  642
+				// back link clicks so we can close the popup instead of
  643
+				// relying on history to do it for us
  644
+				self.options.container
  645
+					.delegate( "a:jqmData(rel='back')", "click.popup", function( e ) {
  646
+						self._close();
  647
+
  648
+						// NOTE prevent the browser and navigation handlers from
  649
+						// working with the link's rel=back. This may cause
  650
+						// issues for developers expecting the event to bubble
  651
+						return false;
  652
+					});
  653
+
635 654
 				return;
636 655
 			}
637 656
 
1  tests/unit/popup/index.html
@@ -56,6 +56,7 @@ <h2 id="qunit-userAgent"></h2>
56 56
 
57 57
       <div data-nstest-role="popup" id="test-history-popup" data-nstest-history="false">
58 58
         <p>This is the test popup</p>
  59
+        <a href="#" data-nstest-rel="back" data-nstest-role="button" data-nstest-theme="a" data-nstest-icon="delete" data-nstest-iconpos="notext" class="ui-btn-right">Close</a>
59 60
       </div>
60 61
     </div>
61 62
   </div>
12  tests/unit/popup/popup_core.js
@@ -467,4 +467,16 @@
467 467
 			start
468 468
 		]);
469 469
 	});
  470
+
  471
+	test( "Close links work on a history disabled popup", function() {
  472
+		var $popup = $( "#test-history-popup" );
  473
+
  474
+		expect( 2 );
  475
+
  476
+		$popup.popup( 'open' );
  477
+		ok( $.mobile.popup.active, "popup is shown on link click" );
  478
+
  479
+		$popup.find( "a" ).click();
  480
+		ok( !$.mobile.popup.active, "popup is hidden on link click" );
  481
+	});
470 482
 })( jQuery );

0 notes on commit d2361b5

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