[Koha-patches] [PATCH] Tag cloud implementation in jquery.
Joe Atzberger
joe.atzberger at liblime.com
Wed Jul 30 03:23:33 CEST 2008
Initial implementation of "cloud" display on opac-tags.
---
koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tmpl | 51 ++++++++++++++++++--
opac/opac-tags.pl | 13 +++--
2 files changed, 53 insertions(+), 11 deletions(-)
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tmpl
index 1393600..2e02d5d 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tmpl
@@ -1,5 +1,43 @@
-<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><!-- TMPL_IF NAME="LibraryNameTitle" --><!-- TMPL_VAR NAME="LibraryNameTitle" --><!-- TMPL_ELSE -->Koha Online<!-- /TMPL_IF --> Catalog › Tags
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><!-- TMPL_VAR NAME="LibraryNameTitle" DEFAULT="Koha Online" --> Catalog › Tags
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<style type="text/css">
+ #tagcloud {background-color: #F3F3F3; text-align: justify;}
+ .tag a {text-decoration: none;}
+ .tag a:hover {text-decoration: underline;}
+ .tag {display: block; padding-left: 1em;}
+ .tagcount {display: none;}
+ .cloudweight {display: none;}
+ .tagweight {
+ display: none;
+ position: relative;
+ bottom: 0.4em;
+ color: red;
+ font-size: 12px;
+ }
+</style>
+<script type="text/javascript">
+ var fontsizes = new Array (12,14,16,18,20,22,24,26,28,30);
+ var fontcount = fontsizes.length;
+ var maxcloudweight = 1;
+ $(document).ready(function() {
+ // $('#tagcloud').css('background-color','lightgrey');
+ // $('#tagcloud .tag').css('border','1px solid black');
+ $('#tagcloud .tag').each(function() {
+ if (maxcloudweight < this.title) { maxcloudweight = this.title; }
+ // have to run through the set of tags once to get the max: cannot be combined w/ 2nd pass
+ });
+ $('#tagcloud .tag').each(function(i) {
+ var pos = this.id;
+ var weight = this.title; // "cloudweight"
+ weight = (! weight) ? 1 : (weight > maxcloudweight) ? maxcloudweight : weight ;
+ var index = Math.round(fontcount * weight/maxcloudweight) - 1;
+ index = (! index ) ? 0 : ( index > fontcount ) ? fontcount : index ;
+ var newsize = fontsizes[index];
+ // alert(pos+ " (" +i+ ") weight = " +weight+ " of " +maxcloudweight+ ", fontsize[" +index+ " of " +fontcount+ "] = " +newsize);
+ $('#' + pos).css({"font-size":(newsize + 'pt'), display:"inline"});
+ });
+ });
+</script>
</head>
<body>
<div id="doc3" class="yui-t1">
@@ -71,12 +109,15 @@
</p>
</form>
</div>
- <!-- TMPL_IF NAME="TAGLOOP" --> <!-- TMPL_VAR NAME="TAGLOOP_COUNT" --> Results:<ul>
+ <!-- TMPL_IF NAME="TAGLOOP" --> <!-- TMPL_VAR NAME="TAGLOOP_COUNT" --> Results:<div id="tagcloud">
<!-- TMPL_LOOP NAME="TAGLOOP" -->
- <li><a href="/cgi-bin/koha/opac-search.pl?tag=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->&q=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->">
- <!-- TMPL_VAR NAME="term" ESCAPE="HTML" --></a> (<!-- TMPL_VAR NAME="weight_total" -->) <!-- (<!-- TMPL_VAR NAME="cloudweight" -->) --> </li>
+ <span class="tag" id="tag<!-- TMPL_VAR NAME="__counter__" -->" title="<!-- TMPL_VAR NAME="cloudweight" -->">
+ <a href="/cgi-bin/koha/opac-search.pl?tag=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->&q=<!-- TMPL_VAR NAME="term" ESCAPE="URL" -->">
+ <!-- TMPL_VAR NAME="term" ESCAPE="HTML" --></a>
+ <span class="tagweight"><!-- TMPL_VAR NAME="weight_total" --></span>
+ </span>
<!-- /TMPL_LOOP -->
- </ul>
+ </div>
<!-- /TMPL_IF -->
</div>
</div>
diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl
index 884fb74..2bd9354 100755
--- a/opac/opac-tags.pl
+++ b/opac/opac-tags.pl
@@ -132,13 +132,13 @@ if (scalar @newtags_keys) {
}
}
my $result = ($openadds) ?
- add_tag($biblionumber,$clean_tag,$loggedinuser,0) : # pre-approved
+ add_tag($biblionumber,$clean_tag,$loggedinuser,$loggedinuser) : # pre-approved
add_tag($biblionumber,$clean_tag,$loggedinuser) ;
if ($result) {
$counts{$biblionumber}++;
} else {
push @errors, {failed_add_tag=>$clean_tag};
- warn "add_tag($biblionumber,$clean_tag,$loggedinuser...) returned bad result ($result)";
+ warn "add_tag($biblionumber,$clean_tag,$loggedinuser...) returned bad result (" . (defined $result ? $result : 'UNDEF') .")";
}
}
}
@@ -199,13 +199,14 @@ if ($add_op) {
$limit = $query->param('limit') || $hardmax;
($limit =~ /^\d+$/ and $limit <= $hardmax) or $limit = $hardmax;
$template->param(limit => $limit);
+ my $arghash = {approved=>1, limit=>$limit, 'sort'=>'-weight_total'};
+ # ($openadds) or $arghash->{approved} = 1;
if ($arg = $query->param('tag')) {
- $results = get_approval_rows({term => $arg, approved=>1, limit=>$limit, 'sort'=>'-weight_total'});
+ $arghash->{term} = $arg;
} elsif ($arg = $query->param('biblionumber')) {
- $results = get_approval_rows({biblionumber => $arg, approved=>1, limit=>$limit, 'sort'=>'-weight_total'});
- } else {
- $results = get_approval_rows({limit=>$limit, approved=>1, 'sort'=>'-weight_total'});
+ $arghash->{biblionumber} = $arg;
}
+ $results = get_approval_rows($arghash);
my $count = scalar @$results;
$template->param(TAGLOOP_COUNT => $count);
--
1.5.5.GIT
More information about the Koha-patches
mailing list