2010-01-20 14:00:14 +00:00
|
|
|
/*
|
|
|
|
* autocomplete_core.js
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
(function($) {
|
|
|
|
|
2010-03-11 03:28:00 +00:00
|
|
|
module("autocomplete: core", {
|
|
|
|
teardown: function() {
|
|
|
|
$( ":ui-autocomplete" ).autocomplete( "destroy" );
|
|
|
|
}
|
|
|
|
});
|
2010-01-20 14:00:14 +00:00
|
|
|
|
|
|
|
test("close-on-blur is properly delayed", function() {
|
|
|
|
var ac = $("#autocomplete").autocomplete({
|
|
|
|
source: ["java", "javascript"]
|
|
|
|
}).val("ja").autocomplete("search");
|
|
|
|
same( $(".ui-menu:visible").length, 1 );
|
|
|
|
ac.blur();
|
|
|
|
same( $(".ui-menu:visible").length, 1 );
|
|
|
|
stop();
|
|
|
|
setTimeout(function() {
|
|
|
|
same( $(".ui-menu:visible").length, 0 );
|
|
|
|
start();
|
|
|
|
}, 200);
|
2010-09-27 14:10:00 +00:00
|
|
|
});
|
2010-01-20 14:00:14 +00:00
|
|
|
|
|
|
|
test("close-on-blur is cancelled when starting a search", function() {
|
|
|
|
var ac = $("#autocomplete").autocomplete({
|
|
|
|
source: ["java", "javascript"]
|
|
|
|
}).val("ja").autocomplete("search");
|
|
|
|
same( $(".ui-menu:visible").length, 1 );
|
|
|
|
ac.blur();
|
|
|
|
same( $(".ui-menu:visible").length, 1 );
|
|
|
|
ac.autocomplete("search");
|
|
|
|
stop();
|
|
|
|
setTimeout(function() {
|
|
|
|
same( $(".ui-menu:visible").length, 1 );
|
|
|
|
start();
|
|
|
|
}, 200);
|
2010-09-27 14:10:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "prevent form submit on enter when menu is active", function() {
|
|
|
|
var event;
|
|
|
|
var ac = $( "#autocomplete" ).autocomplete({
|
|
|
|
source: [ "java", "javascript" ]
|
|
|
|
}).val( "ja" ).autocomplete( "search" );
|
|
|
|
|
|
|
|
event = $.Event( "keydown" );
|
|
|
|
event.keyCode = $.ui.keyCode.DOWN;
|
|
|
|
ac.trigger( event );
|
2011-02-24 11:05:20 +00:00
|
|
|
same( $( ".ui-menu-item:has(.ui-state-focus)" ).length, 1, "menu item is active" );
|
2010-09-27 14:10:00 +00:00
|
|
|
|
|
|
|
event = $.Event( "keydown" );
|
|
|
|
event.keyCode = $.ui.keyCode.ENTER;
|
|
|
|
ac.trigger( event );
|
|
|
|
ok( event.isDefaultPrevented(), "default action is prevented" );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "allow form submit on enter when menu is not active", function() {
|
|
|
|
var event;
|
|
|
|
var ac = $( "#autocomplete" ).autocomplete({
|
2011-03-15 09:48:31 +00:00
|
|
|
autoFocus: false,
|
2010-09-27 14:10:00 +00:00
|
|
|
source: [ "java", "javascript" ]
|
|
|
|
}).val( "ja" ).autocomplete( "search" );
|
|
|
|
|
|
|
|
event = $.Event( "keydown" );
|
|
|
|
event.keyCode = $.ui.keyCode.ENTER;
|
|
|
|
ac.trigger( event );
|
|
|
|
ok( !event.isDefaultPrevented(), "default action is prevented" );
|
|
|
|
});
|
2010-01-20 14:00:14 +00:00
|
|
|
|
|
|
|
})(jQuery);
|