jquery.suggestions: Debounce calls to $.suggestions.special
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 9 Apr 2014 12:07:49 +0000 (14:07 +0200)
committerKrinkle <krinklemail@gmail.com>
Thu, 10 Apr 2014 23:12:17 +0000 (23:12 +0000)
The custom calls used there can be comparatively expensive and it
might not be a good idea to redo them on every keystroke.

Bug: 59172
Change-Id: I0cdf53eec798a714825c94d80f100b5cf5841f5d

resources/src/jquery/jquery.suggestions.js

index 0c89b73..28c4731 100644 (file)
@@ -89,9 +89,9 @@ $.suggestions = {
         * @param {Boolean} delayed Whether or not to delay this by the currently configured amount of time
         */
        update: function ( context, delayed ) {
-               // Only fetch if the value in the textbox changed and is not empty, or if the results were hidden
-               // if the textbox is empty then clear the result div, but leave other settings intouched
                function maybeFetch() {
+                       // Only fetch if the value in the textbox changed and is not empty, or if the results were hidden
+                       // if the textbox is empty then clear the result div, but leave other settings intouched
                        if ( context.data.$textbox.val().length === 0 ) {
                                $.suggestions.hide( context );
                                context.data.prevText = '';
@@ -104,6 +104,9 @@ $.suggestions = {
                                        context.config.fetch.call( context.data.$textbox, context.data.$textbox.val() );
                                }
                        }
+
+                       // Always update special rendering
+                       $.suggestions.special( context );
                }
 
                // Cancels any delayed maybeFetch call, and invokes context.config.cancel.
@@ -116,7 +119,6 @@ $.suggestions = {
                } else {
                        maybeFetch();
                }
-               $.suggestions.special( context );
        },
 
        special: function ( context ) {