From: Martin Mares Date: Mon, 3 Feb 2014 00:24:54 +0000 (+0100) Subject: HighSlide includes photo ID in the hash part of the URL X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=2488aa622dc15f0c5bf553ec85b4832fb571a4a0;p=gallery.git HighSlide includes photo ID in the hash part of the URL --- diff --git a/gal/UCW/Gallery/Web/HighSlide.pm b/gal/UCW/Gallery/Web/HighSlide.pm index ecf6a3a..bf0af46 100644 --- a/gal/UCW/Gallery/Web/HighSlide.pm +++ b/gal/UCW/Gallery/Web/HighSlide.pm @@ -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 "
  • "; + print "
  • "; print "Photo\n"; } diff --git a/gal/highslide/custom.js b/gal/highslide/custom.js index 1a8408d..d801650 100644 --- a/gal/highslide/custom.js +++ b/gal/highslide/custom.js @@ -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;