2009-02-02 14:36:08 +00:00
|
|
|
/*
|
|
|
|
* dialog_methods.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
2009-09-15 15:42:41 +00:00
|
|
|
module("dialog: methods", {
|
|
|
|
teardown: function() {
|
|
|
|
$("body>.ui-dialog").remove();
|
|
|
|
}
|
|
|
|
});
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2009-02-04 04:35:18 +00:00
|
|
|
test("init", function() {
|
2010-08-27 18:48:17 +00:00
|
|
|
expect(6);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
$("<div></div>").appendTo("body").dialog().remove();
|
|
|
|
ok(true, ".dialog() called on element");
|
2009-02-04 04:35:18 +00:00
|
|
|
|
|
|
|
$([]).dialog().remove();
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(true, ".dialog() called on empty collection");
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
$("<div></div>").dialog().remove();
|
|
|
|
ok(true, ".dialog() called on disconnected DOMElement - never connected");
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
$("<div></div>").appendTo("body").remove().dialog().remove();
|
|
|
|
ok(true, ".dialog() called on disconnected DOMElement - removed");
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
var element = $("<div></div>").dialog();
|
|
|
|
element.dialog("option", "foo");
|
|
|
|
element.remove();
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(true, "arbitrary option getter after init");
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
$("<div></div>").dialog().dialog("option", "foo", "bar").remove();
|
|
|
|
ok(true, "arbitrary option setter after init");
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("destroy", function() {
|
2013-01-24 01:12:25 +00:00
|
|
|
expect( 17 );
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
var element, element2;
|
2012-12-04 15:03:05 +00:00
|
|
|
|
|
|
|
$( "#dialog1, #form-dialog" ).hide();
|
2012-11-16 18:33:55 +00:00
|
|
|
domEqual( "#dialog1", function() {
|
|
|
|
var dialog = $( "#dialog1" ).dialog().dialog( "destroy" );
|
|
|
|
equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] );
|
|
|
|
equal( dialog.index(), 0 );
|
|
|
|
});
|
|
|
|
domEqual( "#form-dialog", function() {
|
|
|
|
var dialog = $( "#form-dialog" ).dialog().dialog( "destroy" );
|
|
|
|
equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] );
|
|
|
|
equal( dialog.index(), 2 );
|
|
|
|
});
|
2012-12-05 16:53:34 +00:00
|
|
|
|
|
|
|
// Ensure dimensions are restored (#8119)
|
|
|
|
$( "#dialog1" ).show().css({
|
|
|
|
width: "400px",
|
|
|
|
minHeight: "100px",
|
|
|
|
height: "200px"
|
|
|
|
});
|
|
|
|
domEqual( "#dialog1", function() {
|
|
|
|
$( "#dialog1" ).dialog().dialog( "destroy" );
|
|
|
|
});
|
2013-01-24 01:12:25 +00:00
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element = $( "#dialog1" ).dialog({ modal: true }),
|
|
|
|
element2 = $( "#dialog2" ).dialog({ modal: true });
|
2013-01-24 01:12:25 +00:00
|
|
|
equal( $( ".ui-widget-overlay" ).length, 2, "overlays created when dialogs are open" );
|
|
|
|
equal( $.ui.dialog.overlayInstances, 2, "overlayInstances equals the number of open overlays" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "close" );
|
2013-01-24 01:12:25 +00:00
|
|
|
equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after closing one dialog" );
|
|
|
|
equal( $.ui.dialog.overlayInstances, 1, "overlayInstances equals the number of open overlays" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "destroy" );
|
2013-01-24 01:12:25 +00:00
|
|
|
equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after destroying one dialog" );
|
|
|
|
equal( $.ui.dialog.overlayInstances, 1, "overlayInstances equals the number of open overlays" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element2.dialog( "destroy" );
|
2013-01-24 01:12:25 +00:00
|
|
|
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 );
|
2009-04-15 02:33:28 +00:00
|
|
|
});
|
|
|
|
|
2012-12-12 08:16:33 +00:00
|
|
|
test("#4980: Destroy should place element back in original DOM position", function(){
|
|
|
|
expect( 2 );
|
2012-12-26 13:08:48 +00:00
|
|
|
var container = $("<div id='container'><div id='modal'>Content</div></div>"),
|
|
|
|
modal = container.find("#modal");
|
2012-12-12 08:16:33 +00:00
|
|
|
modal.dialog();
|
2012-12-26 13:08:48 +00:00
|
|
|
ok(!$.contains(container[0], modal[0]), "dialog should move modal element to outside container element");
|
|
|
|
modal.dialog("destroy");
|
|
|
|
ok($.contains(container[0], modal[0]), "dialog(destroy) should place element back in original DOM position");
|
2012-12-12 08:16:33 +00:00
|
|
|
});
|
|
|
|
|
2012-11-17 10:31:57 +00:00
|
|
|
test( "enable/disable disabled", function() {
|
2013-03-14 19:07:06 +00:00
|
|
|
expect( 2 );
|
2013-01-31 05:38:20 +00:00
|
|
|
var element = $( "<div></div>" ).dialog();
|
|
|
|
element.dialog( "disable" );
|
|
|
|
equal(element.dialog( "option", "disabled" ), false, "disable method doesn't do anything" );
|
|
|
|
ok( !element.dialog( "widget" ).hasClass( "ui-dialog-disabled" ), "disable method doesn't add ui-dialog-disabled class" );
|
2009-04-15 02:33:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("close", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 3 );
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
var element,
|
2012-12-26 13:08:48 +00:00
|
|
|
expected = $("<div></div>").dialog(),
|
|
|
|
actual = expected.dialog("close");
|
|
|
|
equal(actual, expected, "close is chainable");
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element = $("<div></div>").dialog();
|
|
|
|
ok(element.dialog("widget").is(":visible") && !element.dialog("widget").is(":hidden"), "dialog visible before close method called");
|
|
|
|
element.dialog("close");
|
|
|
|
ok(element.dialog("widget").is(":hidden") && !element.dialog("widget").is(":visible"), "dialog hidden after close method called");
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("isOpen", function() {
|
|
|
|
expect(4);
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
var element = $("<div></div>").dialog();
|
|
|
|
equal(element.dialog("isOpen"), true, "dialog is open after init");
|
|
|
|
element.dialog("close");
|
|
|
|
equal(element.dialog("isOpen"), false, "dialog is closed");
|
|
|
|
element.remove();
|
|
|
|
|
|
|
|
element = $("<div></div>").dialog({autoOpen: false});
|
|
|
|
equal(element.dialog("isOpen"), false, "dialog is closed after init");
|
|
|
|
element.dialog("open");
|
|
|
|
equal(element.dialog("isOpen"), true, "dialog is open");
|
|
|
|
element.remove();
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
2009-04-15 02:33:28 +00:00
|
|
|
test("moveToTop", function() {
|
2012-10-15 20:12:21 +00:00
|
|
|
expect( 5 );
|
|
|
|
function order() {
|
|
|
|
var actual = $( ".ui-dialog" ).map(function() {
|
|
|
|
return +$( this ).find( ".ui-dialog-content" ).attr( "id" ).replace( /\D+/, "" );
|
|
|
|
}).get().reverse();
|
|
|
|
deepEqual( actual, $.makeArray( arguments ) );
|
|
|
|
}
|
|
|
|
var dialog1, dialog2,
|
|
|
|
focusOn = "dialog1";
|
|
|
|
dialog1 = $( "#dialog1" ).dialog({
|
|
|
|
focus: function() {
|
|
|
|
equal( focusOn, "dialog1" );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
focusOn = "dialog2";
|
|
|
|
dialog2 = $( "#dialog2" ).dialog({
|
|
|
|
focus: function() {
|
|
|
|
equal( focusOn, "dialog2" );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
order( 2, 1 );
|
|
|
|
focusOn = "dialog1";
|
|
|
|
dialog1.dialog( "moveToTop" );
|
|
|
|
order( 1, 2 );
|
2009-04-15 02:33:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("open", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 3 );
|
2013-01-31 05:38:20 +00:00
|
|
|
var element,
|
2012-12-26 13:08:48 +00:00
|
|
|
expected = $("<div></div>").dialog(),
|
|
|
|
actual = expected.dialog("open");
|
|
|
|
equal(actual, expected, "open is chainable");
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element = $("<div></div>").dialog({ autoOpen: false });
|
|
|
|
ok(element.dialog("widget").is(":hidden") && !element.dialog("widget").is(":visible"), "dialog hidden before open method called");
|
|
|
|
element.dialog("open");
|
|
|
|
ok(element.dialog("widget").is(":visible") && !element.dialog("widget").is(":hidden"), "dialog visible after open method called");
|
2009-04-15 02:33:28 +00:00
|
|
|
});
|
|
|
|
|
2012-12-08 01:06:29 +00:00
|
|
|
test("#6137: dialog('open') causes form elements to reset on IE7", function() {
|
|
|
|
expect(2);
|
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
var d1 = $("<form><input type='radio' name='radio' id='a' value='a' checked='checked'></input>" +
|
|
|
|
"<input type='radio' name='radio' id='b' value='b'>b</input></form>").appendTo( "body" ).dialog({autoOpen: false});
|
2012-12-08 01:06:29 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
d1.find("#b").prop( "checked", true );
|
|
|
|
equal(d1.find("input:checked").val(), "b", "checkbox b is checked");
|
2012-12-08 01:06:29 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
d1.dialog("open");
|
|
|
|
equal(d1.find("input:checked").val(), "b", "checkbox b is checked");
|
2012-12-08 01:06:29 +00:00
|
|
|
|
|
|
|
d1.remove();
|
|
|
|
});
|
|
|
|
|
2013-01-31 22:20:19 +00:00
|
|
|
asyncTest( "#8958: dialog can be opened while opening", function() {
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
var element = $( "<div>" ).dialog({
|
|
|
|
autoOpen: false,
|
|
|
|
modal: true,
|
|
|
|
open: function() {
|
|
|
|
equal( $( ".ui-widget-overlay" ).length, 1 );
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$( "#favorite-animal" )
|
|
|
|
// We focus the input to start the test. Once it receives focus, the
|
|
|
|
// dialog will open. Opening the dialog, will cause an element inside
|
|
|
|
// the dialog to gain focus, thus blurring the input.
|
|
|
|
.bind( "focus", function() {
|
|
|
|
element.dialog( "open" );
|
|
|
|
})
|
|
|
|
// When the input blurs, the dialog is in the process of opening. We
|
|
|
|
// try to open the dialog again, to make sure that dialogs properly
|
|
|
|
// handle a call to the open() method during the process of the dialog
|
|
|
|
// being opened.
|
|
|
|
.bind( "blur", function() {
|
|
|
|
element.dialog( "open" );
|
|
|
|
})
|
|
|
|
.focus();
|
|
|
|
});
|
|
|
|
|
2012-12-08 01:06:29 +00:00
|
|
|
test("#5531: dialog width should be at least minWidth on creation", function () {
|
|
|
|
expect( 4 );
|
2013-01-31 05:38:20 +00:00
|
|
|
var element = $("<div></div>").dialog({
|
2012-12-08 01:06:29 +00:00
|
|
|
width: 200,
|
|
|
|
minWidth: 300
|
|
|
|
});
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
equal(element.dialog("option", "width"), 300, "width is minWidth");
|
|
|
|
element.dialog("option", "width", 200);
|
|
|
|
equal(element.dialog("option", "width"), 300, "width unchanged when set to < minWidth");
|
|
|
|
element.dialog("option", "width", 320);
|
|
|
|
equal(element.dialog("option", "width"), 320, "width changed if set to > minWidth");
|
|
|
|
element.remove();
|
2012-12-08 01:06:29 +00:00
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element = $("<div></div>").dialog({
|
2012-12-08 01:06:29 +00:00
|
|
|
minWidth: 300
|
|
|
|
});
|
2013-01-31 05:38:20 +00:00
|
|
|
ok(element.dialog("option", "width") >= 300, "width is at least 300");
|
|
|
|
element.remove();
|
2012-12-08 01:06:29 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2009-02-02 14:36:08 +00:00
|
|
|
})(jQuery);
|