Problem/Motivation
I'd like to add some custom UI to the lightbox, but ideally I'd need to listen to some lightbox events like init as well. I'm not seeing a great place to hook into any of that, and I'm wondering if you have suggestions? Or I could come up with some sort of registration system similar to how Splide works?
I've tried a couple of things so far and I'm hitting some problems:
Drupal.behaviorsattaching isn't working well because of the promise used to load the PhotoSwipeLightbox library. I was hoping to attach events to the lighbox object assigned toDrupal.blazyPhotoSwipe.beforeInit(with the comment "Exposes lightbox object"), but the sequence isblazyPhotoSwipeattach is called and starts loading, then my custom JS attach is called, but nothing is ready yet until the module import promise resolves (Drupal.blazyPhotoSwipe.init.then()).- The only other option I could find is piggypacking off of
Drupal.blazyPhotoSwipe.ui. That happens to exist to add the custom caption, so if I add my custom item there (which I would need to do either way) I'll at least get registered, but there's no opportunity to clean up or listen to other events.
Do you have any thoughts or ideas?
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | blazy_photoswipe-3437745-listeners-5.patch | 9.73 KB | gausarts |
| #4 | blazy_photoswipe-3437745-listeners.patch | 9.2 KB | gausarts |
Comments
Comment #2
gausarts commentedThank you.
Registering UI appears to work, however the current implementation is not really working well to accommodate events due to empty
pswp.pswpobject as per this writing.Be sure to add CSS accordingly to avoid confusion:
Conclusion, we need to inject pswp object manually, or refactor to use gallery element to support multiple instances rather than relying on global
Drupal.blazyPhotoSwipe.beforeInit.Comment #3
gausarts commentedThis is another sample for download link:
https://www.drupal.org/project/blazy_photoswipe/issues/3389181#comment-1...
Comment #4
gausarts commentedThe patch will make immutable
pswpobject available globally, while make it possible to work with individual elements.The last was taken from Slick convention which stores JS instance in the individual gallery element.
This sample will go to
Drupal.behaviors.attachblock:Adjust ES6 mix above accordingly, but fine though.
Also works fine with sample from #3.
Let me know if any betterment for this?
Comment #5
gausarts commentedIIRC, previously using non-indices keys for UI objects appeared to fail, but now works.
But then indices caused duplicated elements on subsequent launches, so I changed:
Drupal.blazyPhotoSwipe.ui[0] = {}, etc.to non-indices keys:
Drupal.blazyPhotoSwipe.ui.customCaption = {}, etc.Comment #7
gausarts commentedThis would do for now.
Improvements are welcome.
Thank you.
Comment #8
karlsheaAwesome, thank you so much! I'll give it a shot.