@@ -, +, @@ the titles given below (Title subfield = 200$a): Book 1: Συλλογής των εν επιτομή τοῖς πάλαι γεωγραφηθέντων Book 2: Επιτομή της ιστορίας των Βαλκανικών Πολέμων (1912-1913) should both be set to "Highlight". quotes). In the results page, notice that: a) You get an Uncaught DOMException error in the web browswer's JavaScript Console (press F12): "Failed to execute 'splitText' on 'Text': The offset 3 is larger than the Text node's length." b) the "Highlight" / "Unhighlight" button vanishes c) some search terms matches are not highlighted (for example "των" in the 2nd Book) In the results page, notice that: a) You get an Uncaught DOMException error in the web browswer's JavaScript Console (press F12): "Failed to execute 'splitText' on 'Text': The offset 3 is larger than the Text node's length." b) Even though some terms are highlighted, the button still says "Highlight" c) some search terms matches are not highlighted (for example "των" in the 2nd Book) to reload the JavaScript code). This time the "Highlight" / "Unhighlight" button is displayed in the OPAC, and all your search terms should be highlighted in yellow. Toggling the highlight should cause no problems, and there shouldn't be any errors logged in your browser's Console. --- .../{jquery.highlight-3.js => jquery.highlight-5.js} | 7 ++++--- koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc | 2 +- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt | 2 +- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt | 2 +- .../{jquery.highlight-3.js => jquery.highlight-5.js} | 7 ++++--- 5 files changed, 11 insertions(+), 9 deletions(-) rename koha-tmpl/intranet-tmpl/lib/jquery/plugins/{jquery.highlight-3.js => jquery.highlight-5.js} (86%) rename koha-tmpl/opac-tmpl/lib/jquery/plugins/{jquery.highlight-3.js => jquery.highlight-5.js} (86%) --- a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.highlight-3.js +++ a/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() { --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc @@ -21,7 +21,7 @@ [% Asset.js("lib/jquery/jquery-ui-1.13.1.min.js") | $raw %] [% Asset.js("lib/shortcut/shortcut.js") | $raw %] [% Asset.js("lib/js-cookie/js.cookie-2.2.1.min.js") | $raw %] -[% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %] +[% Asset.js("lib/jquery/plugins/jquery.highlight-5.js") | $raw %] [% Asset.js("lib/bootstrap/bootstrap.min.js") | $raw %] [% Asset.js("lib/jquery/plugins/jquery.validate.min.js") | $raw %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -1441,7 +1441,7 @@ [% CoverImagePlugins | $raw %] - [% IF ( OpacHighlightedWords ) %][% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %][% END %] + [% IF ( OpacHighlightedWords ) %][% Asset.js("lib/jquery/plugins/jquery.highlight-5.js") | $raw %][% END %] [% IF ( Koha.Preference('OPACDetailQRCode') ) %] [% Asset.js("lib/kjua/kjua.min.js") | $raw %] [% END %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt @@ -584,7 +584,7 @@ [% Asset.js("js/authtoresults.js") | $raw %] [% Asset.js("lib/hc-sticky.js") | $raw %] [% IF ( OpacHighlightedWords ) %] - [% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %] + [% Asset.js("lib/jquery/plugins/jquery.highlight-5.js") | $raw %] [% END %] [% IF OpenLibraryCovers || OpenLibrarySearch %] [% Asset.js("js/openlibrary.js") | $raw %] --- a/koha-tmpl/opac-tmpl/lib/jquery/plugins/jquery.highlight-3.js +++ a/koha-tmpl/opac-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() { --