From 388f9cde80649611a7bdc2a148c73a22da384021 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Fri, 27 Jul 2012 15:49:59 +0530 Subject: [PATCH] Search performance improvement Avoid calling the search for each keypress. It will make browser unresponsive. Call search on timeout. That is when user stops typing for 500 millisecond Change-Id: I93a0e5c5d1035463be9a25047134b042f6743fb8 --- resources/ext.uls.languagefilter.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/resources/ext.uls.languagefilter.js b/resources/ext.uls.languagefilter.js index 5730f98b..1a1cfe69 100644 --- a/resources/ext.uls.languagefilter.js +++ b/resources/ext.uls.languagefilter.js @@ -35,6 +35,14 @@ this.listen(); }; + var delay = function() { + var timer = 0; + return ( function( callback, milliseconds ) { + clearTimeout( timer ); + timer = setTimeout( callback, milliseconds ); + } ); + }(); + LanguageFilter.prototype = { listen: function() { @@ -57,8 +65,11 @@ this.options.$target.focus(); } default: - this.options.$target.empty(); - this.search(); + var that = this; + delay( function() { + that.options.$target.empty(); + that.search(); + }, 500 ); } },