2011-06-13 18:09:44 +00:00
|
|
|
(function( $ ) {
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2011-06-13 18:09:44 +00:00
|
|
|
module( "autocomplete: core" );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2011-06-13 18:09:44 +00:00
|
|
|
asyncTest( "close-on-blur is properly delayed", function() {
|
|
|
|
expect( 3 );
|
|
|
|
var element = $( "#autocomplete" )
|
|
|
|
.autocomplete({
|
|
|
|
source: [ "java", "javascript" ]
|
|
|
|
})
|
|
|
|
.val( "ja" )
|
|
|
|
.autocomplete( "search" ),
|
|
|
|
menu = element.autocomplete( "widget" );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2011-06-13 18:09:44 +00:00
|
|
|
ok( menu.is( ":visible" ) );
|
|
|
|
element.blur();
|
|
|
|
ok( menu.is( ":visible" ) );
|
2010-01-20 14:00:14 +00:00
|
|
|
setTimeout(function() {
|
2011-06-13 18:09:44 +00:00
|
|
|
ok( menu.is( ":hidden") );
|
2010-01-20 14:00:14 +00:00
|
|
|
start();
|
2011-06-13 18:09:44 +00:00
|
|
|
}, 200 );
|
2010-09-27 14:10:00 +00:00
|
|
|
});
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2011-06-13 18:09:44 +00:00
|
|
|
asyncTest( "close-on-blur is cancelled when starting a search", function() {
|
|
|
|
expect( 3 );
|
|
|
|
var element = $( "#autocomplete" )
|
|
|
|
.autocomplete({
|
|
|
|
source: [ "java", "javascript" ]
|
|
|
|
})
|
|
|
|
.val( "ja" )
|
|
|
|
.autocomplete( "search" ),
|
|
|
|
menu = element.autocomplete( "widget" );
|
|
|
|
|
|
|
|
ok( menu.is( ":visible" ) );
|
|
|
|
element.blur();
|
|
|
|
ok( menu.is( ":visible" ) );
|
|
|
|
element.autocomplete( "search" );
|
2010-01-20 14:00:14 +00:00
|
|
|
setTimeout(function() {
|
2011-06-13 18:09:44 +00:00
|
|
|
ok( menu.is( ":visible" ) );
|
2010-01-20 14:00:14 +00:00
|
|
|
start();
|
2011-06-13 18:09:44 +00:00
|
|
|
}, 200 );
|
2010-09-27 14:10:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "prevent form submit on enter when menu is active", function() {
|
2011-06-13 18:09:44 +00:00
|
|
|
expect( 2 );
|
|
|
|
var event,
|
|
|
|
element = $( "#autocomplete" )
|
|
|
|
.autocomplete({
|
|
|
|
source: [ "java", "javascript" ]
|
|
|
|
})
|
|
|
|
.val( "ja" )
|
|
|
|
.autocomplete( "search" ),
|
|
|
|
menu = element.autocomplete( "widget" );
|
|
|
|
|
2010-09-27 14:10:00 +00:00
|
|
|
event = $.Event( "keydown" );
|
|
|
|
event.keyCode = $.ui.keyCode.DOWN;
|
2011-06-13 18:09:44 +00:00
|
|
|
element.trigger( event );
|
|
|
|
deepEqual( menu.find( ".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;
|
2011-06-13 18:09:44 +00:00
|
|
|
element.trigger( event );
|
2010-09-27 14:10:00 +00:00
|
|
|
ok( event.isDefaultPrevented(), "default action is prevented" );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "allow form submit on enter when menu is not active", function() {
|
2011-06-13 18:09:44 +00:00
|
|
|
expect( 1 );
|
|
|
|
var event,
|
|
|
|
element = $( "#autocomplete" )
|
|
|
|
.autocomplete({
|
|
|
|
autoFocus: false,
|
|
|
|
source: [ "java", "javascript" ]
|
|
|
|
})
|
|
|
|
.val( "ja" )
|
|
|
|
.autocomplete( "search" );
|
|
|
|
|
2010-09-27 14:10:00 +00:00
|
|
|
event = $.Event( "keydown" );
|
|
|
|
event.keyCode = $.ui.keyCode.ENTER;
|
2011-06-13 18:09:44 +00:00
|
|
|
element.trigger( event );
|
2010-09-27 14:10:00 +00:00
|
|
|
ok( !event.isDefaultPrevented(), "default action is prevented" );
|
|
|
|
});
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2011-06-13 18:09:44 +00:00
|
|
|
}( jQuery ) );
|