ashleydw / lightbox

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

Gallery (data-gallery) does not work if you don't have data-toggle="lightbox" - Using Javascript #149

Closed sturple closed 8 years ago

sturple commented 8 years ago

Gallery Not Working on Javascript INIT

When creating a data-gallery on elements and creating lightbox via javascript, you shouldn't need to put the data-toggle="lightbox" However if the gallery is created without the data-toggle="lightbox` on the elements the images will never be grouped in a gallery.

For Example

<a href="/path/to/my/image1" data-gallery="mygallery">Image 1</a>
<a href="/path/to/my/image2" data-gallery="mygallery">Image2</a>
 $('.mygallery').ekkoLightbox({title: 'My Gallery'});

Taken from Source Code

existing

this.gallery_items = $(document.body).find('*[data-toggle="lightbox"][data-gallery="' + this.gallery + '"]');.

should be

this.gallery_items = $(document.body).find('*[data-gallery="' + this.gallery + '"]');
  EkkoLightbox.prototype = {
    modal_shown: function() {
      var video_id,
        _this = this;
      if (!this.options.remote) {
        return this.error('No remote target given');
      } else {
        this.gallery = this.$element.data('gallery');
        if (this.gallery) {
          if (this.options.gallery_parent_selector === 'document.body' || this.options.gallery_parent_selector === '') {
            this.gallery_items = $(document.body).find('*[data-toggle="lightbox"][data-gallery="' + this.gallery + '"]');
          } else {
            this.gallery_items = this.$element.parents(this.options.gallery_parent_selector).first().find('*[data-toggle="lightbox"][data-gallery="' + this.gallery + '"]');
          }
ashleydw commented 8 years ago

Yea, this is basically what I said just yesterday in https://github.com/ashleydw/lightbox/pull/146#issuecomment-157995072.

Feel free to open a PR with the toggle removed on those lines (edit the coffeescript files please)