mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
parent
a6499c0dee
commit
8029cc94e1
@ -22,7 +22,7 @@ common.testWidget( "autocomplete", {
|
|||||||
},
|
},
|
||||||
source: null,
|
source: null,
|
||||||
|
|
||||||
// callbacks
|
// Callbacks
|
||||||
change: null,
|
change: null,
|
||||||
close: null,
|
close: null,
|
||||||
create: null,
|
create: null,
|
||||||
@ -32,6 +32,6 @@ common.testWidget( "autocomplete", {
|
|||||||
search: null,
|
search: null,
|
||||||
select: null
|
select: null
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
@ -12,15 +12,15 @@ test( "markup structure", function( assert ) {
|
|||||||
|
|
||||||
assert.hasClasses( element, "ui-autocomplete-input" );
|
assert.hasClasses( element, "ui-autocomplete-input" );
|
||||||
assert.hasClasses( menu, "ui-autocomplete ui-widget ui-widget-content" );
|
assert.hasClasses( menu, "ui-autocomplete ui-widget ui-widget-content" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "prevent form submit on enter when menu is active", function() {
|
test( "prevent form submit on enter when menu is active", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
var event,
|
var event,
|
||||||
element = $( "#autocomplete" )
|
element = $( "#autocomplete" )
|
||||||
.autocomplete({
|
.autocomplete( {
|
||||||
source: [ "java", "javascript" ]
|
source: [ "java", "javascript" ]
|
||||||
})
|
} )
|
||||||
.val( "ja" )
|
.val( "ja" )
|
||||||
.autocomplete( "search" ),
|
.autocomplete( "search" ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
@ -35,16 +35,16 @@ test( "prevent form submit on enter when menu is active", function() {
|
|||||||
event.keyCode = $.ui.keyCode.ENTER;
|
event.keyCode = $.ui.keyCode.ENTER;
|
||||||
element.trigger( event );
|
element.trigger( event );
|
||||||
ok( event.isDefaultPrevented(), "default action is prevented" );
|
ok( event.isDefaultPrevented(), "default action is prevented" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "allow form submit on enter when menu is not active", function() {
|
test( "allow form submit on enter when menu is not active", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
var event,
|
var event,
|
||||||
element = $( "#autocomplete" )
|
element = $( "#autocomplete" )
|
||||||
.autocomplete({
|
.autocomplete( {
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
source: [ "java", "javascript" ]
|
source: [ "java", "javascript" ]
|
||||||
})
|
} )
|
||||||
.val( "ja" )
|
.val( "ja" )
|
||||||
.autocomplete( "search" );
|
.autocomplete( "search" );
|
||||||
|
|
||||||
@ -52,90 +52,90 @@ test( "allow form submit on enter when menu is not active", function() {
|
|||||||
event.keyCode = $.ui.keyCode.ENTER;
|
event.keyCode = $.ui.keyCode.ENTER;
|
||||||
element.trigger( event );
|
element.trigger( event );
|
||||||
ok( !event.isDefaultPrevented(), "default action is prevented" );
|
ok( !event.isDefaultPrevented(), "default action is prevented" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
(function() {
|
( function() {
|
||||||
test( "up arrow invokes search - input", function() {
|
test( "up arrow invokes search - input", function() {
|
||||||
arrowsInvokeSearch( "#autocomplete", true, true );
|
arrowsInvokeSearch( "#autocomplete", true, true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "down arrow invokes search - input", function() {
|
test( "down arrow invokes search - input", function() {
|
||||||
arrowsInvokeSearch( "#autocomplete", false, true );
|
arrowsInvokeSearch( "#autocomplete", false, true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "up arrow invokes search - textarea", function() {
|
test( "up arrow invokes search - textarea", function() {
|
||||||
arrowsInvokeSearch( "#autocomplete-textarea", true, false );
|
arrowsInvokeSearch( "#autocomplete-textarea", true, false );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "down arrow invokes search - textarea", function() {
|
test( "down arrow invokes search - textarea", function() {
|
||||||
arrowsInvokeSearch( "#autocomplete-textarea", false, false );
|
arrowsInvokeSearch( "#autocomplete-textarea", false, false );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "up arrow invokes search - contenteditable", function() {
|
test( "up arrow invokes search - contenteditable", function() {
|
||||||
arrowsInvokeSearch( "#autocomplete-contenteditable", true, false );
|
arrowsInvokeSearch( "#autocomplete-contenteditable", true, false );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "down arrow invokes search - contenteditable", function() {
|
test( "down arrow invokes search - contenteditable", function() {
|
||||||
arrowsInvokeSearch( "#autocomplete-contenteditable", false, false );
|
arrowsInvokeSearch( "#autocomplete-contenteditable", false, false );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "up arrow moves focus - input", function() {
|
test( "up arrow moves focus - input", function() {
|
||||||
arrowsMoveFocus( "#autocomplete", true );
|
arrowsMoveFocus( "#autocomplete", true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "down arrow moves focus - input", function() {
|
test( "down arrow moves focus - input", function() {
|
||||||
arrowsMoveFocus( "#autocomplete", false );
|
arrowsMoveFocus( "#autocomplete", false );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "up arrow moves focus - textarea", function() {
|
test( "up arrow moves focus - textarea", function() {
|
||||||
arrowsMoveFocus( "#autocomplete-textarea", true );
|
arrowsMoveFocus( "#autocomplete-textarea", true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "down arrow moves focus - textarea", function() {
|
test( "down arrow moves focus - textarea", function() {
|
||||||
arrowsMoveFocus( "#autocomplete-textarea", false );
|
arrowsMoveFocus( "#autocomplete-textarea", false );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "up arrow moves focus - contenteditable", function() {
|
test( "up arrow moves focus - contenteditable", function() {
|
||||||
arrowsMoveFocus( "#autocomplete-contenteditable", true );
|
arrowsMoveFocus( "#autocomplete-contenteditable", true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "down arrow moves focus - contenteditable", function() {
|
test( "down arrow moves focus - contenteditable", function() {
|
||||||
arrowsMoveFocus( "#autocomplete-contenteditable", false );
|
arrowsMoveFocus( "#autocomplete-contenteditable", false );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "up arrow moves cursor - input", function() {
|
test( "up arrow moves cursor - input", function() {
|
||||||
arrowsNavigateElement( "#autocomplete", true, false );
|
arrowsNavigateElement( "#autocomplete", true, false );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "down arrow moves cursor - input", function() {
|
test( "down arrow moves cursor - input", function() {
|
||||||
arrowsNavigateElement( "#autocomplete", false, false );
|
arrowsNavigateElement( "#autocomplete", false, false );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "up arrow moves cursor - textarea", function() {
|
test( "up arrow moves cursor - textarea", function() {
|
||||||
arrowsNavigateElement( "#autocomplete-textarea", true, true );
|
arrowsNavigateElement( "#autocomplete-textarea", true, true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "down arrow moves cursor - textarea", function() {
|
test( "down arrow moves cursor - textarea", function() {
|
||||||
arrowsNavigateElement( "#autocomplete-textarea", false, true );
|
arrowsNavigateElement( "#autocomplete-textarea", false, true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "up arrow moves cursor - contenteditable", function() {
|
test( "up arrow moves cursor - contenteditable", function() {
|
||||||
arrowsNavigateElement( "#autocomplete-contenteditable", true, true );
|
arrowsNavigateElement( "#autocomplete-contenteditable", true, true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "down arrow moves cursor - contenteditable", function() {
|
test( "down arrow moves cursor - contenteditable", function() {
|
||||||
arrowsNavigateElement( "#autocomplete-contenteditable", false, true );
|
arrowsNavigateElement( "#autocomplete-contenteditable", false, true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
function arrowsInvokeSearch( id, isKeyUp, shouldMove ) {
|
function arrowsInvokeSearch( id, isKeyUp, shouldMove ) {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
|
|
||||||
var didMove = false,
|
var didMove = false,
|
||||||
element = $( id ).autocomplete({
|
element = $( id ).autocomplete( {
|
||||||
source: [ "a" ],
|
source: [ "a" ],
|
||||||
delay: 0,
|
delay: 0,
|
||||||
minLength: 0
|
minLength: 0
|
||||||
});
|
} );
|
||||||
element.autocomplete( "instance" )._move = function() {
|
element.autocomplete( "instance" )._move = function() {
|
||||||
didMove = true;
|
didMove = true;
|
||||||
};
|
};
|
||||||
@ -146,11 +146,11 @@ test( "allow form submit on enter when menu is not active", function() {
|
|||||||
function arrowsMoveFocus( id, isKeyUp ) {
|
function arrowsMoveFocus( id, isKeyUp ) {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
|
|
||||||
var element = $( id ).autocomplete({
|
var element = $( id ).autocomplete( {
|
||||||
source: [ "a" ],
|
source: [ "a" ],
|
||||||
delay: 0,
|
delay: 0,
|
||||||
minLength: 0
|
minLength: 0
|
||||||
});
|
} );
|
||||||
element.autocomplete( "instance" )._move = function() {
|
element.autocomplete( "instance" )._move = function() {
|
||||||
ok( true, "repsond to arrow" );
|
ok( true, "repsond to arrow" );
|
||||||
};
|
};
|
||||||
@ -162,25 +162,25 @@ test( "allow form submit on enter when menu is not active", function() {
|
|||||||
expect( 1 );
|
expect( 1 );
|
||||||
|
|
||||||
var didMove = false,
|
var didMove = false,
|
||||||
element = $( id ).autocomplete({
|
element = $( id ).autocomplete( {
|
||||||
source: [ "a" ],
|
source: [ "a" ],
|
||||||
delay: 0,
|
delay: 0,
|
||||||
minLength: 0
|
minLength: 0
|
||||||
});
|
} );
|
||||||
element.on( "keypress", function( e ) {
|
element.on( "keypress", function( e ) {
|
||||||
didMove = !e.isDefaultPrevented();
|
didMove = !e.isDefaultPrevented();
|
||||||
});
|
} );
|
||||||
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
|
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
|
||||||
element.simulate( "keypress" );
|
element.simulate( "keypress" );
|
||||||
equal( didMove, shouldMove, "respond to arrow" );
|
equal( didMove, shouldMove, "respond to arrow" );
|
||||||
}
|
}
|
||||||
})();
|
} )();
|
||||||
|
|
||||||
asyncTest( "past end of menu in multiline autocomplete", function() {
|
asyncTest( "past end of menu in multiline autocomplete", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
|
|
||||||
var customVal = "custom value",
|
var customVal = "custom value",
|
||||||
element = $( "#autocomplete-contenteditable" ).autocomplete({
|
element = $( "#autocomplete-contenteditable" ).autocomplete( {
|
||||||
delay: 0,
|
delay: 0,
|
||||||
source: [ "javascript" ],
|
source: [ "javascript" ],
|
||||||
focus: function( event, ui ) {
|
focus: function( event, ui ) {
|
||||||
@ -188,25 +188,25 @@ asyncTest( "past end of menu in multiline autocomplete", function() {
|
|||||||
$( this ).text( customVal );
|
$( this ).text( customVal );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
element
|
element
|
||||||
.simulate( "focus" )
|
.simulate( "focus" )
|
||||||
.autocomplete( "search", "ja" );
|
.autocomplete( "search", "ja" );
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
equal( element.text(), customVal );
|
equal( element.text(), customVal );
|
||||||
start();
|
start();
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "ESCAPE in multiline autocomplete", function() {
|
asyncTest( "ESCAPE in multiline autocomplete", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
|
|
||||||
var customVal = "custom value",
|
var customVal = "custom value",
|
||||||
element = $( "#autocomplete-contenteditable" ).autocomplete({
|
element = $( "#autocomplete-contenteditable" ).autocomplete( {
|
||||||
delay: 0,
|
delay: 0,
|
||||||
source: [ "javascript" ],
|
source: [ "javascript" ],
|
||||||
focus: function( event, ui ) {
|
focus: function( event, ui ) {
|
||||||
@ -214,38 +214,38 @@ asyncTest( "ESCAPE in multiline autocomplete", function() {
|
|||||||
$( this ).text( customVal );
|
$( this ).text( customVal );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
element
|
element
|
||||||
.simulate( "focus" )
|
.simulate( "focus" )
|
||||||
.autocomplete( "search", "ja" );
|
.autocomplete( "search", "ja" );
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
||||||
equal( element.text(), customVal );
|
equal( element.text(), customVal );
|
||||||
start();
|
start();
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "handle race condition", function() {
|
asyncTest( "handle race condition", function() {
|
||||||
expect( 3 );
|
expect( 3 );
|
||||||
var count = 0,
|
var count = 0,
|
||||||
element = $( "#autocomplete" ).autocomplete({
|
element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: function( request, response ) {
|
source: function( request, response ) {
|
||||||
count++;
|
count++;
|
||||||
if ( request.term.length === 1 ) {
|
if ( request.term.length === 1 ) {
|
||||||
equal( count, 1, "request with 1 character is first" );
|
equal( count, 1, "request with 1 character is first" );
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
response([ "one" ]);
|
response( [ "one" ] );
|
||||||
setTimeout( checkResults );
|
setTimeout( checkResults );
|
||||||
});
|
} );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
equal( count, 2, "request with 2 characters is second" );
|
equal( count, 2, "request with 2 characters is second" );
|
||||||
response([ "two" ]);
|
response( [ "two" ] );
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
element.autocomplete( "search", "a" );
|
element.autocomplete( "search", "a" );
|
||||||
element.autocomplete( "search", "ab" );
|
element.autocomplete( "search", "ab" );
|
||||||
@ -255,41 +255,41 @@ asyncTest( "handle race condition", function() {
|
|||||||
"correct results displayed" );
|
"correct results displayed" );
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "simultaneous searches (#9334)", function() {
|
asyncTest( "simultaneous searches (#9334)", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: function( request, response ) {
|
source: function( request, response ) {
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
response([ request.term ]);
|
response( [ request.term ] );
|
||||||
});
|
} );
|
||||||
},
|
},
|
||||||
response: function() {
|
response: function() {
|
||||||
ok( true, "response from first instance" );
|
ok( true, "response from first instance" );
|
||||||
}
|
}
|
||||||
}),
|
} ),
|
||||||
element2 = $( "#autocomplete-textarea" ).autocomplete({
|
element2 = $( "#autocomplete-textarea" ).autocomplete( {
|
||||||
source: function( request, response ) {
|
source: function( request, response ) {
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
response([ request.term ]);
|
response( [ request.term ] );
|
||||||
});
|
} );
|
||||||
},
|
},
|
||||||
response: function() {
|
response: function() {
|
||||||
ok( true, "response from second instance" );
|
ok( true, "response from second instance" );
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
element.autocomplete( "search", "test" );
|
element.autocomplete( "search", "test" );
|
||||||
element2.autocomplete( "search", "test" );
|
element2.autocomplete( "search", "test" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "ARIA", function() {
|
test( "ARIA", function() {
|
||||||
expect( 13 );
|
expect( 13 );
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: [ "java", "javascript" ]
|
source: [ "java", "javascript" ]
|
||||||
}),
|
} ),
|
||||||
liveRegion = element.autocomplete( "instance" ).liveRegion;
|
liveRegion = element.autocomplete( "instance" ).liveRegion;
|
||||||
|
|
||||||
equal( liveRegion.children().length, 0, "Empty live region on create" );
|
equal( liveRegion.children().length, 0, "Empty live region on create" );
|
||||||
@ -311,7 +311,7 @@ test( "ARIA", function() {
|
|||||||
|
|
||||||
element.one( "autocompletefocus", function( event ) {
|
element.one( "autocompletefocus", function( event ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
} );
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
equal( liveRegion.children().filter( ":visible" ).text(), "javascript",
|
equal( liveRegion.children().filter( ":visible" ).text(), "javascript",
|
||||||
"Live region updated when default focus is prevented" );
|
"Live region updated when default focus is prevented" );
|
||||||
@ -335,7 +335,7 @@ test( "ARIA", function() {
|
|||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
equal( liveRegion.parent().length, 0,
|
equal( liveRegion.parent().length, 0,
|
||||||
"The liveRegion should be detached after destroy" );
|
"The liveRegion should be detached after destroy" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "ARIA, aria-label announcement", function() {
|
test( "ARIA, aria-label announcement", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
@ -345,27 +345,27 @@ test( "ARIA, aria-label announcement", function() {
|
|||||||
$.each( items, function( index, item ) {
|
$.each( items, function( index, item ) {
|
||||||
that._renderItemData( ul, item )
|
that._renderItemData( ul, item )
|
||||||
.attr( "aria-label", item.category + " : " + item.label );
|
.attr( "aria-label", item.category + " : " + item.label );
|
||||||
});
|
} );
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
var element = $( "#autocomplete" ).catcomplete({
|
var element = $( "#autocomplete" ).catcomplete( {
|
||||||
source: [ { label: "anders andersson", category: "People" } ]
|
source: [ { label: "anders andersson", category: "People" } ]
|
||||||
}),
|
} ),
|
||||||
liveRegion = element.catcomplete( "instance" ).liveRegion;
|
liveRegion = element.catcomplete( "instance" ).liveRegion;
|
||||||
element.catcomplete( "search", "a" );
|
element.catcomplete( "search", "a" );
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
equal( liveRegion.children().filter( ":visible" ).text(), "People : anders andersson",
|
equal( liveRegion.children().filter( ":visible" ).text(), "People : anders andersson",
|
||||||
"Live region changed on keydown to announce the highlighted value's aria-label attribute" );
|
"Live region changed on keydown to announce the highlighted value's aria-label attribute" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "ARIA, init on detached input", function() {
|
test( "ARIA, init on detached input", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
var element = $( "<input>" ).autocomplete({
|
var element = $( "<input>" ).autocomplete( {
|
||||||
source: [ "java", "javascript" ]
|
source: [ "java", "javascript" ]
|
||||||
}),
|
} ),
|
||||||
liveRegion = element.autocomplete( "instance" ).liveRegion;
|
liveRegion = element.autocomplete( "instance" ).liveRegion;
|
||||||
equal( liveRegion.parent().length, 1, "liveRegion must have a parent" );
|
equal( liveRegion.parent().length, 1, "liveRegion must have a parent" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( ".replaceWith() (#9172)", function() {
|
test( ".replaceWith() (#9172)", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
@ -375,27 +375,27 @@ test( ".replaceWith() (#9172)", function() {
|
|||||||
parent = element.parent();
|
parent = element.parent();
|
||||||
element.replaceWith( replacement );
|
element.replaceWith( replacement );
|
||||||
equal( parent.html().toLowerCase(), replacement );
|
equal( parent.html().toLowerCase(), replacement );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "Search if the user retypes the same value (#7434)", function() {
|
asyncTest( "Search if the user retypes the same value (#7434)", function() {
|
||||||
expect( 3 );
|
expect( 3 );
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: [ "java", "javascript" ],
|
source: [ "java", "javascript" ],
|
||||||
delay: 0
|
delay: 0
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "instance" ).menu.element;
|
menu = element.autocomplete( "instance" ).menu.element;
|
||||||
|
|
||||||
element.val( "j" ).simulate( "keydown" );
|
element.val( "j" ).simulate( "keydown" );
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
ok( menu.is( ":visible" ), "menu displays initially" );
|
ok( menu.is( ":visible" ), "menu displays initially" );
|
||||||
element.trigger( "blur" );
|
element.trigger( "blur" );
|
||||||
ok( !menu.is( ":visible" ), "menu hidden after blur" );
|
ok( !menu.is( ":visible" ), "menu hidden after blur" );
|
||||||
element.val( "j" ).simulate( "keydown" );
|
element.val( "j" ).simulate( "keydown" );
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
ok( menu.is( ":visible" ), "menu displays after typing the same value" );
|
ok( menu.is( ":visible" ), "menu displays after typing the same value" );
|
||||||
start();
|
start();
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
@ -7,7 +7,7 @@ module( "autocomplete: events" );
|
|||||||
|
|
||||||
var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ];
|
var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ];
|
||||||
|
|
||||||
$.each([
|
$.each( [
|
||||||
{
|
{
|
||||||
type: "input",
|
type: "input",
|
||||||
selector: "#autocomplete",
|
selector: "#autocomplete",
|
||||||
@ -27,7 +27,7 @@ $.each([
|
|||||||
asyncTest( "all events - " + settings.type, function() {
|
asyncTest( "all events - " + settings.type, function() {
|
||||||
expect( 13 );
|
expect( 13 );
|
||||||
var element = $( settings.selector )
|
var element = $( settings.selector )
|
||||||
.autocomplete({
|
.autocomplete( {
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
source: data,
|
source: data,
|
||||||
@ -63,40 +63,41 @@ $.each([
|
|||||||
ok( menu.is( ":hidden" ), "menu closed on change" );
|
ok( menu.is( ":hidden" ), "menu closed on change" );
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
|
|
||||||
element.simulate( "focus" )[ settings.valueMethod ]( "j" ).trigger( "keydown" );
|
element.simulate( "focus" )[ settings.valueMethod ]( "j" ).trigger( "keydown" );
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
ok( menu.is( ":visible" ), "menu is visible after delay" );
|
ok( menu.is( ":visible" ), "menu is visible after delay" );
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
|
||||||
// blur must be async for IE to handle it properly
|
|
||||||
setTimeout(function() {
|
// Blur must be async for IE to handle it properly
|
||||||
|
setTimeout( function() {
|
||||||
element.simulate( "blur" );
|
element.simulate( "blur" );
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "change without selection", function() {
|
asyncTest( "change without selection", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
delay: 0,
|
delay: 0,
|
||||||
source: data,
|
source: data,
|
||||||
change: function( event, ui ) {
|
change: function( event, ui ) {
|
||||||
strictEqual( ui.item, null );
|
strictEqual( ui.item, null );
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
element.triggerHandler( "focus" );
|
element.triggerHandler( "focus" );
|
||||||
element.val( "ja" ).triggerHandler( "blur" );
|
element.val( "ja" ).triggerHandler( "blur" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "cancel search", function() {
|
asyncTest( "cancel search", function() {
|
||||||
expect( 6 );
|
expect( 6 );
|
||||||
var first = true,
|
var first = true,
|
||||||
element = $( "#autocomplete" ).autocomplete({
|
element = $( "#autocomplete" ).autocomplete( {
|
||||||
delay: 0,
|
delay: 0,
|
||||||
source: data,
|
source: data,
|
||||||
search: function() {
|
search: function() {
|
||||||
@ -110,76 +111,76 @@ asyncTest( "cancel search", function() {
|
|||||||
open: function() {
|
open: function() {
|
||||||
ok( true, "menu opened" );
|
ok( true, "menu opened" );
|
||||||
}
|
}
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
element.val( "ja" ).trigger( "keydown" );
|
element.val( "ja" ).trigger( "keydown" );
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
ok( menu.is( ":hidden" ), "menu is hidden after first search" );
|
ok( menu.is( ":hidden" ), "menu is hidden after first search" );
|
||||||
element.val( "java" ).trigger( "keydown" );
|
element.val( "java" ).trigger( "keydown" );
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
ok( menu.is( ":visible" ), "menu is visible after second search" );
|
ok( menu.is( ":visible" ), "menu is visible after second search" );
|
||||||
equal( menu.find( ".ui-menu-item" ).length, 2, "# of menu items" );
|
equal( menu.find( ".ui-menu-item" ).length, 2, "# of menu items" );
|
||||||
start();
|
start();
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "cancel focus", function() {
|
asyncTest( "cancel focus", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
var customVal = "custom value",
|
var customVal = "custom value",
|
||||||
element = $( "#autocomplete" ).autocomplete({
|
element = $( "#autocomplete" ).autocomplete( {
|
||||||
delay: 0,
|
delay: 0,
|
||||||
source: data,
|
source: data,
|
||||||
focus: function() {
|
focus: function() {
|
||||||
$( this ).val( customVal );
|
$( this ).val( customVal );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
element.val( "ja" ).trigger( "keydown" );
|
element.val( "ja" ).trigger( "keydown" );
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
equal( element.val(), customVal );
|
equal( element.val(), customVal );
|
||||||
start();
|
start();
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "cancel select", function() {
|
asyncTest( "cancel select", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
var customVal = "custom value",
|
var customVal = "custom value",
|
||||||
element = $( "#autocomplete" ).autocomplete({
|
element = $( "#autocomplete" ).autocomplete( {
|
||||||
delay: 0,
|
delay: 0,
|
||||||
source: data,
|
source: data,
|
||||||
select: function() {
|
select: function() {
|
||||||
$( this ).val( customVal );
|
$( this ).val( customVal );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
element.val( "ja" ).trigger( "keydown" );
|
element.val( "ja" ).trigger( "keydown" );
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
|
||||||
equal( element.val(), customVal );
|
equal( element.val(), customVal );
|
||||||
start();
|
start();
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "blur during remote search", function() {
|
asyncTest( "blur during remote search", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
var ac = $( "#autocomplete" ).autocomplete({
|
var ac = $( "#autocomplete" ).autocomplete( {
|
||||||
delay: 0,
|
delay: 0,
|
||||||
source: function( request, response ) {
|
source: function( request, response ) {
|
||||||
ok( true, "trigger request" );
|
ok( true, "trigger request" );
|
||||||
ac.simulate( "blur" );
|
ac.simulate( "blur" );
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
response([ "result" ]);
|
response( [ "result" ] );
|
||||||
start();
|
start();
|
||||||
}, 25);
|
}, 25 );
|
||||||
},
|
},
|
||||||
open: function() {
|
open: function() {
|
||||||
ok( false, "opened after a blur" );
|
ok( false, "opened after a blur" );
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
ac.val( "ro" ).trigger( "keydown" );
|
ac.val( "ro" ).trigger( "keydown" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
@ -9,16 +9,16 @@ test( "destroy", function( assert ) {
|
|||||||
expect( 1 );
|
expect( 1 );
|
||||||
assert.domEqual( "#autocomplete", function() {
|
assert.domEqual( "#autocomplete", function() {
|
||||||
$( "#autocomplete" ).autocomplete().autocomplete( "destroy" );
|
$( "#autocomplete" ).autocomplete().autocomplete( "destroy" );
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "search, close", function() {
|
test( "search, close", function() {
|
||||||
expect( 6 );
|
expect( 6 );
|
||||||
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ],
|
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ],
|
||||||
element = $( "#autocomplete" ).autocomplete({
|
element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: data,
|
source: data,
|
||||||
minLength: 0
|
minLength: 0
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
|
|
||||||
ok( menu.is( ":hidden" ), "menu is hidden on init" );
|
ok( menu.is( ":hidden" ), "menu is hidden on init" );
|
||||||
@ -35,7 +35,7 @@ test( "search, close", function() {
|
|||||||
|
|
||||||
element.autocomplete( "close" );
|
element.autocomplete( "close" );
|
||||||
ok( menu.is( ":hidden" ), "menu is hidden after close" );
|
ok( menu.is( ":hidden" ), "menu is hidden after close" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "widget", function( assert ) {
|
test( "widget", function( assert ) {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
@ -43,6 +43,6 @@ test( "widget", function( assert ) {
|
|||||||
widgetElement = element.autocomplete( "widget" );
|
widgetElement = element.autocomplete( "widget" );
|
||||||
equal( widgetElement.length, 1, "one element" );
|
equal( widgetElement.length, 1, "one element" );
|
||||||
assert.hasClasses( widgetElement, "ui-menu" );
|
assert.hasClasses( widgetElement, "ui-menu" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
@ -14,16 +14,16 @@ test( "appendTo: null", function() {
|
|||||||
equal( element.autocomplete( "widget" ).parent()[ 0 ], document.body,
|
equal( element.autocomplete( "widget" ).parent()[ 0 ], document.body,
|
||||||
"defaults to body" );
|
"defaults to body" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "appendTo: explicit", function() {
|
test( "appendTo: explicit", function() {
|
||||||
expect( 6 );
|
expect( 6 );
|
||||||
var detached = $( "<div>" ),
|
var detached = $( "<div>" ),
|
||||||
element = $( "#autocomplete" );
|
element = $( "#autocomplete" );
|
||||||
|
|
||||||
element.autocomplete({
|
element.autocomplete( {
|
||||||
appendTo: ".autocomplete-wrap"
|
appendTo: ".autocomplete-wrap"
|
||||||
});
|
} );
|
||||||
equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
||||||
$( "#autocomplete-wrap1" )[ 0 ], "first found element" );
|
$( "#autocomplete-wrap1" )[ 0 ], "first found element" );
|
||||||
equal( $( "#autocomplete-wrap2 .ui-autocomplete" ).length, 0,
|
equal( $( "#autocomplete-wrap2 .ui-autocomplete" ).length, 0,
|
||||||
@ -35,16 +35,16 @@ test( "appendTo: explicit", function() {
|
|||||||
$( "#autocomplete-wrap1" )[ 0 ], "modified after init" );
|
$( "#autocomplete-wrap1" )[ 0 ], "modified after init" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
|
|
||||||
element.autocomplete({
|
element.autocomplete( {
|
||||||
appendTo: detached
|
appendTo: detached
|
||||||
});
|
} );
|
||||||
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
||||||
"detached jQuery object" );
|
"detached jQuery object" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
|
|
||||||
element.autocomplete({
|
element.autocomplete( {
|
||||||
appendTo: detached[ 0 ]
|
appendTo: detached[ 0 ]
|
||||||
});
|
} );
|
||||||
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
||||||
"detached DOM element" );
|
"detached DOM element" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
@ -53,7 +53,7 @@ test( "appendTo: explicit", function() {
|
|||||||
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
||||||
"detached DOM element via option()" );
|
"detached DOM element via option()" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "appendTo: ui-front", function() {
|
test( "appendTo: ui-front", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
@ -65,15 +65,15 @@ test( "appendTo: ui-front", function() {
|
|||||||
$( "#autocomplete-wrap2" )[ 0 ], "null, inside .ui-front" );
|
$( "#autocomplete-wrap2" )[ 0 ], "null, inside .ui-front" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
|
|
||||||
element.autocomplete({
|
element.autocomplete( {
|
||||||
appendTo: $()
|
appendTo: $()
|
||||||
});
|
} );
|
||||||
equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
||||||
$( "#autocomplete-wrap2" )[ 0 ], "empty jQuery object, inside .ui-front" );
|
$( "#autocomplete-wrap2" )[ 0 ], "empty jQuery object, inside .ui-front" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
function autoFocusTest( afValue, focusedLength ) {
|
function autoFocusTest( afValue, focusedLength ) {
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
autoFocus: afValue,
|
autoFocus: afValue,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
source: data,
|
source: data,
|
||||||
@ -83,10 +83,10 @@ function autoFocusTest( afValue, focusedLength ) {
|
|||||||
.find( ".ui-menu-item-wrapper.ui-state-active" )
|
.find( ".ui-menu-item-wrapper.ui-state-active" )
|
||||||
.length,
|
.length,
|
||||||
focusedLength,
|
focusedLength,
|
||||||
"first item is " + (afValue ? "" : "not") + " auto focused" );
|
"first item is " + ( afValue ? "" : "not" ) + " auto focused" );
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
element.val( "ja" ).trigger( "keydown" );
|
element.val( "ja" ).trigger( "keydown" );
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
@ -94,36 +94,36 @@ function autoFocusTest( afValue, focusedLength ) {
|
|||||||
test( "autoFocus: false", function() {
|
test( "autoFocus: false", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
autoFocusTest( false, 0 );
|
autoFocusTest( false, 0 );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "autoFocus: true", function() {
|
test( "autoFocus: true", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
autoFocusTest( true, 1 );
|
autoFocusTest( true, 1 );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "delay", function() {
|
asyncTest( "delay", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: data,
|
source: data,
|
||||||
delay: 25
|
delay: 25
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
element.val( "ja" ).trigger( "keydown" );
|
element.val( "ja" ).trigger( "keydown" );
|
||||||
|
|
||||||
ok( menu.is( ":hidden" ), "menu is closed immediately after search" );
|
ok( menu.is( ":hidden" ), "menu is closed immediately after search" );
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
ok( menu.is( ":visible" ), "menu is open after delay" );
|
ok( menu.is( ":visible" ), "menu is open after delay" );
|
||||||
start();
|
start();
|
||||||
}, 50 );
|
}, 50 );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "disabled", function( assert ) {
|
asyncTest( "disabled", function( assert ) {
|
||||||
expect( 5 );
|
expect( 5 );
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: data,
|
source: data,
|
||||||
delay: 0
|
delay: 0
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "disable" ).autocomplete( "widget" );
|
menu = element.autocomplete( "disable" ).autocomplete( "widget" );
|
||||||
element.val( "ja" ).trigger( "keydown" );
|
element.val( "ja" ).trigger( "keydown" );
|
||||||
|
|
||||||
@ -133,17 +133,17 @@ asyncTest( "disabled", function( assert ) {
|
|||||||
assert.hasClasses( menu, "ui-autocomplete-disabled" );
|
assert.hasClasses( menu, "ui-autocomplete-disabled" );
|
||||||
ok( !element.attr( "aria-disabled" ), "element doesn't get aria-disabled" );
|
ok( !element.attr( "aria-disabled" ), "element doesn't get aria-disabled" );
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
ok( menu.is( ":hidden" ) );
|
ok( menu.is( ":hidden" ) );
|
||||||
start();
|
start();
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "minLength", function() {
|
test( "minLength", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: data
|
source: data
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
element.autocomplete( "search", "" );
|
element.autocomplete( "search", "" );
|
||||||
ok( menu.is( ":hidden" ), "blank not enough for minLength: 1" );
|
ok( menu.is( ":hidden" ), "blank not enough for minLength: 1" );
|
||||||
@ -151,19 +151,19 @@ test( "minLength", function() {
|
|||||||
element.autocomplete( "option", "minLength", 0 );
|
element.autocomplete( "option", "minLength", 0 );
|
||||||
element.autocomplete( "search", "" );
|
element.autocomplete( "search", "" );
|
||||||
ok( menu.is( ":visible" ), "blank enough for minLength: 0" );
|
ok( menu.is( ":visible" ), "blank enough for minLength: 0" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
asyncTest( "minLength, exceed then drop below", function() {
|
asyncTest( "minLength, exceed then drop below", function() {
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
minLength: 2,
|
minLength: 2,
|
||||||
source: function( req, res ) {
|
source: function( req, res ) {
|
||||||
equal( req.term, "12", "correct search term" );
|
equal( req.term, "12", "correct search term" );
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
res([ "item" ]);
|
res( [ "item" ] );
|
||||||
});
|
} );
|
||||||
}
|
}
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
|
|
||||||
ok( menu.is( ":hidden" ), "menu is hidden before first search" );
|
ok( menu.is( ":hidden" ), "menu is hidden before first search" );
|
||||||
@ -172,55 +172,57 @@ asyncTest( "minLength, exceed then drop below", function() {
|
|||||||
ok( menu.is( ":hidden" ), "menu is hidden before second search" );
|
ok( menu.is( ":hidden" ), "menu is hidden before second search" );
|
||||||
element.autocomplete( "search", "1" );
|
element.autocomplete( "search", "1" );
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout( function() {
|
||||||
ok( menu.is( ":hidden" ), "menu is hidden after searches" );
|
ok( menu.is( ":hidden" ), "menu is hidden after searches" );
|
||||||
start();
|
start();
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "minLength, exceed then drop below then exceed", function() {
|
test( "minLength, exceed then drop below then exceed", function() {
|
||||||
expect( 3 );
|
expect( 3 );
|
||||||
var _res = [],
|
var _res = [],
|
||||||
element = $( "#autocomplete" ).autocomplete({
|
element = $( "#autocomplete" ).autocomplete( {
|
||||||
minLength: 2,
|
minLength: 2,
|
||||||
source: function( req, res ) {
|
source: function( req, res ) {
|
||||||
_res.push( res );
|
_res.push( res );
|
||||||
}
|
}
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
|
|
||||||
// trigger a valid search
|
// Trigger a valid search
|
||||||
ok( menu.is( ":hidden" ), "menu is hidden before first search" );
|
ok( menu.is( ":hidden" ), "menu is hidden before first search" );
|
||||||
element.autocomplete( "search", "12" );
|
element.autocomplete( "search", "12" );
|
||||||
|
|
||||||
// trigger a search below the minLength, to turn on cancelSearch flag
|
// Trigger a search below the minLength, to turn on cancelSearch flag
|
||||||
ok( menu.is( ":hidden" ), "menu is hidden before second search" );
|
ok( menu.is( ":hidden" ), "menu is hidden before second search" );
|
||||||
element.autocomplete( "search", "1" );
|
element.autocomplete( "search", "1" );
|
||||||
|
|
||||||
// trigger a valid search
|
// Trigger a valid search
|
||||||
element.autocomplete( "search", "13" );
|
element.autocomplete( "search", "13" );
|
||||||
// react as if the first search was cancelled (default ajax behavior)
|
|
||||||
_res[ 0 ]([]);
|
// React as if the first search was cancelled (default ajax behavior)
|
||||||
// react to second search
|
_res[ 0 ]( [] );
|
||||||
_res[ 1 ]([ "13" ]);
|
|
||||||
|
// React to second search
|
||||||
|
_res[ 1 ]( [ "13" ] );
|
||||||
|
|
||||||
ok( menu.is( ":visible" ), "menu is visible after searches" );
|
ok( menu.is( ":visible" ), "menu is visible after searches" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "source, local string array", function() {
|
test( "source, local string array", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: data
|
source: data
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
element.val( "ja" ).autocomplete( "search" );
|
element.val( "ja" ).autocomplete( "search" );
|
||||||
equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
|
equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
function sourceTest( source, async ) {
|
function sourceTest( source, async ) {
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: source
|
source: source
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
function result() {
|
function result() {
|
||||||
var items = menu.find( ".ui-menu-item" );
|
var items = menu.find( ".ui-menu-item" );
|
||||||
@ -228,15 +230,15 @@ function sourceTest( source, async ) {
|
|||||||
deepEqual( items.eq( 0 ).data( "ui-autocomplete-item" ), {
|
deepEqual( items.eq( 0 ).data( "ui-autocomplete-item" ), {
|
||||||
label: "java",
|
label: "java",
|
||||||
value: "java"
|
value: "java"
|
||||||
});
|
} );
|
||||||
deepEqual( items.eq( 1 ).data( "ui-autocomplete-item" ), {
|
deepEqual( items.eq( 1 ).data( "ui-autocomplete-item" ), {
|
||||||
label: "javascript",
|
label: "javascript",
|
||||||
value: "javascript"
|
value: "javascript"
|
||||||
});
|
} );
|
||||||
deepEqual( items.eq( 2 ).data( "ui-autocomplete-item" ), {
|
deepEqual( items.eq( 2 ).data( "ui-autocomplete-item" ), {
|
||||||
label: "clojure",
|
label: "clojure",
|
||||||
value: "clojure"
|
value: "clojure"
|
||||||
});
|
} );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
if ( async ) {
|
if ( async ) {
|
||||||
start();
|
start();
|
||||||
@ -254,64 +256,64 @@ function sourceTest( source, async ) {
|
|||||||
|
|
||||||
test( "source, local object array, only labels", function() {
|
test( "source, local object array, only labels", function() {
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
sourceTest([
|
sourceTest( [
|
||||||
{ label: "java", value: null },
|
{ label: "java", value: null },
|
||||||
{ label: "php", value: null },
|
{ label: "php", value: null },
|
||||||
{ label: "coldfusion", value: "" },
|
{ label: "coldfusion", value: "" },
|
||||||
{ label: "javascript", value: "" },
|
{ label: "javascript", value: "" },
|
||||||
{ label: "clojure" }
|
{ label: "clojure" }
|
||||||
]);
|
] );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "source, local object array, only values", function() {
|
test( "source, local object array, only values", function() {
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
sourceTest([
|
sourceTest( [
|
||||||
{ value: "java", label: null },
|
{ value: "java", label: null },
|
||||||
{ value: "php", label: null },
|
{ value: "php", label: null },
|
||||||
{ value: "coldfusion", label: "" },
|
{ value: "coldfusion", label: "" },
|
||||||
{ value: "javascript", label: "" },
|
{ value: "javascript", label: "" },
|
||||||
{ value: "clojure" }
|
{ value: "clojure" }
|
||||||
]);
|
] );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "source, url string with remote json string array", function() {
|
test( "source, url string with remote json string array", function() {
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
sourceTest( "remote_string_array.txt", true );
|
sourceTest( "remote_string_array.txt", true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "source, url string with remote json object array, only value properties", function() {
|
test( "source, url string with remote json object array, only value properties", function() {
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
sourceTest( "remote_object_array_values.txt", true );
|
sourceTest( "remote_object_array_values.txt", true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "source, url string with remote json object array, only label properties", function() {
|
test( "source, url string with remote json object array, only label properties", function() {
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
sourceTest( "remote_object_array_labels.txt", true );
|
sourceTest( "remote_object_array_labels.txt", true );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "source, custom", function() {
|
test( "source, custom", function() {
|
||||||
expect( 5 );
|
expect( 5 );
|
||||||
sourceTest(function( request, response ) {
|
sourceTest( function( request, response ) {
|
||||||
equal( request.term, "j" );
|
equal( request.term, "j" );
|
||||||
response([
|
response( [
|
||||||
"java",
|
"java",
|
||||||
{ label: "javascript", value: null },
|
{ label: "javascript", value: null },
|
||||||
{ value: "clojure", label: null }
|
{ value: "clojure", label: null }
|
||||||
]);
|
] );
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
|
|
||||||
test( "source, update after init", function() {
|
test( "source, update after init", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
var element = $( "#autocomplete" ).autocomplete({
|
var element = $( "#autocomplete" ).autocomplete( {
|
||||||
source: [ "java", "javascript", "haskell" ]
|
source: [ "java", "javascript", "haskell" ]
|
||||||
}),
|
} ),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
element.val( "ja" ).autocomplete( "search" );
|
element.val( "ja" ).autocomplete( "search" );
|
||||||
equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
|
equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
|
||||||
element.autocomplete( "option", "source", [ "php", "asp" ] );
|
element.autocomplete( "option", "source", [ "php", "asp" ] );
|
||||||
element.val( "ph" ).autocomplete( "search" );
|
element.val( "ph" ).autocomplete( "search" );
|
||||||
equal( menu.find( ".ui-menu-item" ).text(), "php" );
|
equal( menu.find( ".ui-menu-item" ).text(), "php" );
|
||||||
});
|
} );
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
@ -51,7 +51,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
},
|
},
|
||||||
source: null,
|
source: null,
|
||||||
|
|
||||||
// callbacks
|
// Callbacks
|
||||||
change: null,
|
change: null,
|
||||||
close: null,
|
close: null,
|
||||||
focus: null,
|
focus: null,
|
||||||
@ -165,7 +165,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// replicate some key handlers to allow them to repeat in Firefox and Opera
|
// Replicate some key handlers to allow them to repeat in Firefox and Opera
|
||||||
var keyCode = $.ui.keyCode;
|
var keyCode = $.ui.keyCode;
|
||||||
switch ( event.keyCode ) {
|
switch ( event.keyCode ) {
|
||||||
case keyCode.PAGE_UP:
|
case keyCode.PAGE_UP:
|
||||||
@ -239,7 +239,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// clicking on the scrollbar causes focus to shift to the body
|
// Clicking on the scrollbar causes focus to shift to the body
|
||||||
// but we can't detect a mouseup or a click immediately afterward
|
// but we can't detect a mouseup or a click immediately afterward
|
||||||
// so we have to track the next mousedown and close the menu if
|
// so we have to track the next mousedown and close the menu if
|
||||||
// the user clicks somewhere outside of the autocomplete
|
// the user clicks somewhere outside of the autocomplete
|
||||||
@ -293,7 +293,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
var item = ui.item.data( "ui-autocomplete-item" ),
|
var item = ui.item.data( "ui-autocomplete-item" ),
|
||||||
previous = this.previous;
|
previous = this.previous;
|
||||||
|
|
||||||
// only trigger when focus was lost (click on menu)
|
// Only trigger when focus was lost (click on menu)
|
||||||
if ( this.element[ 0 ] !== $.ui.safeActiveElement( this.document[ 0 ] ) ) {
|
if ( this.element[ 0 ] !== $.ui.safeActiveElement( this.document[ 0 ] ) ) {
|
||||||
this.element.trigger( "focus" );
|
this.element.trigger( "focus" );
|
||||||
this.previous = previous;
|
this.previous = previous;
|
||||||
@ -327,7 +327,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
|
|
||||||
this._addClass( this.liveRegion, null, "ui-helper-hidden-accessible" );
|
this._addClass( this.liveRegion, null, "ui-helper-hidden-accessible" );
|
||||||
|
|
||||||
// turning off autocomplete prevents the browser from remembering the
|
// Turning off autocomplete prevents the browser from remembering the
|
||||||
// value when navigating through history, so we re-enable autocomplete
|
// value when navigating through history, so we re-enable autocomplete
|
||||||
// if the page is unloaded before the widget is destroyed. #7790
|
// if the page is unloaded before the widget is destroyed. #7790
|
||||||
this._on( this.window, {
|
this._on( this.window, {
|
||||||
@ -427,7 +427,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
search: function( value, event ) {
|
search: function( value, event ) {
|
||||||
value = value != null ? value : this._value();
|
value = value != null ? value : this._value();
|
||||||
|
|
||||||
// always save the actual value, not the one passed as an argument
|
// Always save the actual value, not the one passed as an argument
|
||||||
this.term = this._value();
|
this.term = this._value();
|
||||||
|
|
||||||
if ( value.length < this.options.minLength ) {
|
if ( value.length < this.options.minLength ) {
|
||||||
@ -523,7 +523,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
this.isNewMenu = true;
|
this.isNewMenu = true;
|
||||||
this.menu.refresh();
|
this.menu.refresh();
|
||||||
|
|
||||||
// size and position menu
|
// Size and position menu
|
||||||
ul.show();
|
ul.show();
|
||||||
this._resizeMenu();
|
this._resizeMenu();
|
||||||
ul.position( $.extend( {
|
ul.position( $.extend( {
|
||||||
@ -592,7 +592,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
|
if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
|
||||||
this._move( keyEvent, event );
|
this._move( keyEvent, event );
|
||||||
|
|
||||||
// prevents moving cursor to beginning/end of the text field in some browsers
|
// Prevents moving cursor to beginning/end of the text field in some browsers
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -610,7 +610,7 @@ $.extend( $.ui.autocomplete, {
|
|||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// live region extension, adding a `messages` option
|
// Live region extension, adding a `messages` option
|
||||||
// NOTE: This is an experimental API. We are still investigating
|
// NOTE: This is an experimental API. We are still investigating
|
||||||
// a full solution for string manipulation and internationalization.
|
// a full solution for string manipulation and internationalization.
|
||||||
$.widget( "ui.autocomplete", $.ui.autocomplete, {
|
$.widget( "ui.autocomplete", $.ui.autocomplete, {
|
||||||
|
Loading…
Reference in New Issue
Block a user