Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is it possible to subscribe to event notifications for Lightbox2, so that we can run custom JS when the lightbox is displayed / closed / etc?
How are people handling this currently>
Comments
Comment #1
xurizaemonFound a solution to my initial question via StackOverflow.
I wanted to fire Drupal.zipcart.init() after the Lightbox was displayed.
Extend the Lightbox.updateNav function so it fires a custom event when called. This code can be added to site custom JS, and doesn't require patching Lightbox2 module.
Would be great to add some jQuery trigger() calls to Lightbox2 so this is simpler for people to do. For now, the above code works for me.
Comment #2
lobo235 CreditAttribution: lobo235 commentedI would agree that adding jQuery trigger() calls to Lightbox2 would be highly beneficial. If my case, I need to use jQuery to modify the contents of the lightbox once it has been loaded via ajax.
Comment #3
onelittleant CreditAttribution: onelittleant commentedI would recommend that the following Lightbox functions trigger events:
- start
- end
- pause
- togglePlayPause
- changeData
Thanks to grobot above. We used this approach to attach custom Google Analytics events to lightbox actions by hijacking the Lightbox.start function:
Comment #4
yukare CreditAttribution: yukare commentedPlease, can you work on a real patch for this? If someone provides a patch to do this on lightbox in a general way(meaning that it works for all cases and not for a specific site/module) because there are many issues how to do things like this, and if we have a simple way to all cases, will be good.
I plan to make a new 6.12 release at the end of month.