]> 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>
Thu, 25 Apr 2013 14:59:35 +0000 (10:59 -0400)
ui/jquery.ui.autocomplete.js

index e79a66a60a5b87bef7dc3ac08fd48bedf2ea836b..5e798d55dcacca935a33f6a886dadead462e22b4 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>",
@@ -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 ) {