[Koha-patches] [PATCH] Bug 3056 - replace span hacking for terms in C4::Search

Jesse pianohacker at gmail.com
Tue Jul 28 06:33:34 CEST 2009


2009/7/27 Joe Atzberger <joe.atzberger at liblime.com>

> Reimplemented using jquery, added OSS plugin to both interfaces.  This is
> another case where having a /common directory used by both OPAC and STAFF
> would increase runtime efficiency and cut development time.
>
> Removed unused variables.
>
> I changed the OPAC .term color to match the staff interface, rather than
> being a
> second shade of blue.  The highlight/unhighlight link is currently a bit
> bolder
> than its neighbors, but my styling choices are provisional.  I expect the
> final
> tweaking of CSS to come from another more capable designer, like Owen.
>
> Note this patch may rely on previously submitted "Search.pm minor cleanup"
> patch.
> ---
>  C4/Search.pm                                       |   55
> +-----------------
>  .../intranet-tmpl/prog/en/css/staff-global.css     |    5 +-
>  .../en/lib/jquery/plugins/jquery.highlight-3.js    |   53
> +++++++++++++++++
>  .../prog/en/modules/catalogue/results.tmpl         |   62
> +++++++++++++------
>  koha-tmpl/opac-tmpl/prog/en/css/opac.css           |   10 ++-
>  .../en/lib/jquery/plugins/jquery.highlight-3.js    |   53
> +++++++++++++++++
>  .../opac-tmpl/prog/en/modules/opac-opensearch.tmpl |    6 +-
>  .../prog/en/modules/opac-results-grouped.tmpl      |   26 ++++++++-
>  .../opac-tmpl/prog/en/modules/opac-results.tmpl    |   29 +++++++++-
>  9 files changed, 214 insertions(+), 85 deletions(-)
>  create mode 100644
> koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.highlight-3.js
>  create mode 100644
> koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.highlight-3.js
>
> diff --git a/C4/Search.pm b/C4/Search.pm
> index e838ee2..bae6aff 100644
> --- a/C4/Search.pm
> +++ b/C4/Search.pm
> @@ -175,7 +175,6 @@ for my $i (0..$hits) {
>     my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
>
>     #build the hash for the template.
> -    $resultsloop{highlight}       = ($i % 2)?(1):(0);
>     $resultsloop{title}           = $biblio->{'title'};
>     $resultsloop{subtitle}        = $biblio->{'subtitle'};
>     $resultsloop{biblionumber}    = $biblio->{'biblionumber'};
> @@ -1130,23 +1129,13 @@ Format results in a form suitable for passing to
> the template
>  sub searchResults {
>     my ( $searchdesc, $hits, $results_per_page, $offset, $scan,
> @marcresults ) = @_;
>     my $dbh = C4::Context->dbh;
> -    my $even = 1;
>     my @newresults;
>
> -    # add search-term highlighting via <span>s on the search terms
> -    my $span_terms_hashref;
> -    for my $span_term ( split( / /, $searchdesc ) ) {
> -        $span_term =~ s/(.*=|\)|\(|\+|\.|\*)//g;
> -        $span_terms_hashref->{$span_term}++;
> -    }
> -
>     #Build branchnames hash
>     #find branchname
>     #get branch information.....
>     my %branches;
> -    my $bsth =
> -      $dbh->prepare("SELECT branchcode,branchname FROM branches")
> -      ;    # FIXME : use C4::Koha::GetBranches
> +    my $bsth =$dbh->prepare("SELECT branchcode,branchname FROM branches");
> # FIXME : use C4::Branch::GetBranches
>     $bsth->execute();
>     while ( my $bdata = $bsth->fetchrow_hashref ) {
>         $branches{ $bdata->{'branchcode'} } = $bdata->{'branchname'};
> @@ -1248,48 +1237,6 @@
> s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
>             $oldbiblio->{summary} = $summary;
>         }
>
> -        # save an author with no <span> tag, for the <a
> href=search.pl?q=<!--tmpl_var name="author"-->> link
> -        $oldbiblio->{'author_nospan'} = $oldbiblio->{'author'};
> -        $oldbiblio->{'title_nospan'} = $oldbiblio->{'title'};
> -        $oldbiblio->{'subtitle_nospan'} = $oldbiblio->{'subtitle'};
> -        # Add search-term highlighting to the whole record where they
> match using <span>s
> -        if (C4::Context->preference("OpacHighlightedWords")){
> -            my $searchhighlightblob;
> -            for my $highlight_field ( $marcrecord->fields ) {
> -
> -    # FIXME: need to skip title, subtitle, author, etc., as they are
> handled below
> -                next if $highlight_field->tag() =~ /(^00)/;    # skip
> fixed fields
> -                for my $subfield ($highlight_field->subfields()) {
> -                    my $match;
> -                    next if $subfield->[0] eq '9';
> -                    my $field = $subfield->[1];
> -                    for my $term ( keys %$span_terms_hashref ) {
> -                        if ( ( $field =~ /$term/i ) && (( length($term) >
> 3 ) || ($field =~ / $term /i)) ) {
> -                            $field =~ s/$term/<span
> class=\"term\">$&<\/span>/gi;
> -                        $match++;
> -                        }
> -                    }
> -                    $searchhighlightblob .= $field . " ... " if $match;
> -                }
> -
> -            }
> -            $searchhighlightblob = ' ... '.$searchhighlightblob if
> $searchhighlightblob;
> -            $oldbiblio->{'searchhighlightblob'} = $searchhighlightblob;
> -        }
> -
> -        # Add search-term highlighting to the title, subtitle, etc. fields
> -        for my $term ( keys %$span_terms_hashref ) {
> -            my $old_term = $term;
> -            if ( length($term) > 3 ) {
> -                $term =~ s/(.*=|\)|\(|\+|\.|\?|\[|\]|\\|\*)//g;
> -                               foreach(qw(title subtitle author
> publishercode place pages notes size)) {
> -                       $oldbiblio->{$_} =~ s/$term/<span
> class=\"term\">$&<\/span>/gi;
> -                               }
> -            }
> -        }
> -
> -        ($i % 2) and $oldbiblio->{'toggle'} = 1;
> -
>         # Pull out the items fields
>         my @fields = $marcrecord->field($itemtag);
>
> diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css
> b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css
> index a2f122a..cc354ce 100644
> --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css
> +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css
> @@ -407,6 +407,9 @@ a.yuimenuitemlabel-disabled, #disabled a {
>  a.yuimenuitemlabel-disabled:hover, #disabled a:hover {
>        color : #999;
>  }
> +a.highlight_toggle {
> +    display : none;
> +}
>
>  ul.toolbar li {
>        display : inline;
> @@ -1205,9 +1208,7 @@ h1#logo {
>  }
>  h1#logo {
>        background:transparent url(../../img/koha-logo-medium.gif) no-repeat
> scroll 0%;
> -       border: 0;
>        margin:0.75em .3em 0.75em .7em;
> -       padding:0;
>  }
>
>  *html h1#logo {
> diff --git
> a/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.highlight-3.js
> b/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.highlight-3.js
> new file mode 100644
> index 0000000..69bb52d
> --- /dev/null
> +++
> b/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.highlight-3.js
> @@ -0,0 +1,53 @@
> +/*
> +
> +highlight v3
> +
> +Highlights arbitrary terms.
> +
> +<
> http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
> >
> +
> +MIT license.
> +
> +Johann Burkard
> +<http://johannburkard.de>
> +<mailto:jb at eaio.com>
> +
> +*/
> +
> +jQuery.fn.highlight = function(pat) {
> + function innerHighlight(node, pat) {
> +  var skip = 0;
> +  if (node.nodeType == 3) {
> +   var pos = node.data.toUpperCase().indexOf(pat);
> +   if (pos >= 0) {
> +    var spannode = document.createElement('span');
> +    spannode.className = 'term';
> +    var middlebit = node.splitText(pos);
> +    var endbit = middlebit.splitText(pat.length);
> +    var middleclone = middlebit.cloneNode(true);
> +    spannode.appendChild(middleclone);
> +    middlebit.parentNode.replaceChild(spannode, middlebit);
> +    skip = 1;
> +   }
> +  }
> +  else if (node.nodeType == 1 && node.childNodes &&
> !/(script|style)/i.test(node.tagName)) {
> +   for (var i = 0; i < node.childNodes.length; ++i) {
> +    i += innerHighlight(node.childNodes[i], pat);
> +   }
> +  }
> +  return skip;
> + }
> + return this.each(function() {
> +  innerHighlight(this, pat.toUpperCase());
> + });
> +};
> +
> +jQuery.fn.removeHighlight = function() {
> + return this.find("span.term").each(function() {
> +  this.parentNode.firstChild.nodeName;
> +  with (this.parentNode) {
> +   replaceChild(this.firstChild, this);
> +   normalize();
> +  }
> + }).end();
> +};
> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
> b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
> index def42f3..4acf2c1 100644
> --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
> +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
> @@ -1,6 +1,7 @@
>  <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
>  <title>Koha &rsaquo; Catalog &rsaquo; <!-- TMPL_IF NAME="searchdesc"
> -->Results of Search <!-- TMPL_IF NAME="query_desc" -->for '<!-- TMPL_VAR
> NAME="query_desc" -->'<!-- /TMPL_IF --><!-- TMPL_IF NAME="limit_desc"
> -->&nbsp;with limit(s):&nbsp;'<!-- TMPL_VAR NAME="limit_desc" -->'<!--
> /TMPL_IF --><!-- TMPL_ELSE -->You did not specify any search criteria<!--
> /TMPL_IF --></title>
>  <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
> +<script type="text/javascript"
> src="/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.highlight-3.js"></script>
>  <script type="text/javascript">
>  //<![CDATA[
>  var MSG_NO_ITEM_SELECTED = _("Nothing is selected.");
> @@ -9,7 +10,7 @@ var MSG_NON_RESERVES_SELECTED = _("One or more selected
> items cannot be reserved
>  // http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
>  function verify_images() {
>     $("img").each(function(i){
> -           if ((this.src.indexOf('images.amazon.com') >= 0) ||
> (this.src.indexOf('g-images.amazon.com') >=0)) {
> +        if ((this.src.indexOf('images.amazon.com') >= 0) ||
> (this.src.indexOf('g-images.amazon.com') >=0)) {
>             w = this.width;
>             h = this.height;
>             if ((w == 1) || (h == 1)) {
> @@ -17,11 +18,16 @@ function verify_images() {
>             } else if ((this.complete != null) && (!this.complete)) {
>                 this.src = '
> http://g-images.amazon.com/images/G/01/x-site/icons/no-img-sm.gif';
>             }
> -           }
> -        });
>         }
> +    });
> +}
> +$(window).load(function() {
> +    verify_images();
> +});
>  <!-- /TMPL_IF -->
>
> +var q_array = new Array();  // will hold search terms, if present
> +
>  $(document).ready(function() {
>     $('#sortbyform').find("input:submit").hide();
>     $('#sort_by').change(function() {
> @@ -29,17 +35,29 @@ $(document).ready(function() {
>     });
>        $("#z3950searchc").empty();
>        yuiZ3950button();
> -});
> -
> -<!-- TMPL_IF NAME="AmazonEnabled" -->
> -$(window).load(function() {
> -        verify_images();
> -     });
> -<!-- /TMPL_IF -->
> -$(document).ready(function() {
>     $("#selection_ops").show();
>     $(".selection").show();
> +    <!-- TMPL_IF NAME="query_desc" -->
> +        var query_desc = "<!-- TMPL_VAR NAME="query_desc" ESCAPE="JS"-->";
> +        q_array = query_desc.split(" ");
> +        highlightOn();
> +        $("#highlight_toggle_on" ).hide().click(function() {highlightOn()
> ;});
> +        $("#highlight_toggle_off").show().click(function()
> {highlightOff();});
> +    <!-- /TMPL_IF -->
>  });
> +
> +function highlightOff() {
> +    $("p").removeHighlight();
> +    $(".highlight_toggle").toggle();
> +}
> +function highlightOn() {
> +    var x;
> +    for (x in q_array) {
> +        $("p").highlight(q_array[x]);
> +    }
> +    $(".highlight_toggle").toggle();
> +}
> +
>  function selectAll () {
>     $(".selection").attr("checked", "checked");
>  }
> @@ -118,7 +136,11 @@ function yuiZ3950button() {
>  <!-- TMPL_INCLUDE NAME="header.inc" -->
>  <!-- TMPL_INCLUDE NAME="cat-search.inc" -->
>
> -<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>
> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>  &rsaquo;
> Search <!-- TMPL_IF NAME="query_desc" -->for '<!-- TMPL_VAR
> NAME="query_desc" ESCAPE="html"-->'<!-- /TMPL_IF --><!-- TMPL_IF
> NAME="limit_desc" -->&nbsp;with limit(s):&nbsp;'<!-- TMPL_VAR
> NAME="limit_desc" -->'<!-- /TMPL_IF --></div>
> +<div id="breadcrumbs">
> +         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
> +&rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>
> +&rsaquo; Search <!-- TMPL_IF NAME="query_desc" -->for '<!-- TMPL_VAR
> NAME="query_desc" ESCAPE="html"-->'<!-- /TMPL_IF --><!-- TMPL_IF
> NAME="limit_desc" -->&nbsp;with limit(s):&nbsp;'<!-- TMPL_VAR
> NAME="limit_desc" -->'<!-- /TMPL_IF -->
> +</div>
>
>  <div id="doc3" class="yui-t1">
>    <div id="bd">
> @@ -171,6 +193,9 @@ function yuiZ3950button() {
>                 <a href="#" onclick="selectAll(); return false;">Select
> All</a>
>                 |
>                 <a href="#" onclick="clearAll(); return false;">Clear
> All</a>
> +                |
> +                <a href="#" class="highlight_toggle"
> id="highlight_toggle_off">Unhighlight</a>
> +                <a href="#" class="highlight_toggle"
> id="highlight_toggle_on">Highlight</a>
>                 <!-- TMPL_IF NAME="CAN_user_reserveforothers" -->
>                   <input type="button" onclick="placeHold(); return false;"
> value="Place Hold"/>
>                 <!-- /TMPL_IF -->
> @@ -183,16 +208,13 @@ function yuiZ3950button() {
>                        <form method="post" name="fz3950"
> class="fz3950bigrpad">
>                                <span id="z3950searchc"><input type="button"
> id="z3950search" value="z39.50 Search" onclick="PopupZ3950(); return false;"
> /></span>
>                        </form>
> -        <!-- TMPL_IF NAME="searchdesc" -->
>             <h3>No results found</h3>
> +        <!-- TMPL_IF NAME="searchdesc" -->
>             <p>
>                 No results match your search <!-- TMPL_IF NAME="query_desc"
> -->for <span style="font-weight: bold;">'<!-- TMPL_VAR NAME="query_desc"
> ESCAPE="HTML"-->'</span><!-- /TMPL_IF --><!-- TMPL_IF NAME="limit_desc"
> -->&nbsp;with limit(s): <span style="font-weight: bold;">'<!-- TMPL_VAR
> NAME="limit_desc" -->'</span><!-- /TMPL_IF --><!-- TMPL_IF
> NAME="LibraryName" --> in <!-- TMPL_VAR NAME="LibraryName" --> Catalog<!--
> /TMPL_IF -->.
>             </p>
>         <!-- TMPL_ELSE -->
> -            <h3>No results found</h3>
> -            <p>
> -            You did not specify any search criteria.
> -            </p>
> +            <p>You did not specify any search criteria.</p>
>         <!-- /TMPL_IF -->
>                </div>
>     <!-- /TMPL_IF -->
> @@ -249,7 +271,7 @@ function yuiZ3950button() {
>                 <!-- TMPL_LOOP NAME="SEARCH_RESULTS" -->
>                     <!-- TMPL_IF NAME="__odd__" --><tr><!-- TMPL_ELSE
> --><tr class="highlight"><!-- /TMPL_IF -->
>                         <td>
> -                            <a
> href="/cgi-bin/koha/catalogue/search.pl?idx=<!-- TMPL_VAR
> name="scan_index_to_use" -->&amp;q=<!-- TMPL_VAR NAME="scan_use"
> escape="url" -->&quot;<!-- TMPL_VAR NAME="title_nospan" -->&quot;"><!--
> TMPL_VAR NAME="title" --></a>
> +                            <a
> href="/cgi-bin/koha/catalogue/search.pl?idx=<!-- TMPL_VAR
> name="scan_index_to_use" -->&amp;q=<!-- TMPL_VAR NAME="scan_use"
> escape="url" -->&quot;<!-- TMPL_VAR NAME="title" -->&quot;"><!-- TMPL_VAR
> NAME="title" --></a>
>                         </td>
>                         <td>
>                             <!-- TMPL_VAR NAME="author" -->
> @@ -346,7 +368,7 @@ function yuiZ3950button() {
>                                 </p>
>                                 <!-- TMPL_IF name="summary" -->
>                                         <!-- TMPL_IF NAME="author" -->
> -                                            <a
> href="/cgi-bin/koha/catalogue/search.pl?q=au:<!-- TMPL_VAR
> NAME="author_nospan" ESCAPE="URL" -->" title="Search for this Author"><!--
> TMPL_VAR NAME="author" --></a>
> +                                            <a
> href="/cgi-bin/koha/catalogue/search.pl?q=au:<!-- TMPL_VAR NAME="author"
> ESCAPE="URL" -->" title="Search for this Author"><!-- TMPL_VAR NAME="author"
> --></a>
>                                         <!-- TMPL_ELSE -->
>                                             &nbsp;
>                                         <!-- /TMPL_IF -->
> @@ -366,7 +388,7 @@ function yuiZ3950button() {
>                                     <!-- /TMPL_UNLESS -->
>
>                                         <!-- TMPL_IF NAME="author" -->
> -                                            <a
> href="/cgi-bin/koha/catalogue/search.pl?q=au:<!-- TMPL_VAR
> NAME="author_nospan" ESCAPE="URL" -->" title="Search for this Author"><!--
> TMPL_VAR NAME="author" --></a>
> +                                            <a
> href="/cgi-bin/koha/catalogue/search.pl?q=au:<!-- TMPL_VAR NAME="author"
> ESCAPE="URL" -->" title="Search for this Author"><!-- TMPL_VAR NAME="author"
> --></a>
>                                         <!-- TMPL_ELSE -->
>                                             &nbsp;
>                                         <!-- /TMPL_IF -->
> diff --git a/koha-tmpl/opac-tmpl/prog/en/css/opac.css
> b/koha-tmpl/opac-tmpl/prog/en/css/opac.css
> index 7c03aed..127f2af 100644
> --- a/koha-tmpl/opac-tmpl/prog/en/css/opac.css
> +++ b/koha-tmpl/opac-tmpl/prog/en/css/opac.css
> @@ -13,6 +13,10 @@
> a:hover,input.editshelf:hover,a.editshelf:hover,input.deleteshelf:hover {
>        color : #990033;
>  }
>
> +a.highlight_toggle {
> +    display : none;
> +}
> +
>  body {
>        background-color : white;
>        text-align : left;
> @@ -354,8 +358,6 @@ p.availability {
>
>  }
>
> -
> -
>  /* "problem" enhancement */
>  .problem {
>        color : white;
> @@ -364,7 +366,9 @@ p.availability {
>
>  /* style for search terms in catalogsearch */
>  .term {
> -       color : blue;
> +       /* color : blue; */
> +    color : #990000;
> +    background-color : #FFFFCC;
>  }
>
>  a .term {
> diff --git
> a/koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.highlight-3.js
> b/koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.highlight-3.js
> new file mode 100644
> index 0000000..69bb52d
> --- /dev/null
> +++ b/koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.highlight-3.js
> @@ -0,0 +1,53 @@
> +/*
> +
> +highlight v3
> +
> +Highlights arbitrary terms.
> +
> +<
> http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
> >
> +
> +MIT license.
> +
> +Johann Burkard
> +<http://johannburkard.de>
> +<mailto:jb at eaio.com>
> +
> +*/
> +
> +jQuery.fn.highlight = function(pat) {
> + function innerHighlight(node, pat) {
> +  var skip = 0;
> +  if (node.nodeType == 3) {
> +   var pos = node.data.toUpperCase().indexOf(pat);
> +   if (pos >= 0) {
> +    var spannode = document.createElement('span');
> +    spannode.className = 'term';
> +    var middlebit = node.splitText(pos);
> +    var endbit = middlebit.splitText(pat.length);
> +    var middleclone = middlebit.cloneNode(true);
> +    spannode.appendChild(middleclone);
> +    middlebit.parentNode.replaceChild(spannode, middlebit);
> +    skip = 1;
> +   }
> +  }
> +  else if (node.nodeType == 1 && node.childNodes &&
> !/(script|style)/i.test(node.tagName)) {
> +   for (var i = 0; i < node.childNodes.length; ++i) {
> +    i += innerHighlight(node.childNodes[i], pat);
> +   }
> +  }
> +  return skip;
> + }
> + return this.each(function() {
> +  innerHighlight(this, pat.toUpperCase());
> + });
> +};
> +
> +jQuery.fn.removeHighlight = function() {
> + return this.find("span.term").each(function() {
> +  this.parentNode.firstChild.nodeName;
> +  with (this.parentNode) {
> +   replaceChild(this.firstChild, this);
> +   normalize();
> +  }
> + }).end();
> +};
> diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-opensearch.tmpl
> b/koha-tmpl/opac-tmpl/prog/en/modules/opac-opensearch.tmpl
> index 773f208..edefbc9 100644
> --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-opensearch.tmpl
> +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-opensearch.tmpl
> @@ -31,14 +31,14 @@
>      <opensearch:Query role="request" searchTerms="<!-- TMPL_VAR
> NAME="query_desc" ESCAPE="html" --> <!-- TMPL_VAR NAME="limit_desc"
> ESCAPE="html" -->" startPage="<!-- TMPL_VAR NAME="page" -->" />
>         <!-- TMPL_LOOP NAME="SEARCH_RESULTS" -->
>      <item>
> -       <title><!-- TMPL_VAR NAME="title_nospan" ESCAPE="html" --> <!--
> TMPL_VAR NAME="subtitle_nospan"  ESCAPE="html" --></title>
> +       <title><!-- TMPL_VAR NAME="title" ESCAPE="html" --> <!-- TMPL_VAR
> NAME="subtitle"  ESCAPE="html" --></title>
>        <isbn><!-- TMPL_VAR NAME="isbn" ESCAPE="html" --></isbn>
>        <link><!-- TMPL_IF name="BiblioDefaultViewmarc" --><!-- TMPL_VAR
> NAME="OPACBaseURL" -->/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=<!--
> TMPL_VAR NAME="biblionumber" --><!-- TMPL_ELSE --><!-- TMPL_IF
> name="BiblioDefaultViewisbd" --><!-- TMPL_VAR NAME="OPACBaseURL"
> -->/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=<!-- TMPL_VAR
> NAME="biblionumber" --><!-- TMPL_ELSE --><!-- TMPL_VAR NAME="OPACBaseURL"
> -->/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR
> NAME="biblionumber" --><!-- /TMPL_IF --><!-- /TMPL_IF --></link>
>        <description><![CDATA[
>  <!-- TMPL_IF NAME="OPACAmazonEnabled" --><!-- TMPL_IF
> NAME="OPACAmazonCoverImages" --><!-- TMPL_IF NAME="normalized_isbn" --><img
> src="http://images.amazon.com/images/P/<!-- TMPL_VAR
> NAME="normalized_isbn" -->.01.TZZZZZZZ.jpg" alt="" /><!-- /TMPL_IF --><!--
> /TMPL_IF --><!-- /TMPL_IF -->
>  <!-- TMPL_IF NAME="SyndeticsEnabled" --><!-- TMPL_IF
> NAME="SyndeticsCoverImages" --><!-- TMPL_IF NAME="content_identifier_exists"
> --><img src="http://www.syndetics.com/index.aspx?isbn=<!-- TMPL_VAR
> NAME="normalized_isbn" -->/SC.GIF&amp;client=<!-- TMPL_VAR
> NAME="SyndeticsClientCode" -->&amp;type=xw10<!-- TMPL_IF
> NAME="normalized_upc" -->&amp;upc=<!-- TMPL_VAR NAME="normalized_upc"
> --><!-- /TMPL_IF --><!-- TMPL_IF NAME="normalized_oclc" -->&amp;oclc=<!--
> TMPL_VAR NAME="normalized_oclc" --><!-- /TMPL_IF -->" alt="" /><!-- /TMPL_IF
> --><!-- /TMPL_IF --><!-- /TMPL_IF -->
>  <!-- TMPL_IF NAME="BakerTaylorEnabled" --><!-- TMPL_IF
> NAME="normalized_isbn" --><a href="https://<!-- TMPL_VAR
> name="BakerTaylorBookstoreURL" ESCAPE="HTML" --><!-- TMPL_VAR
> name="normalized_isbn" -->"><img alt="See Baker &amp; Taylor" src="<!--
> TMPL_VAR name="BakerTaylorImageURL" ESCAPE="HTML" --><!-- TMPL_VAR
> name="normalized_isbn" -->" /></a><!-- /TMPL_IF --><!-- /TMPL_IF -->
> -          <p><!-- TMPL_IF NAME="author" -->By <!-- TMPL_VAR
> NAME="author_nospan"  ESCAPE="html" -->. <!-- /TMPL_IF -->
> +          <p><!-- TMPL_IF NAME="author" -->By <!-- TMPL_VAR NAME="author"
>  ESCAPE="html" -->. <!-- /TMPL_IF -->
>           <!-- TMPL_IF name="place" --><!-- TMPL_VAR name="place"
>  ESCAPE="html" --> <!-- /TMPL_IF --><!-- TMPL_IF name="publishercode"
> --><!-- TMPL_VAR name="publishercode"  ESCAPE="html" --><!-- /TMPL_IF
> --><!-- TMPL_IF name="publicationyear" --> <!-- TMPL_VAR
> name="publicationyear"  ESCAPE="html" -->
>                     <!-- TMPL_ELSE --><!-- TMPL_IF name="copyrightdate" -->
> <!-- TMPL_VAR name="copyrightdate"  ESCAPE="html" --><!-- /TMPL_IF --><!--
> /TMPL_IF -->
>                         <!-- TMPL_IF name="pages" -->. <!-- TMPL_VAR
> name="pages"  ESCAPE="html" --><!-- /TMPL_IF -->
> @@ -46,7 +46,7 @@
>                         <!-- TMPL_IF name="size" --> <!-- TMPL_VAR
> name="size"  ESCAPE="html" -->. <!-- /TMPL_IF -->
>                         <!-- TMPL_IF name="isbn" --> <!-- TMPL_VAR
> name="isbn"  ESCAPE="html" --><!-- /TMPL_IF --> </p><p>
>  <!-- TMPL_IF NAME="RequestOnOpac" -->
> -<a href="<!-- TMPL_VAR NAME="OPACBaseURL"
> -->/cgi-bin/koha/opac-reserve.pl?biblionumber=<!-- TMPL_VAR
> NAME="biblionumber" -->">Place Hold on <i><!-- TMPL_VAR NAME="title_nospan"
> --></i></a></p>
> +<a href="<!-- TMPL_VAR NAME="OPACBaseURL"
> -->/cgi-bin/koha/opac-reserve.pl?biblionumber=<!-- TMPL_VAR
> NAME="biblionumber" -->">Place Hold on <i><!-- TMPL_VAR NAME="title"
> --></i></a></p>
>  <!-- /TMPL_IF -->
>                                                ]]></description>
>        <guid><!-- TMPL_VAR NAME="OPACBaseURL"
> -->/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR
> NAME="biblionumber" --></guid>
> diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tmpl
> b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tmpl
> index 2113eef..5e63206 100644
> --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tmpl
> +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tmpl
> @@ -11,6 +11,9 @@ href="/cgi-bin/koha/opac-rss.pl?<!-- TMPL_VAR
> name="query_cgi"--><!-- TMPL_VAR N
>  <script type="text/javascript" src="<!-- TMPL_VAR name="themelang"
> -->/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
>  <script type="text/javascript">
>  //<![CDATA[
> +
> +var q_array = new Array();  // will hold the search terms, if possible
> +
>  $(document).ready(function(){
>        $('#sortsubmit').hide();
>     $('#sort_by').change(function() {
> @@ -52,7 +55,26 @@ $(document).ready(function(){
>         $("#bookbag_form").unCheckCheckboxes();
>         return false;
>     });
> +    <!-- TMPL_IF NAME="query_desc" -->
> +    var query_desc = "<!-- TMPL_VAR NAME="query_desc" ESCAPE="JS"-->";
> +    q_array = query_desc.split(" ");
> +    highlightOn();
> +    $("#highlight_toggle_on" ).hide().click(function() {highlightOn() ;});
> +    $("#highlight_toggle_off").show().click(function() {highlightOff();});
> +    <!-- /TMPL_IF -->
>  });
> +
> +function highlightOff() {
> +    $("td").removeHighlight();
> +    $(".highlight_toggle").toggle();
> +}
> +function highlightOn() {
> +    var x;
> +    for (x in q_array) {
> +        $("td").highlight(q_array[x]);
> +    }
> +    $(".highlight_toggle").toggle();
> +}
>  //]]>
>  </script>
>  </head>
> @@ -159,6 +181,8 @@ $(document).ready(function(){
>                <div class="resort"> <select id="sort_by" name="sort_by">
> <!--TMPL_INCLUDE Name="resort_form.inc"--> </select> <input type="submit"
> class="submit clearfix" id="sortsubmit" value="Go" /></div>
>         <!-- TMPL_IF EXPR="opacbookbag || virtualshelves" --><div
> class="cartlist"><span class="checkall"></span>
>                <span class="clearall"></span>
> +        <a href="#" class="highlight_toggle"
> id="highlight_toggle_off">Unhighlight</a>
> +        <a href="#" class="highlight_toggle"
> id="highlight_toggle_on">Highlight</a>
>                <span class="addto"></span></div>
>                <!-- /TMPL_IF -->
>
> @@ -188,7 +212,7 @@ $(document).ready(function(){
>                       <!-- TMPL_IF name="BiblioDefaultViewisbd" --><a
> class="title" href="/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=<!--
> TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->" title="View details for this
> title"><!-- TMPL_VAR NAME="title" --> <!-- TMPL_VAR NAME="subtitle" --></a>
>                       <!-- TMPL_ELSE --><a class="title"
> href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR
> NAME="biblionumber" ESCAPE="URL" -->" title="View details for this
> title"><!-- TMPL_VAR NAME="title" --> <!-- TMPL_VAR NAME="subtitle" --></a>
>                       <!-- /TMPL_IF --><!-- /TMPL_IF -->
> -                      <!-- TMPL_IF NAME="author" -->by <a
> href="/cgi-bin/koha/opac-search.pl?q=au:<!-- TMPL_VAR NAME="author_nospan"
> ESCAPE="URL" -->" title="Search for works by this author"><!-- TMPL_VAR
> NAME="author" --></a>
> +                      <!-- TMPL_IF NAME="author" -->by <a
> href="/cgi-bin/koha/opac-search.pl?q=au:<!-- TMPL_VAR NAME="author"
> ESCAPE="URL" -->" title="Search for works by this author"><!-- TMPL_VAR
> NAME="author" --></a>
>                       <!-- TMPL_ELSE -->&nbsp;<!-- /TMPL_IF -->
>                                <p> <!-- TMPL_IF name="publicationyear" -->
> - <!-- TMPL_VAR name="publicationyear" --><!-- /TMPL_IF -->
>                                                <!-- TMPL_IF
> name="publishercode" -->- <!-- TMPL_VAR name="publishercode" --><!--
> /TMPL_IF -->
> diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
> b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
> index f2d7e10..005d0ce 100644
> --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
> +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
> @@ -10,6 +10,7 @@
>
>
>  <script type="text/javascript" src="<!-- TMPL_VAR name="themelang"
> -->/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
> +<script type="text/javascript" src="<!-- TMPL_VAR name="themelang"
> -->/lib/jquery/plugins/jquery.highlight-3.js"></script>
>  <script type="text/javascript">
>  //<![CDATA[
>
> @@ -78,6 +79,20 @@ function tagAdded() {
>     return false;
>  }
>
> +var q_array = new Array();  // holds search terms if available
> +
> +function highlightOff() {
> +    $("td").removeHighlight();
> +    $(".highlight_toggle").toggle();
> +}
> +function highlightOn() {
> +    var x;
> +    for (x in q_array) {
> +        $("td").highlight(q_array[x]);
> +    }
> +    $(".highlight_toggle").toggle();
> +}
> +
>  $(document).ready(function(){
>        $(".addtocart").show();
>        var param1 = "<label for=\"addto\">"+_("Add to: ")+"<\/label><select
> name=\"addto\" id=\"addto\"><option value=\"\"><\/option>";
> @@ -145,6 +160,14 @@ $(document).ready(function(){
>  <!-- /TMPL_IF -->
>     $("#holdDetails").hide();
>
> +    <!-- TMPL_IF NAME="query_desc" -->
> +        var query_desc = "<!-- TMPL_VAR NAME="query_desc" ESCAPE="JS"-->";
> +        q_array = query_desc.split(" ");
> +        highlightOn();
> +        $("#highlight_toggle_on" ).hide().click(function() {highlightOn()
> ;});
> +        $("#highlight_toggle_off").show().click(function()
> {highlightOff();});
> +    <!-- /TMPL_IF -->
> +
>        <!-- TMPL_IF NAME="TagsEnabled" -->
>         $(".tagbutton").click(KOHA.Tags.add_tag_button);
>            <!-- TMPL_IF NAME="TagsInputOnList" -->
> @@ -250,7 +273,7 @@ $(document).ready(function(){
>                        <tr>
>                        <!-- /TMPL_IF -->
>                 <td>
> -                    <a href="/cgi-bin/koha/opac-search.pl?q=<!-- TMPL_VAR
> NAME="scan_use" escape="url" -->&quot;<!-- TMPL_VAR NAME="title_nospan"
>  ESCAPE="URL" -->&quot;"><!-- TMPL_IF NAME="title" --><!-- TMPL_VAR
> NAME="title" --><!-- TMPL_ELSE -->No title<!-- /TMPL_IF --></a>
> +                    <a href="/cgi-bin/koha/opac-search.pl?q=<!-- TMPL_VAR
> NAME="scan_use" escape="url" -->&quot;<!-- TMPL_VAR NAME="title"
>  ESCAPE="URL" -->&quot;"><!-- TMPL_IF NAME="title" --><!-- TMPL_VAR
> NAME="title" --><!-- TMPL_ELSE -->No title<!-- /TMPL_IF --></a>
>                 </td>
>                 <td>
>                     <!-- TMPL_VAR NAME="author" -->
> @@ -280,6 +303,8 @@ $(document).ready(function(){
>             <!-- checkall, clearall are now needed for placehold -->
>             <span class="checkall"></span>
>                <span class="clearall"></span>
> +            <a href="#" class="highlight_toggle"
> id="highlight_toggle_off">Unhighlight</a>
> +            <a href="#" class="highlight_toggle"
> id="highlight_toggle_on">Highlight</a>
>             <!-- TMPL_IF EXPR="opacbookbag || virtualshelves" -->
>                <span class="addto"></span>
>             <!-- /TMPL_IF -->
> @@ -346,7 +371,7 @@ $(document).ready(function(){
>                                 <!-- TMPL_ELSE --><a class="title"
> href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR
> NAME="biblionumber" ESCAPE="URL" -->" title="View details for this
> title"><!-- TMPL_IF NAME="title" --><!-- TMPL_VAR NAME="title" --><!--
> TMPL_ELSE -->No title<!-- /TMPL_IF --> <!-- TMPL_VAR NAME="subtitle"
>  --></a>
>                                 <!-- /TMPL_IF -->
>                                 <!-- /TMPL_IF -->
> -                                <!-- TMPL_IF NAME="author" -->by <a
> href="/cgi-bin/koha/opac-search.pl?q=au:<!-- TMPL_VAR NAME="author_nospan"
> ESCAPE="URL" -->" title="Search for works by this author"><!-- TMPL_VAR
> NAME="author" --></a>
> +                                <!-- TMPL_IF NAME="author" -->by <a
> href="/cgi-bin/koha/opac-search.pl?q=au:<!-- TMPL_VAR NAME="author"
> ESCAPE="URL" -->" title="Search for works by this author"><!-- TMPL_VAR
> NAME="author" --></a>
>                                 <!-- TMPL_ELSE -->&nbsp;
>                                 <!-- /TMPL_IF -->
>                                <span class="results_summary"><span
> class="label">Publication:</span>
> --
> 1.5.6.5
>
> _______________________________________________
> Koha-patches mailing list
> Koha-patches at lists.koha.org
> http://lists.koha.org/mailman/listinfo/koha-patches
>

Excellent idea. The search function of my sysprefs project, which used that
same span-hacking method, was running into problems with HTML tags. This is
just the ticket; I'll use the same jQuery plugin.

Thanks,
-- 
Jesse Weaver
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/koha-patches/attachments/20090727/f4293873/attachment-0002.htm>


More information about the Koha-patches mailing list