diff --git a/script/lightbox.js b/script/lightbox.js index 504455b..0a924dd 100644 --- a/script/lightbox.js +++ b/script/lightbox.js @@ -337,6 +337,8 @@ , type: $link.attr('data-type') , id: $link.attr('data-id') , $Media: $link.attr('data-type')=='video'?self.$video:self.$image + , width: $link.find('img').attr('width') + , height: $link.find('img').attr('height') //ADDED-END }); } @@ -506,15 +508,11 @@ // When image to show is preloaded, we send the width and height to sizeContainer() var preloader = new Image(); preloader.onload = function(){ - var $preloader; - self.$image.attr({ 'alt': self.album[imageNumber].alt, 'src': filename }); - $preloader = $(preloader); - //Orientation management if(Math.abs(self.album[imageNumber].orientation) == 90 && preloader.width > preloader.height) { var sWidth = preloader.width; @@ -557,15 +555,20 @@ }, 0); */ if(e) { - var oMedia = this.album[this.currentImageIndex]; - if(oMedia.type == 'image') { - if(typeof oResizeTimer != 'undefined') clearTimeout(oResizeTimer); - oResizeTimer = setTimeout(()=>{this.changeImage(this.currentImageIndex);}, 200); - } - else { - //var $Media = oMedia.$Media; - //this.updateSize($($Media), $Media.videoWidth, $Media.videoHeight, oMedia.type); - } + if(typeof oResizeTimer != 'undefined') clearTimeout(oResizeTimer); + oResizeTimer = setTimeout( + () => { + switch(this.album[this.currentImageIndex].type) { + case 'image': + this.changeImage(this.currentImageIndex); + break; + case 'video': + this.updateSize(this.currentImageIndex); + break; + } + }, + 200 + ); } //ADDED-END }; @@ -710,11 +713,11 @@ // Preload previous and next images in set. Lightbox.prototype.preloadNeighboringImages = function() { - if (this.album.length > this.currentImageIndex + 1) { + if (this.album.length > this.currentImageIndex + 1 && this.album[this.currentImageIndex + 1].type == 'image') { var preloadNext = new Image(); preloadNext.src = this.album[this.currentImageIndex + 1].link; } - if (this.currentImageIndex > 0) { + if (this.currentImageIndex > 0 && this.album[this.currentImageIndex - 1].type == 'image') { var preloadPrev = new Image(); preloadPrev.src = this.album[this.currentImageIndex - 1].link; }