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($) {
|
|
|
|
|
2013-11-16 11:21:02 +00:00
|
|
|
// TODO add teardown callback to remove dialogs
|
2009-02-02 14:36:08 +00:00
|
|
|
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() {
|
2014-06-10 11:51:25 +00:00
|
|
|
expect( 8 );
|
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-10-02 15:27:43 +00:00
|
|
|
|
|
|
|
// Support: IE8
|
|
|
|
// For some reason the focus doesn't get set properly if we don't
|
|
|
|
// focus the body first.
|
|
|
|
$( "body" ).focus();
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element = $( markup ).dialog( options );
|
2012-12-10 20:31:56 +00:00
|
|
|
setTimeout(function() {
|
2015-03-10 19:16:27 +00:00
|
|
|
testFn(function done() {
|
|
|
|
element.remove();
|
|
|
|
setTimeout( next );
|
|
|
|
});
|
2012-12-10 20:31:56 +00:00
|
|
|
});
|
|
|
|
}
|
2012-11-16 19:24:57 +00:00
|
|
|
|
2012-12-10 20:31:56 +00:00
|
|
|
function step1() {
|
2015-03-10 19:16:27 +00:00
|
|
|
checkFocus( "<div><input><input></div>", options, function( done ) {
|
2013-10-02 15:27:43 +00:00
|
|
|
var input = element.find( "input:last" ).focus().blur();
|
|
|
|
element.dialog( "instance" )._focusTabbable();
|
|
|
|
setTimeout(function() {
|
|
|
|
equal( document.activeElement, input[ 0 ],
|
|
|
|
"1. an element that was focused previously." );
|
2015-03-10 19:16:27 +00:00
|
|
|
done();
|
2013-10-02 15:27:43 +00:00
|
|
|
});
|
2015-03-10 19:16:27 +00:00
|
|
|
}, step2 );
|
2013-10-02 15:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function step2() {
|
2015-03-10 19:16:27 +00:00
|
|
|
checkFocus( "<div><input><input autofocus></div>", options, function( done ) {
|
2013-01-31 05:38:20 +00:00
|
|
|
equal( document.activeElement, element.find( "input" )[ 1 ],
|
2013-10-02 15:27:43 +00:00
|
|
|
"2. first element inside the dialog matching [autofocus]" );
|
2015-03-10 19:16:27 +00:00
|
|
|
done();
|
2013-10-02 15:27:43 +00:00
|
|
|
}, step3 );
|
2012-12-10 20:31:56 +00:00
|
|
|
}
|
2012-11-17 17:04:10 +00:00
|
|
|
|
2013-10-02 15:27:43 +00:00
|
|
|
function step3() {
|
2015-03-10 19:16:27 +00:00
|
|
|
checkFocus( "<div><input><input></div>", options, function( done ) {
|
2013-01-31 05:38:20 +00:00
|
|
|
equal( document.activeElement, element.find( "input" )[ 0 ],
|
2013-10-02 15:27:43 +00:00
|
|
|
"3. tabbable element inside the content element" );
|
2015-03-10 19:16:27 +00:00
|
|
|
done();
|
2013-10-02 15:27:43 +00:00
|
|
|
}, step4 );
|
2012-12-10 20:31:56 +00:00
|
|
|
}
|
2012-11-17 17:04:10 +00:00
|
|
|
|
2013-10-02 15:27:43 +00:00
|
|
|
function step4() {
|
2015-03-10 19:16:27 +00:00
|
|
|
checkFocus( "<div>text</div>", options, function( done ) {
|
2012-12-10 20:31:56 +00:00
|
|
|
equal( document.activeElement,
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" )[ 0 ],
|
2013-10-02 15:27:43 +00:00
|
|
|
"4. tabbable element inside the buttonpane" );
|
2015-03-10 19:16:27 +00:00
|
|
|
done();
|
2013-10-02 15:27:43 +00:00
|
|
|
}, step5 );
|
2012-12-10 20:31:56 +00:00
|
|
|
}
|
|
|
|
|
2013-10-02 15:27:43 +00:00
|
|
|
function step5() {
|
2015-03-10 19:16:27 +00:00
|
|
|
checkFocus( "<div>text</div>", {}, function( done ) {
|
2012-12-10 20:31:56 +00:00
|
|
|
equal( document.activeElement,
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "widget" ).find( ".ui-dialog-titlebar .ui-dialog-titlebar-close" )[ 0 ],
|
2013-10-02 15:27:43 +00:00
|
|
|
"5. the close button" );
|
2015-03-10 19:16:27 +00:00
|
|
|
done();
|
2013-10-02 15:27:43 +00:00
|
|
|
}, step6 );
|
2012-12-10 20:31:56 +00:00
|
|
|
}
|
2012-11-17 17:04:10 +00:00
|
|
|
|
2013-10-02 15:27:43 +00:00
|
|
|
function step6() {
|
2015-03-10 19:16:27 +00:00
|
|
|
checkFocus( "<div>text</div>", { autoOpen: false }, function( done ) {
|
|
|
|
element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).hide();
|
|
|
|
element.dialog( "open" );
|
|
|
|
setTimeout(function() {
|
|
|
|
equal( document.activeElement, element.parent()[ 0 ], "6. the dialog itself" );
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}, step7 );
|
2014-06-10 11:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function step7() {
|
2015-03-10 19:16:27 +00:00
|
|
|
checkFocus(
|
|
|
|
"<div><input><input autofocus></div>",
|
|
|
|
{
|
|
|
|
open: function() {
|
|
|
|
var inputs = $( this ).find( "input" );
|
|
|
|
inputs.last().keydown(function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
inputs.first().focus();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function( done ) {
|
|
|
|
var inputs = element.find( "input" );
|
|
|
|
equal( document.activeElement, inputs[ 1 ], "Focus starts on second input" );
|
|
|
|
inputs.last().simulate( "keydown", { keyCode: $.ui.keyCode.TAB });
|
|
|
|
setTimeout(function() {
|
|
|
|
equal( document.activeElement, inputs[ 0 ],
|
|
|
|
"Honor preventDefault, allowing custom focus management" );
|
|
|
|
done();
|
|
|
|
}, 50 );
|
|
|
|
},
|
|
|
|
start
|
|
|
|
);
|
2012-12-10 20:31:56 +00:00
|
|
|
}
|
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 );
|
|
|
|
|
2014-06-10 10:38:26 +00:00
|
|
|
var element = $( "<div><input name='0'><input name='1'></div>" ).dialog(),
|
|
|
|
inputs = element.find( "input" );
|
|
|
|
|
|
|
|
// Remove close button to test focus on just the two buttons
|
|
|
|
element.dialog( "widget" ).find( ".ui-button").remove();
|
2012-12-08 01:06:29 +00:00
|
|
|
|
|
|
|
function checkTab() {
|
2014-06-10 10:38:26 +00:00
|
|
|
equal( document.activeElement, inputs[ 0 ], "Tab key event moved focus within the modal" );
|
2012-12-08 01:06:29 +00:00
|
|
|
|
|
|
|
// 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() {
|
2014-06-10 10:38:26 +00:00
|
|
|
equal( document.activeElement, inputs[ 1 ], "Shift-Tab key event moved focus back to second input" );
|
2012-12-08 01:06:29 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-06-10 10:38:26 +00:00
|
|
|
inputs[ 1 ].focus();
|
2012-12-10 20:31:56 +00:00
|
|
|
setTimeout(function() {
|
2014-06-10 10:38:26 +00:00
|
|
|
equal( document.activeElement, inputs[ 1 ], "Focus set on second input" );
|
2012-12-10 20:31:56 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
2013-11-16 11:21:02 +00:00
|
|
|
|
|
|
|
asyncTest( "interaction between overlay and other dialogs", function() {
|
|
|
|
$.widget( "ui.testWidget", $.ui.dialog, {
|
|
|
|
options: {
|
|
|
|
modal: true,
|
|
|
|
autoOpen: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
expect( 2 );
|
|
|
|
var first = $( "<div><input id='input-1'></div>" ).dialog({
|
|
|
|
modal: true
|
|
|
|
}),
|
|
|
|
firstInput = first.find( "input" ),
|
|
|
|
second = $( "<div><input id='input-2'></div>" ).testWidget(),
|
|
|
|
secondInput = second.find( "input" );
|
|
|
|
|
|
|
|
// Support: IE8
|
|
|
|
// For some reason the focus doesn't get set properly if we don't
|
|
|
|
// focus the body first.
|
|
|
|
$( "body" ).focus();
|
|
|
|
|
|
|
|
// Wait for the modal to init
|
|
|
|
setTimeout(function() {
|
|
|
|
second.testWidget( "open" );
|
|
|
|
|
|
|
|
// Simulate user tabbing from address bar to an element outside the dialog
|
|
|
|
$( "#favorite-animal" ).focus();
|
|
|
|
setTimeout(function() {
|
|
|
|
equal( document.activeElement, secondInput[ 0 ] );
|
|
|
|
|
|
|
|
// Last active dialog must receive focus
|
|
|
|
firstInput.focus();
|
|
|
|
$( "#favorite-animal" ).focus();
|
|
|
|
setTimeout(function() {
|
|
|
|
equal( document.activeElement, firstInput[ 0 ] );
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
first.remove();
|
|
|
|
second.remove();
|
|
|
|
delete $.ui.testWidget;
|
|
|
|
delete $.fn.testWidget;
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2009-02-02 14:36:08 +00:00
|
|
|
})(jQuery);
|