Lightbox2: Adding a Download Link

I implemented the truly awesome Lightbox2 Drupal module for one of my customers recently. It performed as advertised pretty much out of the box. The photo gallery displayed in beautiful DHTML just like the big boys did it. Only problem, as was quickly pointed out to me, was that there was no way to actually download the pictures. Interesting oversight.

With a bit of trial and error, I figured out where I needed to tweak the code to add the download link. If you need this bit of functionality, crack open the /modules/lightbox2/js/lightbox.js file in your favorite text editor. Scroll down to around line 734 and look for a line like this:

numberDisplay = s.image_count.replace(/\!current/, currentImage).replace(/\!total/, Lightbox.total);

Append, right under that, these two lines:

var imgLink = '[<a href="'+Lightbox.imageArray[Lightbox.activeImage][0]+'">Download Image</a>]';  
numberDisplay = numberDisplay + "<br />" + imgLink;

Voila. You're done. You should now see a link directly under the "X of Y" gallery count to download the image. This should take care of it for all image galleries. You could scroll down and add similar code for other media types if you need to.

Don't forget that modifications to contributed code can be blown away with the next patch. Keep good records. Check your code in. Eat your vegetables.

Comments

Thanks, Worked Perfectly