diff options
Diffstat (limited to 'ui/jquery.ui.autocomplete.js')
-rw-r--r-- | ui/jquery.ui.autocomplete.js | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 28cfdf2fb..2f303ca6e 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -16,9 +16,6 @@ */ (function( $, undefined ) { -// used to prevent race conditions with remote data sources -var requestIndex = 0; - $.widget( "ui.autocomplete", { version: "@VERSION", defaultElement: "<input>", @@ -77,7 +74,6 @@ $.widget( "ui.autocomplete", { this._on( this.element, { keydown: function( event ) { - /*jshint maxcomplexity:15*/ if ( this.element.prop( "readOnly" ) ) { suppressKeyPress = true; suppressInput = true; @@ -142,7 +138,9 @@ $.widget( "ui.autocomplete", { keypress: function( event ) { if ( suppressKeyPress ) { suppressKeyPress = false; - event.preventDefault(); + if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) { + event.preventDefault(); + } return; } if ( suppressKeyPressRepeat ) { @@ -417,21 +415,24 @@ $.widget( "ui.autocomplete", { this.source( { term: value }, this._response() ); }, - _response: function() { - var that = this, - index = ++requestIndex; + _response: (function() { + var requestIndex = 0; - return function( content ) { - if ( index === requestIndex ) { - that.__response( content ); - } + return function() { + var index = ++requestIndex; - that.pending--; - if ( !that.pending ) { - that.element.removeClass( "ui-autocomplete-loading" ); - } + return $.proxy(function( content ) { + if ( index === requestIndex ) { + this.__response( content ); + } + + this.pending--; + if ( !this.pending ) { + this.element.removeClass( "ui-autocomplete-loading" ); + } + }, this ); }; - }, + })(), __response: function( content ) { if ( content ) { |