Skip to content
This repository
Browse code

make sure the popup is closed on destroy (including cleanup)

  • Loading branch information...
commit 5181ea579ae3580d4513a2e5c25b3bac7003f60b 1 parent 46a65c6
John Bender authored August 28, 2012
21  js/widgets/popup.js
@@ -600,17 +600,22 @@ define( [ "jquery",
600 600
 		},
601 601
 
602 602
 		_destroy: function() {
  603
+			var self = this;
  604
+
  605
+			// hide and remove bindings
  606
+			self._close();
  607
+
603 608
 			// Put the element back to where the placeholder was and remove the "ui-popup" class
604  
-			this._setTheme( "none" );
605  
-			this.element
606  
-				.insertAfter( this._ui.placeholder )
  609
+			self._setTheme( "none" );
  610
+			self.element
  611
+				.insertAfter( self._ui.placeholder )
607 612
 				.removeClass( "ui-popup ui-overlay-shadow ui-corner-all" );
608  
-			this._ui.screen.remove();
609  
-			this._ui.container.remove();
610  
-			this._ui.placeholder.remove();
  613
+			self._ui.screen.remove();
  614
+			self._ui.container.remove();
  615
+			self._ui.placeholder.remove();
611 616
 
612  
-			// Unbind handlers that were bound to elements outside this.element (the window, in this case)
613  
-			$.each( this._globalHandlers, function( idx, oneSrc ) {
  617
+			// Unbind handlers that were bound to elements outside self.element (the window, in self case)
  618
+			$.each( self._globalHandlers, function( idx, oneSrc ) {
614 619
 				$.each( oneSrc.handler, function( eventType, handler ) {
615 620
 					oneSrc.src.unbind( eventType, handler );
616 621
 				});
4  tests/unit/popup/index.html
@@ -58,6 +58,10 @@ <h2 id="qunit-userAgent"></h2>
58 58
         <p>This is the test popup</p>
59 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>
60 60
       </div>
  61
+
  62
+      <div data-nstest-role="popup" id="test-destroy-popup" data-nstest-history="false">
  63
+        <p>This is the test popup</p>
  64
+      </div>
61 65
     </div>
62 66
   </div>
63 67
 
13  tests/unit/popup/popup_core.js
@@ -479,4 +479,17 @@
479 479
 		$popup.find( "a" ).click();
480 480
 		ok( !$.mobile.popup.active, "popup is hidden on link click" );
481 481
 	});
  482
+
  483
+	asyncTest( "Destroy closes the popup first", function() {
  484
+		var $popup = $( "#test-destroy-popup" );
  485
+
  486
+		expect( 1 );
  487
+
  488
+		$popup.one( "popupafterclose", function() {
  489
+			ok( true, "closed on destroy" );
  490
+			start();
  491
+		});
  492
+
  493
+		$popup.popup( "destroy" );
  494
+	});
482 495
 })( jQuery );

0 notes on commit 5181ea5

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