From 3de683d135af4480a62911f4b48d287718a2fa05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Thu, 25 Apr 2013 10:59:20 -0400 Subject: [PATCH] Autocomplete: Refactored _response() so that requestIndex is defined closer to where it's used. (cherry picked from commit 947d738c0b9403da527b31ad2af3b6b9150383bd) --- ui/jquery.ui.autocomplete.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 789f736ce..5dea71287 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: "", @@ -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 ) { -- 2.39.5