From 9bcf66bab64d4b9801947294b1e39b24499895a6 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Fri, 13 May 2011 18:15:58 -0400 Subject: [PATCH 1/2] Autocomplete: Updating position when target is dragged or resized. Fixed #6642 - autocomplete cannot be used inside a dialog --- ui/jquery.ui.autocomplete.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 0e62ccfdb62..8f334e98472 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -170,6 +170,18 @@ $.widget( "ui.autocomplete", { self._change( event ); }, 150 ); }); + + // dragging or resizing the appendTo element or any of its descendants should + // cause the menu's position to be recalculated + $( this.options.appendTo || "body", doc ).bind( "drag.autocomplete, resize.autocomplete", function( event ) { + if ( self.menu.element.is(":hidden") ) return; + setTimeout( function() { + self.menu.element.position( $.extend({ + of: self.element + }, self.options.position )).zIndex( self.element.zIndex() + 1 ); + }, 0 ); + }); + this._initSource(); this.response = function() { return self._response.apply( self, arguments ); From ad36cca95189a4c3cb3030e05d419bcc6801c974 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Fri, 13 May 2011 18:41:02 -0400 Subject: [PATCH 2/2] Autocomplete: Caching appendTo element (optimization) --- ui/jquery.ui.autocomplete.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 8f334e98472..7fee70c2f28 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -47,6 +47,7 @@ $.widget( "ui.autocomplete", { _create: function() { var self = this, doc = this.element[ 0 ].ownerDocument, + appendToEl = $( this.options.appendTo || "body", doc ), suppressKeyPress; this.valueMethod = this.element[ this.element.is( "input" ) ? "val" : "text" ]; @@ -170,10 +171,10 @@ $.widget( "ui.autocomplete", { self._change( event ); }, 150 ); }); - + // dragging or resizing the appendTo element or any of its descendants should // cause the menu's position to be recalculated - $( this.options.appendTo || "body", doc ).bind( "drag.autocomplete, resize.autocomplete", function( event ) { + appendToEl.bind( "drag.autocomplete, resize.autocomplete", function( event ) { if ( self.menu.element.is(":hidden") ) return; setTimeout( function() { self.menu.element.position( $.extend({ @@ -188,7 +189,7 @@ $.widget( "ui.autocomplete", { }; this.menu = $( "" ) .addClass( "ui-autocomplete" ) - .appendTo( $( this.options.appendTo || "body", doc )[0] ) + .appendTo( appendToEl ) // prevent the close-on-blur in case of a "slow" click on the menu (long mousedown) .mousedown(function( event ) { // clicking on the scrollbar causes focus to shift to the body @@ -379,7 +380,7 @@ $.widget( "ui.autocomplete", { this._trigger( "close", event ); } }, - + _change: function( event ) { if ( this.previous !== this._value() ) { this._trigger( "change", event, { item: this.selectedItem } );