var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ];
test( "appendTo", function() {
- expect( 5 );
- var element = $( "#autocomplete" ).autocomplete();
+ expect( 7 );
+ var detached = $( "<div>" ),
+ element = $( "#autocomplete" ).autocomplete();
equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" );
element.autocomplete( "destroy" );
element.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" );
equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" );
element.autocomplete( "destroy" );
+
+ element.autocomplete({
+ appendTo: detached
+ });
+ equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached jQuery object" );
+ element.autocomplete( "destroy" );
+
+ element.autocomplete({
+ appendTo: detached[0]
+ });
+ equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element" );
+ element.autocomplete( "destroy" );
});
function autoFocusTest( afValue, focusedLength ) {
this._initSource();
this.menu = $( "<ul>" )
.addClass( "ui-autocomplete" )
- .appendTo( this.document.find( this.options.appendTo || "body" )[ 0 ] )
+ .appendTo( this._appendTo() )
.menu({
// custom key handling for now
input: $(),
}
},
+ _appendTo: function() {
+ var element = this.options.appendTo;
+ if ( element && (element.jquery || element.nodeType) ) {
+ return $( element );
+ }
+ return this.document.find( element || "body" ).eq( 0 );
+ },
+
_isMultiLine: function() {
// Textareas are always multi-line
if ( this.element.is( "textarea" ) ) {