define( [ "jquery", "ui/widgets/dialog" ], function( $ ) { module( "dialog: methods", { teardown: function() { $( "body>.ui-dialog" ).remove(); } } ); test( "init", function() { expect( 6 ); $( "
" ).appendTo( "body" ).dialog().remove(); ok( true, ".dialog() called on element" ); $( [] ).dialog().remove(); ok( true, ".dialog() called on empty collection" ); $( "" ).dialog().remove(); ok( true, ".dialog() called on disconnected DOMElement - never connected" ); $( "" ).appendTo( "body" ).remove().dialog().remove(); ok( true, ".dialog() called on disconnected DOMElement - removed" ); var element = $( "" ).dialog(); element.dialog( "option", "foo" ); element.remove(); ok( true, "arbitrary option getter after init" ); $( "" ).dialog().dialog( "option", "foo", "bar" ).remove(); ok( true, "arbitrary option setter after init" ); } ); test( "destroy", function( assert ) { expect( 17 ); var element, element2; $( "#dialog1, #form-dialog" ).hide(); assert.domEqual( "#dialog1", function() { var dialog = $( "#dialog1" ).dialog().dialog( "destroy" ); equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); equal( dialog.index(), 0 ); } ); assert.domEqual( "#form-dialog", function() { var dialog = $( "#form-dialog" ).dialog().dialog( "destroy" ); equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); equal( dialog.index(), 2 ); } ); // Ensure dimensions are restored (#8119) $( "#dialog1" ).show().css( { width: "400px", minHeight: "100px", height: "200px" } ); assert.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( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays" ); element = $( "#dialog1" ).dialog( { modal: true } ), element2 = $( "#dialog2" ).dialog( { modal: true } ); equal( $( ".ui-widget-overlay" ).length, 2, "overlays created when dialogs are open" ); equal( $( document ).data( "ui-dialog-overlays" ), 2, "ui-dialog-overlays equals the number of open overlays" ); element.dialog( "close" ); equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after closing one dialog" ); equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" ); element.dialog( "destroy" ); equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after destroying one dialog" ); equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" ); element2.dialog( "destroy" ); equal( $( ".ui-widget-overlay" ).length, 0, "overlays removed when all dialogs are destoryed" ); equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays 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" ).trigger( "focus" ); ok( true, "close and destroy modal dialog before its really opened" ); start(); } ); } ); test( "#4980: Destroy should place element back in original DOM position", function() { expect( 2 ); var container = $( "