I can't get data-description working in bluimp-image-gallery

6 views
Skip to first unread message

fugee ohu

unread,
Feb 29, 2016, 5:44:16 PM2/29/16
to Ruby on Rails: Talk
In my view:

<a href= "<%= task.name %>" data-description = "<%= task.comment %>"  data-gallery ><%= image_tag(task.name.thumb) %></a>

In my js file:

blueimp.Gallery(
    document.getElementById('links'), {
        onslide: function (index, slide) {
            var text = this.list[index].getAttribute('data-description'),
                node = this.container.find('.description');
            node.empty();
            if (text) {
                node[0].appendChild(document.createTextNode(text));
            }
        }
});

document.getElementById('links').onclick = function (event) {
    event = event || window.event;
    var target = event.target || event.srcElement,
        link = target.src ? target.parentNode : target,
        options = {index: link, event: event, onslide: function (index, slide) {
            var text = this.list[index].getAttribute('data-description'),
                node = this.container.find('.description');
            node.empty();
            if (text) {
                node[0].appendChild(document.createTextNode(text));
            }
        } },
        links = this.getElementsByTagName('a');
    blueimp.Gallery(links, options);
};

nanaya

unread,
Feb 29, 2016, 11:54:52 PM2/29/16
to rubyonra...@googlegroups.com
Hi

On Tue, Mar 1, 2016, at 07:44, fugee ohu wrote:
> In my view:
>
> <a href= "<%= task.name %>" data-description = "<%= task.comment %>"
> data-gallery ><%= image_tag(task.name.thumb) %></a>
>

I don't know if it's typo in your mail or you just don't notice but
this:

<a href= "<%= task.name %>" data-description = "<%= task.comment %>"
data-gallery >

will have an empty data-description attribute because there are spaces
between the equal sign so they just become another attributes
(data-description = "content" -> three different attributes, two of
which are invalid).

Correct one is:
Reply all
Reply to author
Forward
0 new messages