aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.autocomplete.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2012-04-03 16:47:14 -0400
committerScott González <scott.gonzalez@gmail.com>2012-04-03 16:47:14 -0400
commit96f9c84b7b2149c6b93ac226a52065652f218e1e (patch)
tree9f15376ff3cbf3726de4af4ed45494701b6804c0 /ui/jquery.ui.autocomplete.js
parent4ade13450e7145100dcce3356eb1449e1a5f7090 (diff)
downloadjquery-ui-96f9c84b7b2149c6b93ac226a52065652f218e1e.tar.gz
jquery-ui-96f9c84b7b2149c6b93ac226a52065652f218e1e.zip
Autocomplete: Move race condition logic from ajax requests to general response handler. Fixes #8234 - Autocomplete: Automatic race-condition handling for custom sources.
Diffstat (limited to 'ui/jquery.ui.autocomplete.js')
-rw-r--r--ui/jquery.ui.autocomplete.js38
1 files changed, 20 insertions, 18 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js
index 7051c90af..226d40605 100644
--- a/ui/jquery.ui.autocomplete.js
+++ b/ui/jquery.ui.autocomplete.js
@@ -186,9 +186,6 @@ $.widget( "ui.autocomplete", {
self._change( event );
});
this._initSource();
- this.response = function() {
- return self._response.apply( self, arguments );
- };
this.menu = $( "<ul></ul>" )
.addClass( "ui-autocomplete" )
.appendTo( this.document.find( this.options.appendTo || "body" )[0] )
@@ -326,18 +323,11 @@ $.widget( "ui.autocomplete", {
url: url,
data: request,
dataType: "json",
- context: {
- autocompleteRequest: ++requestIndex
- },
success: function( data, status ) {
- if ( this.autocompleteRequest === requestIndex ) {
- response( data );
- }
+ response( data );
},
error: function() {
- if ( this.autocompleteRequest === requestIndex ) {
- response( [] );
- }
+ response( [] );
}
});
};
@@ -380,10 +370,26 @@ $.widget( "ui.autocomplete", {
this.element.addClass( "ui-autocomplete-loading" );
this.cancelSearch = false;
- this.source( { term: value }, this.response );
+ this.source( { term: value }, this._response() );
+ },
+
+ _response: function() {
+ var that = this,
+ index = ++requestIndex;
+
+ return function( content ) {
+ if ( index === requestIndex ) {
+ that.__response( content );
+ }
+
+ that.pending--;
+ if ( !that.pending ) {
+ that.element.removeClass( "ui-autocomplete-loading" );
+ }
+ };
},
- _response: function( content ) {
+ __response: function( content ) {
if ( content ) {
content = this._normalize( content );
}
@@ -395,10 +401,6 @@ $.widget( "ui.autocomplete", {
// use ._close() instead of .close() so we don't cancel future searches
this._close();
}
- this.pending--;
- if ( !this.pending ) {
- this.element.removeClass( "ui-autocomplete-loading" );
- }
},
close: function( event ) {