I’m using Lightbox2 for displaying images in a gallery and would like to include the filename in the image label along with the image number and total count. By default, Lightbox2 allows customization of the label to show the image number and total using the albumLabel option in the format “Image %1 of %2”. I want to modify this to also show the filename of the image being viewed, e.g., “Image %1 of %2 – filename.jpg” just without the .jpg .
Here is the relevant part of my current Lightbox2 setup:
Lightbox.defaults = {
albumLabel: 'Image %1 of %2',
...
};
Lightbox.prototype.imageCountLabel = function(currentImageNum, totalImages) {
return this.options.albumLabel.replace(/%1/g, currentImageNum).replace(/%2/g, totalImages);
};
I’ve tried modifying the albumLabel to include a placeholder for the filename and adjusting the imageCountLabel method to replace it with the actual filename, but it’s not working as expected. Here’s what I’ve attempted:
Lightbox.defaults = {
albumLabel: 'Image %1 of %2 - %3', // Added %3 for filename
...
};
Lightbox.prototype.imageCountLabel = function(currentImageNum, totalImages, filename) {
return this.options.albumLabel
.replace(/%1/g, currentImageNum)
.replace(/%2/g, totalImages)
.replace(/%3/g, filename);
};
Could anyone help me correct this setup or suggest a better way to include the filename in the image label?