ashleydw / lightbox

A lightbox gallery plugin for Bootstrap
http://ashleydw.github.io/lightbox
MIT License
1.85k stars 1.3k forks source link

Added new configuration options that allow specifying which attribute… #276

Open chasepeeler opened 6 years ago

chasepeeler commented 6 years ago

A few simple changes: 1.) allows users to specify alternate attributes to use for the data source, title, and footer. These still default to data-remote, data-title, and data-footer, so it won't break anything.

I have images where the src is a dataUrl. I found that I was having to store the string twice, once in the src attribute, and once in the data-remote attribute. With these updates, I can just specify that the data is in the src attribute: $(myImage).ekkoLightbox({dataSrc: "src"});

2.) I created a new method called _getAttr(element,attr). If the attribute starts with data-, it'll use $(element).data(), otherwise it'll use $(element).attr().

Users should expect that they can manipulate the values in the data- attributes using the data method. Since data-remote was being accessed directly, any updates made via .data('remote',someUrl); would not get picked up by lightbox. This new method allows accessing the data- attributes via the data method, but, still allows accessing non-data attributes via attr, in order to support the update above for allowing alternate attributes to be specified as the sources for various items.

chasepeeler commented 6 years ago

Made another small update that allows specifying a callback to use for the dataSrc, titleSrc, or footerSrc elements.

$(img).ekkoLightbox(
    {
        dataSrc: 'src',
        footerSrc: function(){
            return $(this).data('description').trim() || $(this).data('name');
        }
    }
);
chasepeeler commented 6 years ago

Just made another update to remove a console.log that I left in by accident. While I was at it, I went ahead and squashed my commits.