]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Don't handle overlays on destory if there are not any. Fixed: #9004 - failed... 893/head
authorDavid Petersen <public@petersendidit.com>
Thu, 24 Jan 2013 01:12:25 +0000 (19:12 -0600)
committerDavid Petersen <public@petersendidit.com>
Thu, 24 Jan 2013 19:43:02 +0000 (13:43 -0600)
tests/unit/dialog/dialog_methods.js
ui/jquery.ui.dialog.js

index b4c58c31e114f786ed39a448965a33691aa5a4c3..efca71fd8470086bedc5e7cce7932061bb543fb4 100644 (file)
@@ -34,7 +34,9 @@ test("init", function() {
 });
 
 test("destroy", function() {
-       expect( 7 );
+       expect( 17 );
+
+       var el, el2;
 
        $( "#dialog1, #form-dialog" ).hide();
        domEqual( "#dialog1", function() {
@@ -57,6 +59,35 @@ test("destroy", function() {
        domEqual( "#dialog1", function() {
                $( "#dialog1" ).dialog().dialog( "destroy" );
        });
+
+       // Don't throw errors when destroying a never opened modal dialog (#9004)
+       $( "#dialog1" ).dialog({ autoOpen: false, modal: true }).dialog( "destroy" );
+       equal( $( ".ui-widget-overlay" ).length, 0, "overlay does not exist" );
+       equal( $.ui.dialog.overlayInstances, 0, "overlayInstances equals the number of open overlays");
+
+       el = $( "#dialog1" ).dialog({ modal: true }),
+       el2 = $( "#dialog2" ).dialog({ modal: true });
+       equal( $( ".ui-widget-overlay" ).length, 2, "overlays created when dialogs are open" );
+       equal( $.ui.dialog.overlayInstances, 2, "overlayInstances equals the number of open overlays" );
+       el.dialog( "close" );
+       equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after closing one dialog" );
+       equal( $.ui.dialog.overlayInstances, 1, "overlayInstances equals the number of open overlays" );
+       el.dialog( "destroy" );
+       equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after destroying one dialog" );
+       equal( $.ui.dialog.overlayInstances, 1, "overlayInstances equals the number of open overlays" );
+       el2.dialog( "destroy" );
+       equal( $( ".ui-widget-overlay" ).length, 0, "overlays removed when all dialogs are destoryed" );
+       equal( $.ui.dialog.overlayInstances, 0, "overlayInstances equals the number of open overlays" );
+});
+
+asyncTest("#9000: Dialog leaves broken event handler after close/destroy in certain cases", function() {
+       expect( 1 );
+       $( "#dialog1" ).dialog({ modal:true }).dialog( "close" ).dialog( "destroy" );
+       setTimeout(function() {
+               $( "#favorite-animal" ).focus();
+               ok( true, "close and destroy modal dialog before its really opened" );
+               start();
+       }, 2 );
 });
 
 test("#4980: Destroy should place element back in original DOM position", function(){
index ef5787ef60a294ebc73619f157f78ea9a632f294..bfe37235e23768300e9777b9cdcf9ba945a45791 100644 (file)
@@ -704,11 +704,15 @@ $.widget( "ui.dialog", {
                        return;
                }
 
-               $.ui.dialog.overlayInstances--;
-               if ( !$.ui.dialog.overlayInstances ) {
-                       this._off( this.document, "focusin" );
+               if ( this.overlay ) {
+                       $.ui.dialog.overlayInstances--;
+
+                       if ( !$.ui.dialog.overlayInstances ) {
+                               this._off( this.document, "focusin" );
+                       }
+                       this.overlay.remove();
+                       this.overlay = null;
                }
-               this.overlay.remove();
        }
 });