]> mj.ucw.cz Git - gallery.git/blob - gal/UCW/Gallery/Web/HighSlide.pm
a1cffec59f41be05894722bcb515f9bf3686eb32
[gallery.git] / gal / UCW / Gallery / Web / HighSlide.pm
1 # HighSlide JS Theme for MJ's Photo Gallery
2 # (c) 2012 Martin Mares <mj@ucw.cz>; GPL'ed
3
4 package UCW::Gallery::Web::HighSlide;
5
6 use strict;
7 use warnings;
8
9 use UCW::Gallery;
10 use UCW::Gallery::Web;
11
12 our @ISA = qw(UCW::Gallery::Web);
13
14 sub theme_head_extras($) {
15         my ($self) = @_;
16         my $hsdir = $self->get('ThemeUrlPrefix') . "highslide";
17         return <<AMEN ;
18 <script type="text/javascript" src="$hsdir/highslide-with-gallery.js"></script>
19 <script type="text/javascript" src="$hsdir/custom.js" charset="utf-8"></script>
20 <script type="text/javascript">
21 hs.graphicsDir = '$hsdir/graphics/';
22 </script>
23 <link rel="stylesheet" type="text/css" href="$hsdir/highslide.css">
24 <link rel="stylesheet" type="text/css" href="$hsdir/custom.css">
25 <!--[if lt IE 7]>
26 <link rel="stylesheet" type="text/css" href="$hsdir/highslide-ie6.css">
27 <![endif]-->
28 AMEN
29 }
30
31 sub show_links($$$$) {
32         my ($self, $prev, $up, $next) = @_;
33         my $nav = $self->get('ThemeUrlPrefix') . "highslide/nav";
34         print "<p class=parent>";
35         print "<a href='$prev'><img class=back prev src='$nav/prev.png'></a>" if $prev ne "";
36         printf "<a href='$next'><img class=fwd src='$nav/next.png'></a>" if $next ne "";
37         printf "<a href='$up'><img class=up src='$nav/back.png'></a>" if $up ne "";
38 }
39
40 sub show_pre_thumbs($) {
41         my ($self) = @_;
42         print "\n<div class='highslide-gallery'><ul>\n";
43         $self->{hs_thumb_counter} = 0;
44 }
45
46 sub show_post_thumbs($) {
47         my ($self) = @_;
48         print "</ul></div>\n\n";
49 }
50
51 sub show_thumb($) {
52         my ($self, $meta, $photo_id, $click_url) = @_;
53         my $m = $meta->{photo}->{$photo_id};
54         my $annot = UCW::CGI::html_escape($m->{title});
55         my $tf = $self->get('ThumbFormats')->[0];
56         my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
57         my $tw = $tm->{w};
58         my $th = $tm->{h};
59         my $thumb = $self->get('ThumbUrlPrefix') . "$tf/$photo_id.jpg";
60         # HighSlide requires title either for all images, or for none
61         my $tit = " title=\"$annot\"";
62         my $aid = $self->{hs_thumb_counter}++ ? "" : " id=thumb1";
63         my $photo_url = $self->get('PhotoUrlPrefix') . "$photo_id.jpg";
64         print "<li><a$aid href='$click_url' class=highslide onclick='return hs.expand(this, { src: \"$photo_url\" })'>";
65         print "<img src='$thumb' width=$tw height=$th alt='Photo'$tit></a>\n";
66 }
67
68 sub run($$) {
69         my ($class, $gal) = @_;
70         my $self = $class->SUPER::attach($gal);
71         $self->dispatch();
72         return $self;
73 }
74
75 1;