]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Track pending requests and only remove the loading class when the last...
authorScott González <scott.gonzalez@gmail.com>
Fri, 17 Dec 2010 16:15:17 +0000 (11:15 -0500)
committerScott González <scott.gonzalez@gmail.com>
Sat, 18 Dec 2010 19:44:27 +0000 (14:44 -0500)
ui/jquery.ui.autocomplete.js

index 84d76ec0849bcb83b85b2056efad23298da9abf8..76ceb24c0856095b7e1a84df0ee376065875ee2f 100644 (file)
@@ -26,6 +26,9 @@ $.widget( "ui.autocomplete", {
                },
                source: null
        },
+
+       pending: 0,
+
        _create: function() {
                var self = this,
                        doc = this.element[ 0 ].ownerDocument,
@@ -291,6 +294,7 @@ $.widget( "ui.autocomplete", {
        },
 
        _search: function( value ) {
+               this.pending++;
                this.element.addClass( "ui-autocomplete-loading" );
 
                this.source( { term: value }, this.response );
@@ -304,7 +308,10 @@ $.widget( "ui.autocomplete", {
                } else {
                        this.close();
                }
-               this.element.removeClass( "ui-autocomplete-loading" );
+               this.pending--;
+               if ( !this.pending ) {
+                       this.element.removeClass( "ui-autocomplete-loading" );
+               }
        },
 
        close: function( event ) {