From 036c9f8701d0bde45f832010b4e72e30bdb85de4 Mon Sep 17 00:00:00 2001 From: Andreas Roussos Date: Sat, 27 Nov 2021 07:38:44 +0100 Subject: [PATCH] Bug 29578: Upgrade the jQuery highlighter plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Under certain conditions, the jQuery term highlighter can break and in the process actually make the "Highlight"/"Unhighlight" button disappear altogether. This affects catalog searches in both the OPAC and the Staff Client. This patch fixes that by upgrading the plugin to its latest version. Test plan: 0) Catalogue two books using the titles below, one of which includes a word ("τοῖς") containing Greek diacritics: Book #1 title: Συλλογής των εν επιτομή τοῖς πάλαι γεωγραφηθέντων Book #2 title: Επιτομή της ιστορίας των Βαλκανικών Πολέμων (1912-1913) Then, perform a catalog search for "επιτομή των" (without the quotes). In the results page, notice that: a) the "Highlight"/"Unhighlight" button has disappeared, and b) not all search terms are highlighted (e.g. "των" in the 2nd book) 1) Apply this patch. 2) Repeat the same search (remember to press CTRL-F5 to refresh JS code). This time the "Highlight"/"Unhighlight" button is displayed normally, and all instances of your search terms are highlighted in the results. Signed-off-by: ThibaudGLT Work on Firefox 94.0-Ubuntu 20.04LTS --- .../intranet-tmpl/lib/jquery/plugins/jquery.highlight-3.js | 7 ++++--- .../bootstrap/lib/jquery/plugins/jquery.highlight-3.js | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.highlight-3.js b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.highlight-3.js index 8eabca4bfd..578da60639 100644 --- a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.highlight-3.js +++ b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.highlight-3.js @@ -1,6 +1,6 @@ /* -highlight v3 +highlight v5 Highlights arbitrary terms. @@ -19,6 +19,7 @@ jQuery.fn.highlight = function(pat) { var skip = 0; if (node.nodeType == 3) { var pos = node.data.toUpperCase().indexOf(pat); + pos -= (node.data.substr(0, pos).toUpperCase().length - node.data.substr(0, pos).length); if (pos >= 0) { var spannode = document.createElement('span'); spannode.className = 'term'; @@ -37,9 +38,9 @@ jQuery.fn.highlight = function(pat) { } return skip; } - return this.each(function() { + return this.length && pat && pat.length ? this.each(function() { innerHighlight(this, pat.toUpperCase()); - }); + }) : this; }; jQuery.fn.removeHighlight = function() { diff --git a/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.highlight-3.js b/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.highlight-3.js index 8eabca4bfd..578da60639 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.highlight-3.js +++ b/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.highlight-3.js @@ -1,6 +1,6 @@ /* -highlight v3 +highlight v5 Highlights arbitrary terms. @@ -19,6 +19,7 @@ jQuery.fn.highlight = function(pat) { var skip = 0; if (node.nodeType == 3) { var pos = node.data.toUpperCase().indexOf(pat); + pos -= (node.data.substr(0, pos).toUpperCase().length - node.data.substr(0, pos).length); if (pos >= 0) { var spannode = document.createElement('span'); spannode.className = 'term'; @@ -37,9 +38,9 @@ jQuery.fn.highlight = function(pat) { } return skip; } - return this.each(function() { + return this.length && pat && pat.length ? this.each(function() { innerHighlight(this, pat.toUpperCase()); - }); + }) : this; }; jQuery.fn.removeHighlight = function() { -- 2.20.1