link to image

May 3, 2012 at 12:58 PM


I'm implementing your script and I'd like to know how to make it possible to link to a particular image in the gallery.

I get my images from my database, where every image has its unique ID. I've already added this ID to the thumb's 'id'-attribute. So a thumbnail item might look like this now:


<img title="HPIM2444" longdesc="server/php/files/12_HPIM2444.JPG" src="server/php/thumbnails/12_HPIM2444.JPG" id="12" style="opacity: 1;">



I also added 'id' to context.images[]:

context.images[i] = { thumb: thumb.attr('src'), image: image_src, error: false, preloaded: false, desc: desc, title: title, size: false, link: link, id: id };


Now imagine a link to an image: "adgallery.php?photoid=12"

I then can extract photoid and get the index by searching for the id in context.images with this function:


function getIndexOf(v) {
  var a = context.images;
  var l = a.length;
  for (var k=0;k<l;k++) {
    if (a[k].id==v) {
        return k;
  return false;



I guessed that I could then set the returned value as start_at_index.

That last bit is causing problems though, since start_at_index is already set at the beginning or your script. Can you help me sort this out, or enlighten me with an easier way to link to an image in the gallery?



May 4, 2012 at 7:59 AM


I'm working on that currently. Right now, you can append #ad-image4 in the url to start att image 5, but there are some issues with it currently. I'll be making a release soon that should fix this.

May 4, 2012 at 12:13 PM

Thanks for your reply, 

It's a nice function but does not allow me to permalink to a specific image: When I add new photos to the gallery the link will not direct me to the same image anymore.

I think the way i'm doing it could work if i could just pass the returned value of getIndexOf(v) to start_at_index somehow. You got any thoughts on that?



May 4, 2012 at 3:31 PM

I'm planning on implementing both #ad-image-[index] as well as #ad-image-[image id]. Then you get permalinks, as long as you don't change the image id of course.

I'll also add a hashchange listener to make it easier to link to specific images.

May 4, 2012 at 6:58 PM

That's great news!

Can you give me any kind of time estimate ?

May 5, 2012 at 8:44 AM

I hope to make a new release within a week, but I can't make any promises unfortunately.

May 6, 2012 at 8:38 AM

I've just commited a fix for this, where you can use both #ad-image-[index] or #ad-image-[link id], but I won't be making a release just yet. If you need if before I can make a release, just grab the code from the Souce Code tab.