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