# Group all lightbox elements in a discussion

**URL:** https://meta.discourse.org/t/group-all-lightbox-elements-in-a-discussion/61468
**Category:** Development
**Created:** [4월 23, 2017, 5:59오후 UTC](https://meta.discourse.org/t/group-all-lightbox-elements-in-a-discussion/61468 "2017-04-23T17:59:21Z")
**Posts on this page:** 3
**Page:** 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: [4월 23, 2017, 5:59오후 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…

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [4월 24, 2017, 7:46오전 UTC](https://meta.discourse.org/t/group-all-lightbox-elements-in-a-discussion/61468/2 "2017-04-24T07:46:06Z")

</div>

Can you describe what you are trying to achieve? It will help us help you 😉

---

<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: [4월 24, 2017, 10:33오전 UTC](https://meta.discourse.org/t/group-all-lightbox-elements-in-a-discussion/61468/3 "2017-04-24T10:33:11Z")

</div>

🙂 yes sure. I want to create gallery between all the images in a discussion.  
Like is required here: [Navigating between images within a post](https://meta.discourse.org/t/navigating-between-images-within-a-post/39158)

btw, is this a good category for questions like this one?
