From 3d2ddb8c3b3eb0f1d5c697bc9dcf7faf371f6708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Grabovsk=C3=BD?= Date: Fri, 27 Mar 2015 13:38:45 +0100 Subject: [PATCH] Make catalog search case-insensitive & instantaneous --- js/catalog-search.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/catalog-search.js b/js/catalog-search.js index 07e21f87..b91fc1ea 100644 --- a/js/catalog-search.js +++ b/js/catalog-search.js @@ -21,9 +21,8 @@ var catalogSearch = function() { $controls.append($searchLabel) .append($searchBox); - $searchBox.change(function() { - var query = new RegExp(this.value, 'm'), - $found = searchThreads($threads, query); + $searchBox.keyup(function() { + var $found = searchThreads($threads, this.value); $threads.hide(); $found.show(); }); @@ -31,7 +30,8 @@ var catalogSearch = function() { // Filter threads by their content, given a regex. Can be extended later to load data // remotely and filter by multiple fields -var searchThreads = function($threads, re) { +var searchThreads = function($threads, query) { + var re = new RegExp(query, 'mi'); return $threads.filter(function() { return re.test($('.replies', this).text()); });