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