aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/unit/autocomplete/autocomplete_common.js2
-rw-r--r--tests/unit/autocomplete/autocomplete_options.js8
-rw-r--r--ui/jquery.ui.autocomplete.js20
3 files changed, 21 insertions, 9 deletions
diff --git a/tests/unit/autocomplete/autocomplete_common.js b/tests/unit/autocomplete/autocomplete_common.js
index e1d24ef8d..63b24d384 100644
--- a/tests/unit/autocomplete/autocomplete_common.js
+++ b/tests/unit/autocomplete/autocomplete_common.js
@@ -1,6 +1,6 @@
TestHelpers.commonWidgetTests( "autocomplete", {
defaults: {
- appendTo: "body",
+ appendTo: null,
autoFocus: false,
delay: 300,
disabled: false,
diff --git a/tests/unit/autocomplete/autocomplete_options.js b/tests/unit/autocomplete/autocomplete_options.js
index 913f5bc28..9f0bd2d43 100644
--- a/tests/unit/autocomplete/autocomplete_options.js
+++ b/tests/unit/autocomplete/autocomplete_options.js
@@ -18,11 +18,11 @@ test( "appendTo", function() {
equal( $( "#ac-wrap2 .ui-autocomplete" ).length, 0, "only appends to one element" );
element.autocomplete( "destroy" );
- element.autocomplete({
- appendTo: null
- });
- equal( element.autocomplete( "widget" ).parent()[0], document.body, "null" );
+ $( "#ac-wrap2" ).addClass( "ui-front" );
+ element.autocomplete();
+ equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap2" )[0], "null, inside .ui-front" );
element.autocomplete( "destroy" );
+ $( "#ac-wrap2" ).removeClass( "ui-front" );
element.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" );
equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" );
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js
index a858b3382..65f702a28 100644
--- a/ui/jquery.ui.autocomplete.js
+++ b/ui/jquery.ui.autocomplete.js
@@ -23,7 +23,7 @@ $.widget( "ui.autocomplete", {
version: "@VERSION",
defaultElement: "<input>",
options: {
- appendTo: "body",
+ appendTo: null,
autoFocus: false,
delay: 300,
minLength: 1,
@@ -323,10 +323,22 @@ $.widget( "ui.autocomplete", {
_appendTo: function() {
var element = this.options.appendTo;
- if ( element && (element.jquery || element.nodeType) ) {
- return $( element );
+
+ if ( element ) {
+ element = element.jquery || element.nodeType ?
+ $( element ) :
+ this.document.find( element ).eq( 0 );
+ }
+
+ if ( !element ) {
+ element = this.element.closest( ".ui-front" );
}
- return this.document.find( element || "body" ).eq( 0 );
+
+ if ( !element.length ) {
+ element = this.document[0].body;
+ }
+
+ return element;
},
_isMultiLine: function() {