]> mj.ucw.cz Git - gallery.git/blob - lib/UCW/Gallery/Web/HighSlide.pm
Merge branch 'master' of ssh://git.ucw.cz/home/mj/GIT/gallery
[gallery.git] / lib / 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 common::sense;
7 use utf8;
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 $self->showing_image ? <<AMEN_MINI : <<AMEN_FULL ;
18 <link rel="stylesheet" type="text/css" href="$hsdir/custom.css">
19 AMEN_MINI
20 <script type="text/javascript" src="$hsdir/highslide-with-gallery.js"></script>
21 <script type="text/javascript" src="$hsdir/custom.js" charset="utf-8"></script>
22 <script type="text/javascript">
23 hs.graphicsDir = '$hsdir/graphics/';
24 </script>
25 <link rel="stylesheet" type="text/css" href="$hsdir/highslide.css">
26 <link rel="stylesheet" type="text/css" href="$hsdir/custom.css">
27 <!--[if lt IE 7]>
28 <link rel="stylesheet" type="text/css" href="$hsdir/highslide-ie6.css">
29 <![endif]-->
30 AMEN_FULL
31 }
32
33 sub show_links($$$$) {
34         my ($self, $prev, $up, $next) = @_;
35         my $nav = $self->get('ThemeUrlPrefix') . "highslide/nav";
36         print "<p class=parent>";
37         print "<a href='$prev'><img class=back prev src='$nav/prev.png'></a>" if $prev ne "";
38         printf "<a href='$next'><img class=fwd src='$nav/next.png'></a>" if $next ne "";
39         printf "<a href='$up'><img class=up src='$nav/back.png'></a>" if $up ne "";
40 }
41
42 sub show_pre_thumbs($) {
43         my ($self) = @_;
44         print "\n<div class='highslide-gallery'><ul>\n";
45         $self->{hs_thumb_counter} = 0;
46 }
47
48 sub show_post_thumbs($) {
49         my ($self) = @_;
50         print "</ul></div>\n\n";
51 }
52
53 sub show_thumb($) {
54         my ($self, $meta, $photo_id, $click_url) = @_;
55         my $m = $meta->{photo}->{$photo_id};
56         my $annot = UCW::CGI::html_escape($m->{title});
57         my $tf = $self->get('ThumbFormats')->[0];
58         my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
59         my $tw = $tm->{w};
60         my $th = $tm->{h};
61         my $thumb = $self->get('ThumbUrlPrefix') . "$tf/$photo_id.jpg";
62         # Highslide requires title either for all images, or for none
63         my $tit = " title=\"$annot\"";
64         my $aid = 'i'.(++$self->{hs_thumb_counter});
65         my $photo_url = $self->get('PhotoUrlPrefix') . $self->{gal}->photo_file_name($m, $photo_id);
66         print "<li><a id='$aid' href='$click_url' class=highslide onclick='return hs.expand(this, { src: \"$photo_url\" })'>";
67         print "<img src='$thumb' width=$tw height=$th alt='Photo'$tit></a>\n";
68         if ($self->get('GeoHack')) {
69                 my ($lat, $lon) = ($m->{lat}, $m->{lon});
70                 if (defined $lat && defined $lon) {
71                         my $local = "<a href='map.cgi?i=" . $self->{hs_thumb_counter} . "'>trasa</a>";
72                         my $osm = "<a href='http://www.openstreetmap.org/?mlat=$lat&amp;mlon=$lon#map=16/$lat/$lon'>OSM</a>";
73                         print "<div class='highslide-caption'>Ukázat na mapě: $local, $osm</div>\n";
74                 }
75         }
76 }
77
78 sub run($$) {
79         my ($class, $gal) = @_;
80         my $self = $class->SUPER::attach($gal);
81         $self->dispatch();
82         return $self;
83 }
84
85 1;