Opening uploaded images in modal windows
-
Yes, as i guessed, when option "delay image loading" iis enabled (and it's enabled by default), images are missing a lot of information that they have when they are finally loaded. They ar emissing src, they are missing parent <a> and some other stuff.
Whole image loading / not loading thing is done in https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/images.js and there is no single hook in there that would enable some plugin magic.
I solved my problem by:- inserting trigger on the bottom of loadImages function. After row 98 i inserted: $(window).trigger('action:images.loaded');
- changed trigger in main.js of gallery plugin from:
$(window).on('action:ajaxify.end', function() {
to:
$(window).on('action:images.loaded', function() {
Now im wondering how could i make this permanent so it can survive next nodebb update? Plugin par is easy, ill just create my own plugin that wont update from github, but nodebb part is out of my knowlage base (im fresh to nodebb so i have no idea what are my options)
Is there a way for me to insert this kind of trigger permanently or at least update proof? Is there a reason (security or otherwise) there is no image trigger inside nodebb? If there is no reason, would you be willing to insert hook like that so image plugins can use it?
Only other way around it (without adding hook to nodebb code) that i know is that i remake plugin so that it hacks and slash generated image code on server side and or user side and basically force what i need out of it. That sounds kinda silly and i'm pretty much sure i'm missing something (i'm pretty much new to nodejs too) that would make this more "elegant" solution.
I did find one plugin that does something similar:
https://github.com/smartameer/nodebb-plugin-gallery-view/blob/master/public/js/main.jsLooks like a lot of unneeded code which could be all skipped if there was image hook available.
-
Here you go.
https://github.com/NodeBB/NodeBB/pull/5828
After i slept on it, i changed position of hook so it works for both "delay loading" turned on and off. Original place was working only for delay loading turned on so it needed one more hook inside "unloadImages" function and i prefer solutions with less code.