]> mj.ucw.cz Git - gallery.git/blob - gal2/UCW/Gallery/Web/HighSlide.pm
Gallery2: Caveat gone
[gallery.git] / gal2 / 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 my $theme_name = "plain";
15 my $navw = 48;
16 my $navh = 48;
17 my $box_w = 130;
18 my $box_h = 110;
19 my $thumb_w = 114;
20 my $thumb_h = 94;
21
22 sub theme_dir($) {
23         my ($self) = @_;
24         return $self->get('ThemeUrlPrefix') . $theme_name;
25 }
26
27 sub theme_head_extras($) {
28         my ($self) = @_;
29         my $tdir = $self->theme_dir;
30         my $hsdir = $self->get('ThemeUrlPrefix') . "highslide";
31         return <<AMEN ;
32 <link rel=stylesheet href='$tdir/style.css' type='text/css' media=all>
33 <script type="text/javascript" src="$hsdir/highslide-with-gallery.js"></script>
34 <script type="text/javascript" src="$hsdir/highslide.config.js" charset="utf-8"></script>
35 <script type="text/javascript">
36 hs.graphicsDir = '$hsdir/graphics/';
37 </script>
38 <link rel="stylesheet" type="text/css" href="$hsdir/highslide.css">
39 <!--[if lt IE 7]>
40 <link rel="stylesheet" type="text/css" href="$hsdir/highslide-ie6.css">
41 <![endif]-->
42 AMEN
43 }
44
45 sub show_links($$$$) {
46         my ($self, $prev, $up, $next) = @_;
47         my $theme = $self->theme_dir;
48         print "<p class=parent>";
49         print "<span class=back style='width: ${navw}px; height: ${navh}px'>";
50         print "<a href='$prev'><img src='$theme/prev.png' width=${navw} height=${navh} alt='Back'></a>" if $prev ne "";
51         print "</span>\n";
52         printf "<span class=fwd style='width: ${navw}px; height: ${navh}px'>";
53         printf "<a href='$next'><img src='$theme/next.png' width=${navw} height=${navh} alt='Forward'></a>" if $next ne "";
54         print "</span>\n";
55         printf "<a href='$up'><img src='$theme/back.png' width=${navw} height=${navh} alt='Up'></a>" if $up ne "";
56 }
57
58 sub show_pre_thumbs($) {
59         my ($self) = @_;
60         print "\n<div class='highslide-gallery'><ul>\n";
61         $self->{hs_thumb_counter} = 0;
62 }
63
64 sub show_post_thumbs($) {
65         my ($self) = @_;
66         print "</ul></div>\n\n";
67 }
68
69 sub show_thumb($) {
70         my ($self, $meta, $photo_id, $click_url) = @_;
71         my $theme = $self->theme_dir;
72         my $m = $meta->{photo}->{$photo_id};
73         my $annot = UCW::CGI::html_escape($m->{title});
74         my $tf = $self->{thumb_fmt};
75         my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
76         my $tw = $tm->{w};
77         my $th = $tm->{h};
78         my $thumb = $self->get('ThumbUrlPrefix') . "$tf/$photo_id.jpg";
79         # HighSlide requires title either for all images, or for none
80         my $tit = " title=\"$annot\"";
81         my $aid = $self->{hs_thumb_counter}++ ? "" : " id=thumb1";
82         my $photo_url = $self->get('PhotoUrlPrefix') . "$photo_id.jpg";
83         print "<li><a$aid href='$click_url' class=highslide onclick='return hs.expand(this, { src: \"$photo_url\" })'>";
84         print "<img src='$thumb' width=$tw height=$th alt='Photo'$tit></a>\n";
85 }
86
87 sub attach($$) {
88         my ($class, $gal) = @_;
89         my $self = $class->SUPER::attach($gal);
90         $self->{thumb_fmt} = $gal->require_thumbnails($thumb_w, $thumb_h);
91         return $self;
92 }
93
94 1;