diff options
author | Scott González <scott.gonzalez@gmail.com> | 2013-04-25 10:59:20 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2013-04-25 10:59:35 -0400 |
commit | 947d738c0b9403da527b31ad2af3b6b9150383bd (patch) | |
tree | e08f3e2f3b21e1e2fab3610795fe9061fa8c34c0 /ui/jquery.ui.autocomplete.js | |
parent | 64a39d9b0d5710729653b185eae427853608744b (diff) | |
download | jquery-ui-947d738c0b9403da527b31ad2af3b6b9150383bd.tar.gz jquery-ui-947d738c0b9403da527b31ad2af3b6b9150383bd.zip |
Autocomplete: Refactored _response() so that requestIndex is defined closer to where it's used.
Diffstat (limited to 'ui/jquery.ui.autocomplete.js')
-rw-r--r-- | ui/jquery.ui.autocomplete.js | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index e79a66a60..5e798d55d 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>", @@ -416,21 +413,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 ) { |