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
This commit is contained in:
Santhosh Thottingal
2012-07-27 15:49:59 +05:30
parent d8038afad9
commit 388f9cde80

View File

@@ -35,6 +35,14 @@
this.listen(); this.listen();
}; };
var delay = function() {
var timer = 0;
return ( function( callback, milliseconds ) {
clearTimeout( timer );
timer = setTimeout( callback, milliseconds );
} );
}();
LanguageFilter.prototype = { LanguageFilter.prototype = {
listen: function() { listen: function() {
@@ -57,8 +65,11 @@
this.options.$target.focus(); this.options.$target.focus();
} }
default: default:
this.options.$target.empty(); var that = this;
this.search(); delay( function() {
that.options.$target.empty();
that.search();
}, 500 );
} }
}, },