2009-02-02 14:36:08 +00:00
|
|
|
/*
|
|
|
|
* dialog_core.js
|
|
|
|
*/
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2009-02-02 14:36:08 +00:00
|
|
|
(function($) {
|
|
|
|
|
|
|
|
module("dialog: core");
|
|
|
|
|
2009-02-04 04:35:18 +00:00
|
|
|
test("title id", function() {
|
2012-05-30 04:11:42 +00:00
|
|
|
expect(1);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var titleId,
|
2013-01-31 05:38:20 +00:00
|
|
|
element = $("<div></div>").dialog();
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
titleId = element.dialog("widget").find(".ui-dialog-title").attr("id");
|
2012-12-26 13:08:48 +00:00
|
|
|
ok( /ui-id-\d+$/.test( titleId ), "auto-numbered title id");
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
|
2012-11-17 12:23:57 +00:00
|
|
|
test( "ARIA", function() {
|
|
|
|
expect( 4 );
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
var element = $( "<div></div>" ).dialog(),
|
|
|
|
wrapper = element.dialog( "widget" );
|
2012-11-17 12:23:57 +00:00
|
|
|
equal( wrapper.attr( "role" ), "dialog", "dialog role" );
|
|
|
|
equal( wrapper.attr( "aria-labelledby" ), wrapper.find( ".ui-dialog-title" ).attr( "id" ) );
|
2013-01-31 05:38:20 +00:00
|
|
|
equal( wrapper.attr( "aria-describedby" ), element.attr( "id" ), "aria-describedby added" );
|
|
|
|
element.remove();
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element = $("<div><div aria-describedby='section2'><p id='section2'>descriotion</p></div></div>").dialog();
|
|
|
|
strictEqual( element.dialog( "widget" ).attr( "aria-describedby" ), undefined, "no aria-describedby added, as already present in markup" );
|
|
|
|
element.remove();
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
test("widget method", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 1 );
|
2012-12-08 18:19:36 +00:00
|
|
|
var dialog = $("<div>").appendTo("#qunit-fixture").dialog();
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual(dialog.parent()[0], dialog.dialog("widget")[0]);
|
2012-12-08 18:19:36 +00:00
|
|
|
dialog.remove();
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
asyncTest( "focus tabbable", function() {
|
2012-11-16 19:24:57 +00:00
|
|
|
expect( 5 );
|
2013-01-31 05:38:20 +00:00
|
|
|
var element,
|
2012-11-16 19:24:57 +00:00
|
|
|
options = {
|
|
|
|
buttons: [{
|
|
|
|
text: "Ok",
|
|
|
|
click: $.noop
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
function checkFocus( markup, options, testFn, next ) {
|
2013-01-31 05:38:20 +00:00
|
|
|
element = $( markup ).dialog( options );
|
2012-12-10 20:31:56 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
testFn();
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2012-12-10 20:31:56 +00:00
|
|
|
setTimeout( next );
|
|
|
|
});
|
|
|
|
}
|
2012-11-16 19:24:57 +00:00
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
function step1() {
|
|
|
|
checkFocus( "<div><input><input autofocus></div>", options, function() {
|
2013-01-31 05:38:20 +00:00
|
|
|
equal( document.activeElement, element.find( "input" )[ 1 ],
|
2012-12-10 20:31:56 +00:00
|
|
|
"1. first element inside the dialog matching [autofocus]" );
|
|
|
|
}, step2 );
|
|
|
|
}
|
2012-11-17 17:04:10 +00:00
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
function step2() {
|
|
|
|
checkFocus( "<div><input><input></div>", options, function() {
|
2013-01-31 05:38:20 +00:00
|
|
|
equal( document.activeElement, element.find( "input" )[ 0 ],
|
2012-12-10 20:31:56 +00:00
|
|
|
"2. tabbable element inside the content element" );
|
|
|
|
}, step3 );
|
|
|
|
}
|
2012-11-17 17:04:10 +00:00
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
function step3() {
|
|
|
|
checkFocus( "<div>text</div>", options, function() {
|
|
|
|
equal( document.activeElement,
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" )[ 0 ],
|
2012-12-10 20:31:56 +00:00
|
|
|
"3. tabbable element inside the buttonpane" );
|
|
|
|
}, step4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function step4() {
|
|
|
|
checkFocus( "<div>text</div>", {}, function() {
|
|
|
|
equal( document.activeElement,
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "widget" ).find( ".ui-dialog-titlebar .ui-dialog-titlebar-close" )[ 0 ],
|
2012-12-10 20:31:56 +00:00
|
|
|
"4. the close button" );
|
|
|
|
}, step5 );
|
|
|
|
}
|
2012-11-17 17:04:10 +00:00
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
function step5() {
|
2013-01-31 05:38:20 +00:00
|
|
|
element = $( "<div>text</div>" ).dialog({
|
2012-11-17 17:04:10 +00:00
|
|
|
autoOpen: false
|
|
|
|
});
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).hide();
|
|
|
|
element.dialog( "open" );
|
2012-12-10 20:31:56 +00:00
|
|
|
setTimeout(function() {
|
2013-01-31 05:38:20 +00:00
|
|
|
equal( document.activeElement, element.parent()[ 0 ], "5. the dialog itself" );
|
|
|
|
element.remove();
|
2012-12-10 20:31:56 +00:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
}
|
2012-11-17 17:04:10 +00:00
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
step1();
|
2012-11-16 19:24:57 +00:00
|
|
|
});
|
|
|
|
|
2012-12-08 01:06:29 +00:00
|
|
|
test( "#7960: resizable handles below modal overlays", function() {
|
2012-11-26 21:27:18 +00:00
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
var resizable = $( "<div>" ).resizable(),
|
|
|
|
dialog = $( "<div>" ).dialog({ modal: true }),
|
|
|
|
resizableZindex = parseInt( resizable.find( ".ui-resizable-handle" ).css( "zIndex" ), 10 ),
|
|
|
|
overlayZindex = parseInt( $( ".ui-widget-overlay" ).css( "zIndex" ), 10 );
|
|
|
|
|
|
|
|
ok( resizableZindex < overlayZindex, "Resizable handles have lower z-index than modal overlay" );
|
|
|
|
dialog.dialog( "destroy" );
|
|
|
|
});
|
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
asyncTest( "Prevent tabbing out of dialogs", function() {
|
2012-12-08 01:06:29 +00:00
|
|
|
expect( 3 );
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
var element = $( "<div><input><input></div>" ).dialog(),
|
|
|
|
inputs = element.find( "input" ),
|
|
|
|
widget = element.dialog( "widget" )[ 0 ];
|
2012-12-08 01:06:29 +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 });
|
2012-12-10 20:31:56 +00:00
|
|
|
setTimeout( checkShiftTab );
|
2012-12-08 01:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkShiftTab() {
|
|
|
|
ok( $.contains( widget, document.activeElement ), "Shift-Tab key event moved focus within the modal" );
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2012-12-10 20:31:56 +00:00
|
|
|
setTimeout( start );
|
2012-12-08 01:06:29 +00:00
|
|
|
}
|
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
inputs[1].focus();
|
|
|
|
setTimeout(function() {
|
|
|
|
equal( document.activeElement, inputs[1], "Focus set on second input" );
|
|
|
|
inputs.eq( 1 ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB });
|
2012-12-08 01:06:29 +00:00
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
setTimeout( checkTab );
|
|
|
|
});
|
2012-12-08 01:06:29 +00:00
|
|
|
});
|
|
|
|
|
2013-02-03 00:32:42 +00:00
|
|
|
asyncTest( "#9048: multiple modal dialogs opened and closed in different order", function() {
|
|
|
|
expect( 1 );
|
|
|
|
$( "#dialog1, #dialog2" ).dialog({ autoOpen: false, modal:true });
|
|
|
|
$( "#dialog1" ).dialog( "open" );
|
|
|
|
$( "#dialog2" ).dialog( "open" );
|
|
|
|
$( "#dialog1" ).dialog( "close" );
|
|
|
|
setTimeout(function() {
|
|
|
|
$( "#dialog2" ).dialog( "close" );
|
|
|
|
$( "#favorite-animal" ).focus();
|
|
|
|
ok( true, "event handlers cleaned up (no errors thrown)" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
2009-02-02 14:36:08 +00:00
|
|
|
})(jQuery);
|