]> mj.ucw.cz Git - gallery.git/commitdiff
HighSlide includes photo ID in the hash part of the URL
authorMartin Mares <mj@ucw.cz>
Mon, 3 Feb 2014 00:24:54 +0000 (01:24 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 8 Feb 2015 20:14:18 +0000 (21:14 +0100)
gal/UCW/Gallery/Web/HighSlide.pm
gal/highslide/custom.js

index ecf6a3a4e4a829ae564efb6a19fd5da14b80a6f6..bf0af46d93ba3ddf9570316be42ac5e6e2c3d1de 100644 (file)
@@ -61,9 +61,9 @@ sub show_thumb($) {
        my $thumb = $self->get('ThumbUrlPrefix') . "$tf/$photo_id.jpg";
        # Highslide requires title either for all images, or for none
        my $tit = " title=\"$annot\"";
-       my $aid = $self->{hs_thumb_counter}++ ? "" : " id=thumb1";
+       my $aid = 'i'.(++$self->{hs_thumb_counter});
        my $photo_url = $self->get('PhotoUrlPrefix') . $self->{gal}->photo_file_name($m, $photo_id);
-       print "<li><a$aid href='$click_url' class=highslide onclick='return hs.expand(this, { src: \"$photo_url\" })'>";
+       print "<li><a id='$aid' href='$click_url' class=highslide onclick='return hs.expand(this, { src: \"$photo_url\" })'>";
        print "<img src='$thumb' width=$tw height=$th alt='Photo'$tit></a>\n";
 }
 
index 1a8408df0e2442662bee86a323050ae8a3d6b82c..d801650776517b8ec92e0f461aaf5e0808aa4346 100644 (file)
@@ -39,4 +39,56 @@ hs.addSlideshow({
                relativeTo: 'expander'
        }
 
+
+////////////////////////////////////////////////
+// Dynamic change of the hash part of the URL //
+////////////////////////////////////////////////
+var hashTag = '';
+// Use hashDelimiter to "hide" name of the anchor (and to not scroll the page)
+var hashDelimiter = '_';
+
+hs.extend (hs.Expander.prototype, {
+       onAfterExpand: function(sender) {
+               hashTag = this.a.id;
+               window.location.hash = hashDelimiter + hashTag;
+       },
+
+       onBeforeClose: function(sender) {
+               window.location.hash = '';
+       }
 });
+
+function showDefaultImage() {
+       var hashParts = window.location.hash.split(hashDelimiter);
+       var myThumb = document.getElementById(hashParts[1])
+       if (hashParts[1] && myThumb) myThumb.click();
+       else window.location.hash = '';
+}
+// If the new hash is not equal to the hash we store internally,
+// then it must be the user hitting the "back/forward" button
+function checkHashChange() {
+       var hashParts = window.location.hash.split(hashDelimiter);
+       if (hashParts[1] != hashTag) {
+               hs.close();
+               window.location.hash = '';
+       }
+}
+
+// Add onLoad and onHashChange functions
+if(window.onload) {
+       var current = window.onload;
+       var newAction = function() {
+               current();
+               showDefaultImage();
+       };
+       window.onload = newAction;
+} else window.onload = showDefaultImage;
+
+if(window.onhashchange) {
+       var curronload = window.onHashChange;
+       var newAction = function() {
+               current();
+               checkHashChange();
+       };
+       window.onhashchange = newAction;
+} else window.onhashchange = checkHashChange;