Skip to content
Permalink
Browse files

Autocomplete: Refactored _response() so that requestIndex is defined …

…closer to where it's used.
  • Loading branch information
scottgonzalez committed Apr 25, 2013
1 parent 64a39d9 commit 947d738c0b9403da527b31ad2af3b6b9150383bd
Showing with 15 additions and 15 deletions.
  1. +15 −15 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 ) {

0 comments on commit 947d738

Please sign in to comment.
You can’t perform that action at this time.