Permalink
Browse files

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

  • Loading branch information...
johnbender committed Aug 28, 2012
1 parent 46a65c6 commit 5181ea579ae3580d4513a2e5c25b3bac7003f60b
Showing with 30 additions and 8 deletions.
  1. +13 −8 js/widgets/popup.js
  2. +4 −0 tests/unit/popup/index.html
  3. +13 −0 tests/unit/popup/popup_core.js
View
@@ -600,17 +600,22 @@ define( [ "jquery",
},
_destroy: function() {
var self = this;
// hide and remove bindings
self._close();
// Put the element back to where the placeholder was and remove the "ui-popup" class
this._setTheme( "none" );
this.element
.insertAfter( this._ui.placeholder )
self._setTheme( "none" );
self.element
.insertAfter( self._ui.placeholder )
.removeClass( "ui-popup ui-overlay-shadow ui-corner-all" );
this._ui.screen.remove();
this._ui.container.remove();
this._ui.placeholder.remove();
self._ui.screen.remove();
self._ui.container.remove();
self._ui.placeholder.remove();
// Unbind handlers that were bound to elements outside this.element (the window, in this case)
$.each( this._globalHandlers, function( idx, oneSrc ) {
// Unbind handlers that were bound to elements outside self.element (the window, in self case)
$.each( self._globalHandlers, function( idx, oneSrc ) {
$.each( oneSrc.handler, function( eventType, handler ) {
oneSrc.src.unbind( eventType, handler );
});
@@ -58,6 +58,10 @@ <h2 id="qunit-userAgent"></h2>
<p>This is the test popup</p>
<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>
</div>
<div data-nstest-role="popup" id="test-destroy-popup" data-nstest-history="false">
<p>This is the test popup</p>
</div>
</div>
</div>
@@ -479,4 +479,17 @@
$popup.find( "a" ).click();
ok( !$.mobile.popup.active, "popup is hidden on link click" );
});
asyncTest( "Destroy closes the popup first", function() {
var $popup = $( "#test-destroy-popup" );
expect( 1 );
$popup.one( "popupafterclose", function() {
ok( true, "closed on destroy" );
start();
});
$popup.popup( "destroy" );
});
})( jQuery );

0 comments on commit 5181ea5

Please sign in to comment.