miromannino / Justified-Gallery

Javascript library to help creating high quality justified galleries of images. Used by thousands of websites as well as the photography community 500px.
http://miromannino.github.io/Justified-Gallery/
MIT License
1.68k stars 299 forks source link

`jg.complete` not firing consistently under certain conditions #314

Closed henryshunt closed 4 years ago

henryshunt commented 5 years ago

I have a button below my gallery that lets the user load more images if not enough images were loaded to require the scrollbar (scrolling to the end would otherwise auto load more). I was testing that this button works, by first letting the page load some initial images, and then zooming out the page until I can see the button without scrolling, then clicking on it to load more images.

I subsequently discovered a bug where, after the loading of images resulting from clicking the button, the images add and display fine (using the norewind option), but the jg.complete event will sometimes fire, other times not. It is a 50/50 chance whether the event will be fired or not. To give you an example, I repeated the above actions multiple times, immediately after each other and refreshing the page in between each one, with zero changes made to either the code or how the page was used. I got the following relating to whether the jg.complete event was fired after clicking the button: not fired, fired, not fired, not fired, not fired, fired, fired, not fired.

I was able to stop the bug happening by removing the first return statement in the analyzeImages function, but I do not know the codebase well so am not expecting that to have no side effects.

Hopefully this info, and the fix that I have found to work will enable you to pinpoint the real cause and fix it. The furthest I got with debugging was establishing that analyzeImages(false) is being called but it never reaches the line responsible for triggering the event.