]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Append to closest .ui-front if available.
authorScott González <scott.gonzalez@gmail.com>
Fri, 14 Dec 2012 14:10:32 +0000 (09:10 -0500)
committerScott González <scott.gonzalez@gmail.com>
Fri, 14 Dec 2012 14:10:32 +0000 (09:10 -0500)
tests/unit/autocomplete/autocomplete_common.js
tests/unit/autocomplete/autocomplete_options.js
ui/jquery.ui.autocomplete.js

index e1d24ef8db280eccd41296e82a81c0502d9ba0d4..63b24d384b93937a93b2f1baebfa878c7a42bc9a 100644 (file)
@@ -1,6 +1,6 @@
 TestHelpers.commonWidgetTests( "autocomplete", {
        defaults: {
-               appendTo: "body",
+               appendTo: null,
                autoFocus: false,
                delay: 300,
                disabled: false,
index 913f5bc2893d1a02b05e436338060fe04be8bb94..9f0bd2d43f211b6e6775655c9946c1eb56da66ac 100644 (file)
@@ -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" );
index a858b3382987b7b88ea00b812ecee9c47d376803..65f702a284d7ec16b7045f85c4b74ba5ae834ac2 100644 (file)
@@ -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() {