2009-02-02 14:36:08 +00:00
|
|
|
/*
|
|
|
|
* dialog_tickets.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
2011-08-19 11:03:59 +00:00
|
|
|
module( "dialog: tickets" );
|
|
|
|
|
|
|
|
asyncTest( "#3123: Prevent tabbing out of modal dialogs", function() {
|
|
|
|
expect( 3 );
|
|
|
|
|
|
|
|
var el = $( "<div><input id='t3123-first'><input id='t3123-last'></div>" ).dialog({ modal: true }),
|
|
|
|
inputs = el.find( "input" ),
|
2012-07-13 19:52:32 +00:00
|
|
|
widget = el.dialog( "widget" )[ 0 ];
|
2011-08-19 11:03:59 +00:00
|
|
|
|
|
|
|
function checkTab() {
|
|
|
|
ok( $.contains( widget, document.activeElement ), "Tab key event moved focus within the modal" );
|
|
|
|
|
|
|
|
// check shift tab
|
|
|
|
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB, shiftKey: true });
|
|
|
|
setTimeout( checkShiftTab, 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkShiftTab() {
|
|
|
|
ok( $.contains( widget, document.activeElement ), "Shift-Tab key event moved focus within the modal" );
|
|
|
|
|
|
|
|
el.remove();
|
|
|
|
start();
|
|
|
|
}
|
2012-04-19 14:27:06 +00:00
|
|
|
|
|
|
|
inputs.eq( 1 ).focus();
|
|
|
|
equal( document.activeElement, inputs[1], "Focus set on second input" );
|
|
|
|
inputs.eq( 1 ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB });
|
|
|
|
|
|
|
|
setTimeout( checkTab, 2 );
|
2011-08-19 11:03:59 +00:00
|
|
|
});
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2009-09-15 16:14:15 +00:00
|
|
|
test("#4826: setting resizable false toggles resizable on dialog", function() {
|
|
|
|
expect(6);
|
2012-04-19 14:27:06 +00:00
|
|
|
var i;
|
2009-09-15 16:14:15 +00:00
|
|
|
|
|
|
|
el = $('<div></div>').dialog({ resizable: false });
|
|
|
|
shouldnotresize("[default]");
|
2012-04-19 14:27:06 +00:00
|
|
|
for (i=0; i<2; i++) {
|
2009-09-15 16:14:15 +00:00
|
|
|
el.dialog('close').dialog('open');
|
2012-02-28 14:56:32 +00:00
|
|
|
shouldnotresize('initialized with resizable false toggle ('+ (i+1) +')');
|
2009-09-15 16:14:15 +00:00
|
|
|
}
|
|
|
|
el.remove();
|
|
|
|
|
|
|
|
el = $('<div></div>').dialog({ resizable: true });
|
|
|
|
shouldresize("[default]");
|
2012-04-19 14:27:06 +00:00
|
|
|
for (i=0; i<2; i++) {
|
2009-09-15 16:14:15 +00:00
|
|
|
el.dialog('close').dialog('option', 'resizable', false).dialog('open');
|
2012-02-28 14:56:32 +00:00
|
|
|
shouldnotresize('set option resizable false toggle ('+ (i+1) +')');
|
2009-09-15 16:14:15 +00:00
|
|
|
}
|
|
|
|
el.remove();
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2009-09-15 16:14:15 +00:00
|
|
|
});
|
|
|
|
|
2010-02-16 02:13:38 +00:00
|
|
|
test("#5184: isOpen in dialogclose event is true", function() {
|
|
|
|
expect( 3 );
|
|
|
|
|
|
|
|
el = $( "<div></div>" ).dialog({
|
|
|
|
close: function() {
|
|
|
|
ok( !el.dialog("isOpen"), "dialog is not open during close" );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ok( el.dialog("isOpen"), "dialog is open after init" );
|
|
|
|
el.dialog( "close" );
|
|
|
|
ok( !el.dialog("isOpen"), "dialog is not open after close" );
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
2010-04-19 22:42:34 +00:00
|
|
|
test("#5531: dialog width should be at least minWidth on creation", function () {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 4 );
|
2010-04-19 22:42:34 +00:00
|
|
|
el = $('<div></div>').dialog({
|
|
|
|
width: 200,
|
|
|
|
minWidth: 300
|
|
|
|
});
|
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.dialog('option', 'width'), 300, "width is minWidth");
|
2010-04-19 22:42:34 +00:00
|
|
|
el.dialog('option', 'width', 200);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.dialog('option', 'width'), 300, "width unchanged when set to < minWidth");
|
2010-04-19 22:42:34 +00:00
|
|
|
el.dialog('option', 'width', 320);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.dialog('option', 'width'), 320, "width changed if set to > minWidth");
|
2010-04-19 22:42:34 +00:00
|
|
|
el.remove();
|
|
|
|
|
|
|
|
el = $('<div></div>').dialog({
|
|
|
|
minWidth: 300
|
|
|
|
});
|
|
|
|
ok(el.dialog('option', 'width') >= 300, "width is at least 300");
|
|
|
|
el.remove();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2010-10-01 22:46:19 +00:00
|
|
|
test("#6137: dialog('open') causes form elements to reset on IE7", function() {
|
|
|
|
expect(2);
|
|
|
|
|
|
|
|
d1 = $('<form><input type="radio" name="radio" id="a" value="a" checked="checked"></input>' +
|
2011-06-08 21:02:57 +00:00
|
|
|
'<input type="radio" name="radio" id="b" value="b">b</input></form>').appendTo( "body" ).dialog({autoOpen: false});
|
2010-10-01 22:46:19 +00:00
|
|
|
|
2011-06-08 21:02:57 +00:00
|
|
|
d1.find('#b').prop( "checked", true );
|
2010-10-01 22:46:19 +00:00
|
|
|
equal($('input:checked').val(), 'b', "checkbox b is checked");
|
|
|
|
|
|
|
|
d1.dialog('open');
|
|
|
|
equal($('input:checked').val(), 'b', "checkbox b is checked");
|
|
|
|
|
2011-06-08 21:02:57 +00:00
|
|
|
d1.remove();
|
2010-11-12 13:16:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("#6645: Missing element not found check in overlay", function(){
|
|
|
|
expect(2);
|
|
|
|
d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true});
|
2012-04-19 14:27:06 +00:00
|
|
|
d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove(); }});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal($.ui.dialog.overlay.instances.length, 2, 'two overlays created');
|
2010-11-12 13:16:41 +00:00
|
|
|
d2.dialog('close');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal($.ui.dialog.overlay.instances.length, 1, 'one overlay remains after closing the 2nd overlay');
|
2010-11-12 13:16:41 +00:00
|
|
|
d1.add(d2).remove();
|
|
|
|
});
|
2010-10-01 22:46:19 +00:00
|
|
|
|
2011-03-08 14:42:10 +00:00
|
|
|
test("#6966: Escape key closes all dialogs, not the top one", function(){
|
2012-05-03 23:02:23 +00:00
|
|
|
expect(24);
|
|
|
|
// test with close function removing dialog triggered through the overlay
|
|
|
|
d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true, close: function(){ d1.remove(); }});
|
|
|
|
d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove(); }});
|
|
|
|
|
|
|
|
ok(d1.data('dialog') && d1.dialog('isOpen'), 'first dialog is open');
|
|
|
|
ok(d2.data('dialog') && d2.dialog('isOpen'), 'second dialog is open');
|
|
|
|
|
|
|
|
$( document ).simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
|
|
|
|
ok(d1.data('dialog') && d1.dialog('isOpen'), 'first dialog still open');
|
|
|
|
ok(!d2.data('dialog'), 'second dialog is closed');
|
|
|
|
|
|
|
|
$( document ).simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
|
|
|
|
ok(!d1.data('dialog'), 'first dialog is closed');
|
|
|
|
ok(!d2.data('dialog'), 'second dialog is closed');
|
|
|
|
|
|
|
|
d2.remove();
|
|
|
|
d1.remove();
|
|
|
|
|
|
|
|
// test with close function removing dialog triggered through the dialog
|
|
|
|
d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true, close: function(){ d1.remove(); }});
|
2012-04-19 14:27:06 +00:00
|
|
|
d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove(); }});
|
2012-05-03 23:02:23 +00:00
|
|
|
|
|
|
|
ok(d1.data('dialog') && d1.dialog('isOpen'), 'first dialog is open');
|
|
|
|
ok(d2.data('dialog') && d2.dialog('isOpen'), 'second dialog is open');
|
|
|
|
|
|
|
|
d2.simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
|
|
|
|
ok(d1.data('dialog') && d1.dialog('isOpen'), 'first dialog still open');
|
|
|
|
ok(!d2.data('dialog'), 'second dialog is closed');
|
|
|
|
|
|
|
|
d1.simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
|
|
|
|
ok(!d1.data('dialog'), 'first dialog is closed');
|
|
|
|
ok(!d2.data('dialog'), 'second dialog is closed');
|
|
|
|
|
|
|
|
d2.remove();
|
|
|
|
d1.remove();
|
|
|
|
|
|
|
|
// test without close function removing dialog
|
|
|
|
d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true});
|
|
|
|
d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true});
|
|
|
|
|
2011-03-08 14:42:10 +00:00
|
|
|
ok(d1.dialog("isOpen"), 'first dialog is open');
|
|
|
|
ok(d2.dialog("isOpen"), 'second dialog is open');
|
2012-05-03 23:02:23 +00:00
|
|
|
|
2011-03-08 14:42:10 +00:00
|
|
|
d2.simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE});
|
|
|
|
ok(d1.dialog("isOpen"), 'first dialog still open');
|
2012-05-03 23:02:23 +00:00
|
|
|
ok(!d2.dialog("isOpen"), 'second dialog is closed');
|
|
|
|
|
|
|
|
d1.simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE});
|
|
|
|
ok(!d1.dialog("isOpen"), 'first dialog is closed');
|
|
|
|
ok(!d2.dialog("isOpen"), 'second dialog is closed');
|
|
|
|
|
2011-03-08 14:42:10 +00:00
|
|
|
d2.remove();
|
|
|
|
d1.remove();
|
|
|
|
|
2012-05-03 23:02:23 +00:00
|
|
|
// test without close function removing dialog triggered through the overlay
|
2011-03-08 14:42:10 +00:00
|
|
|
d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true});
|
|
|
|
d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true});
|
2012-05-03 23:02:23 +00:00
|
|
|
|
2011-03-08 14:42:10 +00:00
|
|
|
ok(d1.dialog("isOpen"), 'first dialog is open');
|
|
|
|
ok(d2.dialog("isOpen"), 'second dialog is open');
|
2012-05-03 23:02:23 +00:00
|
|
|
|
|
|
|
$( document ).simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE});
|
2011-03-08 14:42:10 +00:00
|
|
|
ok(d1.dialog("isOpen"), 'first dialog still open');
|
|
|
|
ok(!d2.dialog("isOpen"), 'second dialog is closed');
|
2012-05-03 23:02:23 +00:00
|
|
|
|
|
|
|
$( document ).simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE});
|
|
|
|
ok(!d1.dialog("isOpen"), 'first dialog is closed');
|
|
|
|
ok(!d2.dialog("isOpen"), 'second dialog is closed');
|
|
|
|
|
2011-03-08 14:42:10 +00:00
|
|
|
d2.remove();
|
|
|
|
d1.remove();
|
|
|
|
});
|
|
|
|
|
2011-12-15 20:52:49 +00:00
|
|
|
test("#4980: Destroy should place element back in original DOM position", function(){
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2011-12-15 20:52:49 +00:00
|
|
|
container = $('<div id="container"><div id="modal">Content</div></div>');
|
|
|
|
modal = container.find('#modal');
|
|
|
|
modal.dialog();
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2009-02-02 14:36:08 +00:00
|
|
|
})(jQuery);
|