Bug 8525: highlight matches on OPAC detail page
authorJared Camins-Esakov <jcamins@cpbibliography.com>
Mon, 30 Jul 2012 21:16:07 +0000 (17:16 -0400)
committerPaul Poulain <paul.poulain@biblibre.com>
Mon, 3 Sep 2012 07:58:28 +0000 (09:58 +0200)
After doing a search and going to the details page, it can sometimes
be difficult to see exactly *why* a record was returned by a search.
By highlighting matches on the detail page as well as the results
page, we make it much easier to figure that out.

This patch uses a query_desc CGI parameter which is inserted into links
from the results page with javascript. This serves to avoid the
potential privacy implications of a cookie, and ensures that users
without javascript enabled see no change whatsoever.

To test:
1) Do a search (or two) in the OPAC with OpacHighlightedWords on.
2) View a record or two of the results, and ensure that the correct
   words are highlighted.
3) Disable OpacHighlightedWords and do another search (or two),
   this time ensuring that no words are highlighted.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
koha-tmpl/opac-tmpl/prog/en/css/opac.css
koha-tmpl/opac-tmpl/prog/en/includes/opac-detail-sidebar.inc
koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tt
koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt
opac/opac-detail.pl

index 68dc01b..021238d 100644 (file)
@@ -434,6 +434,13 @@ a .term {
   background-repeat: no-repeat;
 }
 
+#action a.highlight_toggle {
+    background-image: url("../../images/sprite.png"); /* place hold icon */
+    background-position: -5px -841px;
+    background-repeat: no-repeat;
+    display: none;
+}
+
 #action a#furthersearches {
     background-image: url("../../images/sprite.png");
     background-position: 106px -295px;
index 85d44d7..0f16f3a 100644 (file)
             <li><a class="addtocart cart[% biblionumber %]" href="#" onclick="addRecord('[% biblionumber %]'); return false;">Add to your cart</a>  <a style="display:none;" class="cartRemove cartR[% biblionumber %]" href="#" onclick="delSingleRecord('[% biblionumber %]'); return false;">(remove)</a></li>
         [% END %]
     [% END %]
+    [% IF ( OpacHighlightedWords && query_desc ) %]
+    <li>
+        <a href="#" class="highlight_toggle" id="highlight_toggle_off">Unhighlight</a>
+        <a href="#" class="highlight_toggle" id="highlight_toggle_on">Highlight</a>
+    </li>
+    [% END %]
     <li style="display:none;"><a href="#" id="furthersearches">More searches</a></li>
 </ul>
 
index 6c4ecdc..fa81977 100644 (file)
@@ -12,6 +12,7 @@
 [% IF ( OpacStarRatings != 'disable' ) %]<script type="text/javascript" src="/opac-tmpl/prog/en/lib/jquery/plugins/jquery.rating.js"></script>
 <link rel="stylesheet" type="text/css" href="/opac-tmpl/prog/en/css/jquery.rating.css" />[% END %]
 
+[% IF ( OpacHighlightedWords ) %]<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.highlight-3.js"></script>[% END %]
 <script type="text/JavaScript" language="JavaScript">
 //<![CDATA[
 
         [% END %]
     [% END %]
 
+    [% IF ( OpacHighlightedWords ) %]
+        var q_array = new Array();  // holds search terms if available
+
+        function highlightOff() {
+            $("#catalogue_detail_biblio").removeHighlight();
+            $(".highlight_toggle").toggle();
+        }
+        function highlightOn() {
+            var x;
+            for (x in q_array) {
+                $(".title").highlight(q_array[x]);
+                $(".author").highlight(q_array[x]);
+                $(".results_summary").highlight(q_array[x]);
+            }
+            $(".highlight_toggle").toggle();
+        }
+    [% END %]
 
      $(document).ready(function() { 
         $('#bibliodescriptions').tabs();
             widgets : ['zebra'],
             sortList: [[0,0]]
         });
+        [% IF ( query_desc ) %][% IF ( OpacHighlightedWords ) %]var query_desc = "[% query_desc |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
+            q_array = query_desc.split(" ");
+            highlightOn();
+            $("#highlight_toggle_on" ).hide().click(function() {highlightOn() ;});
+            $("#highlight_toggle_off").show().click(function() {highlightOff();});[% END %][% END %]
        [% IF ( GoogleJackets ) %]
         KOHA.Google.GetCoverFromIsbn([% covernewwindow %]);
        [% END %]
index ef2ca72..86e1a08 100644 (file)
@@ -15,6 +15,12 @@ href="/cgi-bin/koha/opac-rss.pl?[% query_cgi %][% limit_cgi |html %]" />
 var q_array = new Array();  // will hold the search terms, if possible
 
 $(document).ready(function(){
+    [% IF ( OpacHighlightedWords ) %]
+        $('a.title').each(function() {
+            $(this).attr('href', $(this).attr('href') + '&query_desc=[% query_desc | url %]');
+        });
+    [% END %]
+
        $('#sortsubmit').hide();
     $('#sort_by').change(function() {
         $('#bookbag_form').submit();
index 3f8e6d3..6191342 100644 (file)
@@ -97,6 +97,12 @@ function highlightOn() {
 }
 [% END %]
 $(document).ready(function(){
+    [% IF ( OpacHighlightedWords ) %]
+        $('a.title').each(function() {
+            $(this).attr('href', $(this).attr('href') + '&query_desc=[% query_desc | url %]');
+        });
+    [% END %]
+
     [% IF ( opacbookbag ) %]$(".addtocart").show();[% END %]
 
 [% IF ( opacbookbag ) %]
index 8b3e21d..feaa89b 100755 (executable)
@@ -961,4 +961,8 @@ if (C4::Context->preference('OPACLocalCoverImages') == 1) {
     $template->{VARS}->{localimages} = \@images;
 }
 
+if (C4::Context->preference('OpacHighlightedWords')) {
+    $template->{VARS}->{query_desc} = $query->param('query_desc');
+}
+
 output_html_with_http_headers $query, $cookie, $template->output;