From 51176d7805cb0be8ebde319083c05f30066a42b2 Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Fri, 17 Sep 2021 14:48:31 +0200 Subject: [PATCH] fix search input in domains --- public/opac/java/search_input/search_input.js | 34 +++++------ .../search_input/tests/search_input_test.js | 57 +++++++++++++------ 2 files changed, 57 insertions(+), 34 deletions(-) diff --git a/public/opac/java/search_input/search_input.js b/public/opac/java/search_input/search_input.js index c9fcc3407d2..bbecaf8d96a 100644 --- a/public/opac/java/search_input/search_input.js +++ b/public/opac/java/search_input/search_input.js @@ -15,13 +15,13 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ (function ( $ ) { $.fn.search_input = function(options) { if ($('head').find('link[href*="search_input.css"]').length < 1) { - $('head').append('<link media="screen" href="' + $('head').append('<link media="screen" href="' + baseUrl + '/public/opac/java/search_input/search_input.css" rel="stylesheet" type="text/css"></link>'); } @@ -48,7 +48,7 @@ if (options.search_path && '' === options.search_path) delete options.search_path; - + var html = $(this); var not_found_class = 'search_input_not_found'; @@ -60,7 +60,7 @@ .show(); } - + var accentsTidy = function(s){ var r = s.toLowerCase(); r = r.replace(new RegExp("[à áâãäå]", 'g'),"a"); @@ -68,7 +68,7 @@ r = r.replace(new RegExp("ç", 'g'),"c"); r = r.replace(new RegExp("[èéêë]", 'g'),"e"); r = r.replace(new RegExp("[ìÃîï]", 'g'),"i"); - r = r.replace(new RegExp("ñ", 'g'),"n"); + r = r.replace(new RegExp("ñ", 'g'),"n"); r = r.replace(new RegExp("[òóôõö]", 'g'),"o"); r = r.replace(new RegExp("Å“", 'g'),"oe"); r = r.replace(new RegExp("[ùúûü]", 'g'),"u"); @@ -76,7 +76,7 @@ return r; }; - + var highlightItems = function(elements) { resetAll(); html.find('*').not(elements).not(default_fixed_display + options.fixed_display).addClass(not_found_class); @@ -88,7 +88,7 @@ .show(); } - + var initRegex = function (searchText) { if (!searchText || searchText == "" || searchText == '*') return resetAll(); @@ -99,14 +99,14 @@ var reg_exps = []; $.each(searchText, function(index, term) { - var reg = new RegExp('\\b' + term, 'gi'); + var reg = new RegExp('\\b' + term, 'i'); reg_exps.push(reg); }); return reg_exps; }; - + var checkRegex = function (reg_exps, value) { var check = true; @@ -120,13 +120,13 @@ return check; }; - + var onSearchInputChange = function(searchText) { if (options.search_path) { searchInSpecificPath(searchText); - return; + return; } - + var reg_exps = initRegex(searchText); var matches = html.find('*').contents().filter(function() { return 3 == this.nodeType && checkRegex(reg_exps, this.nodeValue); @@ -135,7 +135,7 @@ highlightItems(matches); }; - + var searchInSpecificPath = function (searchText) { var reg_exps = initRegex(searchText); var matches = html.find(options.search_path).contents().filter(function() { @@ -152,21 +152,21 @@ .parent() .find(options.search_path) .removeClass(not_found_class); - + matches .parents() .siblings() - .removeClass(not_found_class) + .removeClass(not_found_class); matches .parents() .removeClass(not_found_class); }; - + var search_input = (undefined == options.input) ? html.prepend("<div class='search_input'>" + - "<form>" + + "<form>" + "<label for='" + options.id + "'>" + options.label + "</label>" + "<input type='text' name='search_input' id='" + options.id +"'></input>" + "</form>" + diff --git a/public/opac/java/search_input/tests/search_input_test.js b/public/opac/java/search_input/tests/search_input_test.js index 94778c7cc05..36fe67694c3 100644 --- a/public/opac/java/search_input/tests/search_input_test.js +++ b/public/opac/java/search_input/tests/search_input_test.js @@ -32,20 +32,43 @@ QUnit.module('search_widget', { +'</div>'); fixture_ul_li = $( - '<div><ul><li>' - + '<div class="sections">Listes</div>' - + '<div class="actions">Actions</div>' - + '<ul><li><div class="contents">Prems</div>' - + '<div class="actions">Actions</div></li>' - + '<li><div class="contents">Seconds</div>' - + '<div class="actions">Actions</div></li>' - + '</ul></li><li><div class="sections">Categories</div>' - + '<div class="actions">Actions</div>' - + '<ul><li><div class="contents">Premier</div>' - + '<div class="actions">Actions</div><li>' - + '<li><div class="contents">Deuxieme</div>' - + '<div class="actions">Actions</div></li>' - + '</ul></li></ul></div>'); + '<div>' + + '<ul>' + + '<li>' + + '<div class="sections">Listes</div>' + + '<div class="actions">Actions</div>' + + '<ul>' + + '<li>' + + '<div class="contents">Prems</div>' + + '<div class="actions">Actions</div>' + + '</li>' + + '<li>' + + '<div class="contents">Seconds</div>' + + '<div class="actions">Actions</div>' + + '</li>' + + '</ul>' + + '</li>' + + '<li>' + + '<div class="sections">Categories</div>' + + '<div class="actions">Actions</div>' + + '<ul>' + + '<li>' + + '<div class="contents">Premier</div>' + + '<div class="actions">Actions</div>' + + '</li>' + + '<li>' + + '<div class="contents">Premier bis</div>' + + '<div class="actions">Actions</div>' + + '</li>' + + '<li>' + + '<div class="contents">Premier ter</div>' + + '<div class="actions">Actions</div>' + + '</li>' + + '<li>' + + '<div class="contents">Deuxieme</div>' + + '<div class="actions">Actions</div>' + + '</li>' + + '</ul></li></ul></div>'); fixture.search_input({ id : 'admin_left_menu', label : '' , @@ -115,15 +138,15 @@ test('search terms "prem" should not hide li sections', function() { test('search terms "deux" should hide li contents Prems Seconds and Premier', function() { fixture_ul_li.find('input').val('deux'); fixture_ul_li.find('input').trigger($.Event( "keyup", { keyCode: 0 })); - equal(fixture_ul_li.find('div.contents.search_input_not_found').length, 3, + equal(fixture_ul_li.find('div.contents.search_input_not_found').length, 5, fixture_ul_li.html()); }); -test('search terms "deux" should hide 4 div.actions', function() { +test('search terms "deux" should hide 6 div.actions', function() { fixture_ul_li.find('input').val('deux'); fixture_ul_li.find('input').trigger($.Event( "keyup", { keyCode: 0 })); - equal(fixture_ul_li.find('div.actions.search_input_not_found').length, 4, + equal(fixture_ul_li.find('div.actions.search_input_not_found').length, 6, fixture_ul_li.html()); }); -- GitLab