# Group all lightbox elements in a discussion

**URL:** <https://meta.discourse.org/t/group-all-lightbox-elements-in-a-discussion/61468>\
**Category:** Development\
**Created:** [April 23, 2017, 5:59pm UTC](https://meta.discourse.org/t/group-all-lightbox-elements-in-a-discussion/61468 "2017-04-23T17:59:21Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![designbygio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/designbygio/32/122415_2.png) [@designbygio](https://meta.discourse.org/u/designbygio)\
**Post date:** [April 23, 2017, 5:59pm UTC](https://meta.discourse.org/t/group-all-lightbox-elements-in-a-discussion/61468/1 "2017-04-23T17:59:21Z")

</div>

I need to group all the `.lightbox` elements in a discussion.  
Does someone has any idea where i should call lightbox.js in order to get fired when all the discussion is ready, not each individual post?

So far i figured out that:  
Lightbox is set up in `lib/lightbox.js` and is called after DOM is rendered by [`api.decorateCooked()`](https://github.com/discourse/discourse/blob/b240437b6f7038f5823ea61e08884be828b95f32/app/assets/javascripts/discourse/lib/plugin-api.js.es6) which just pass a callback function to [`addDecorator()`](https://github.com/discourse/discourse/blob/07d596ea056390fb45440263517bf2ec592041a3/app/assets/javascripts/discourse/widgets/post-cooked.js.es6)  
addDecorator has as argument, a DOM element `cooked`.

Lightbox.js is actually called in the context of each post replay.  
Basically if in `lightbox.js` i do:  
console.log(‘.lighbox’) i get always one or as many picture EACH SINGLE USER added to each replay.  
I need instead to get ALL the image that are in the whole discussion.

So far the only place where i found `lightbox.js` called is in `post-decoration.js`, which it confuse me a little…

---

_[View the full topic](https://meta.discourse.org/t/group-all-lightbox-elements-in-a-discussion/61468)._
