From 26d1454dfdda77a8c6e024da20f087afb3140401 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 9 Apr 2014 14:07:49 +0200 Subject: [PATCH] jquery.suggestions: Debounce calls to $.suggestions.special 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/resources/src/jquery/jquery.suggestions.js b/resources/src/jquery/jquery.suggestions.js index 0c89b7377e..28c47319fb 100644 --- a/resources/src/jquery/jquery.suggestions.js +++ b/resources/src/jquery/jquery.suggestions.js @@ -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 ) { -- 2.20.1