]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Refactored _response() so that requestIndex is defined closer to where...
authorScott González <scott.gonzalez@gmail.com>
Thu, 25 Apr 2013 14:59:20 +0000 (10:59 -0400)
committerScott González <scott.gonzalez@gmail.com>
Mon, 25 Nov 2013 22:26:58 +0000 (17:26 -0500)
(cherry picked from commit 947d738c0b9403da527b31ad2af3b6b9150383bd)

ui/jquery.ui.autocomplete.js

index 789f736ce5c578e4b588d772fda836c3dafd77c6..5dea7128783f225e61d4d9b1f1e03f2b09ea979f 100644 (file)
@@ -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>",
@@ -418,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 ) {