From c09325326915f2a5264513110fdca54cc493908e Mon Sep 17 00:00:00 2001 From: Morten Winther Olsson Date: Tue, 17 Apr 2018 21:29:15 +0200 Subject: [PATCH] Bug fix for onload race condition Proposed fix for bug illustrated on https://jsfiddle.net/olwimo/h633q2re/ Please note that this is a quick&dirty fix off the top of my head, and I haven't done any testing yet; I'll do a few quick tests soon, just to be sure I haven't missed some obvious fault/better solution, but I'm not too familiar with lightbox, so it's better if you guys find the "right" way to fix it anyway - I just didn't want to report the bug without at least suggesting a way to fix it. --- src/js/lightbox.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/js/lightbox.js b/src/js/lightbox.js index 5b8785aa..174948fd 100644 --- a/src/js/lightbox.js +++ b/src/js/lightbox.js @@ -30,6 +30,7 @@ function Lightbox(options) { this.album = []; + this.albumResetCounter = 0; this.currentImageIndex = void 0; this.init(); @@ -207,6 +208,7 @@ this.sizeOverlay(); + this.albumResetCounter++; this.album = []; var imageNumber = 0; @@ -265,6 +267,7 @@ // Hide most UI elements in preparation for the animated resizing of the lightbox. Lightbox.prototype.changeImage = function(imageNumber) { var self = this; + var albumResetCounter = this.albumResetCounter; this.disableKeyboardNav(); var $image = this.$lightbox.find('.lb-image'); @@ -287,6 +290,9 @@ var windowHeight; var windowWidth; + if (albumResetCounter !== self.albumResetCounter) + return; + $image.attr({ 'alt': self.album[imageNumber].alt, 'src': self.album[imageNumber].link