diff --git a/core/lazyload/resources/lazyload.js b/core/lazyload/resources/lazyload.js index 16765ce54..7d3a829d6 100644 --- a/core/lazyload/resources/lazyload.js +++ b/core/lazyload/resources/lazyload.js @@ -167,19 +167,20 @@ var loadVisibleImages = function () { var visibleImages = getVisibleImages(); - $(visibleImages).each(function (index) { + $(visibleImages).each(function () { // Generate a new image, add the source so it starts loading var $loadImage = $('', { src: this.source }); var image = this; + var imageIndex = images.map(function(e) { return e.id; }).indexOf(image.id); // If the image was loaded successfully $loadImage.on('load', function () { // Remove the image from the images array because it's not // needed anymore - delete images[index]; + delete images[imageIndex]; var $image = $('.' + settings.imageIdentifierPrefix + image.id); var $placeholder = $image.next('.' + settings.placeholderClass); @@ -208,7 +209,7 @@ // If the image can't be loaded $loadImage.on('error', function () { - delete images[index]; + delete images[imageIndex]; // Trigger a error event $(document).trigger("lazyimage-loaded", { diff --git a/core/lazyload/resources/lazyload.min.js b/core/lazyload/resources/lazyload.min.js index 7b2427612..8f65339ba 100644 --- a/core/lazyload/resources/lazyload.min.js +++ b/core/lazyload/resources/lazyload.min.js @@ -1 +1 @@ -!function(e){var t=!1,i={threshold:200,imageIdentifierPrefix:"lazy-image-",imageSelector:".lazy-image:not(.lazy-placeholder)",placeholderClass:"lazy-placeholder",defaultAspectRatio:1.777777778,loaderHtml:'
'},a={viewportChanged:!1,touchScrolling:!1,resized:!1},r=[],o=0,s=function(){r=[],e(i.imageSelector).each(function(t){if(!e(this).hasClass("loaded")){var a=o+=1;e(this).addClass(i.imageIdentifierPrefix+a);var s=parseInt(e(this).attr("data-width")),n=parseInt(e(this).attr("data-height")),d=i.defaultAspectRatio,l=e(this).attr("data-as-background");s&&n&&(d=n/s);var c=!1;e(this).next("."+i.placeholderClass).length>=1&&(c=!0),r.push({id:a,source:e(this).attr("data-src"),boundaries:{},hasPlaceholderImage:e(this).hasClass("lazyimage"),divPlaceholderExists:c,width:s,height:n,aspectRatio:d,asBackground:l,html:e(this)[0].outerHTML})}}),n(),l()},n=function(){e(r).each(function(t){if(!this.hasPlaceholderImage&&!this.asBackground&&!this.divPlaceholderExists){var a=e("."+i.imageIdentifierPrefix+this.id),o=a.attr("class");"string"==typeof o&&(o=o.replace(i.imageIdentifierPrefix+this.id,""));var s=e("
",{class:i.placeholderClass+" "+o});s.append(e("
").css({height:0,"padding-bottom":100*this.aspectRatio+"%"})),s.append(e(i.loaderHtml)),s.insertAfter(a),r[t]&&(r[t].divPlaceholderExists=!0)}})},d=function(){var t,o=(t=function(){return e.grep(r,function(t){if(void 0===t)return!1;var a=e(window).scrollTop(),r=e(window).innerHeight(),o=a-200-i.threshold,s=a+r+200+i.threshold;return t.boundaries.top>=o&&t.boundaries.top<=s||t.boundaries.top<=o&&t.boundaries.bottom<=s&&t.boundaries.bottom>=o})},a.resized?(a.resized=!1,l(t())):t());e(o).each(function(t){var a=e("",{src:this.source}),o=this;a.on("load",function(){delete r[t];var a=e("."+i.imageIdentifierPrefix+o.id),s=a.next("."+i.placeholderClass);a.attr("src",o.source),a.addClass("loaded"),o.asBackground?e("."+i.imageIdentifierPrefix+o.id).css({backgroundImage:"url("+o.source+")"}):o.hasPlaceholderImage||s.hide(),e(document).trigger("lazyimage-loaded",{type:"success",imageId:"."+i.imageIdentifierPrefix+o.id})}),a.on("error",function(){delete r[t],e(document).trigger("lazyimage-loaded",{type:"error",imageId:"."+i.imageIdentifierPrefix+o.id})})})},l=function(t){for(var a in r){var o=r[a],s=e("."+i.imageIdentifierPrefix+o.id),n=s.next("."+i.placeholderClass),d=n.length>0?n.offset().top:s.offset().top;o.boundaries={top:d,bottom:d+(n.length>0?n.outerHeight():s.outerHeight())},r[a]=o}if("function"==typeof t)return t()};e.lazyLoad=function(r){if("string"==typeof r)switch(r){case"refetchElements":s(),d()}else t||(t=!0,r&&(i=e.extend(i,r)),s(),setInterval(function(){!0!==a.viewportChanged&&!0!==a.touchScrolling||(d(),a.viewportChanged=!1,a.touchScrolling=!1)},250),e(document).on("touchmove",function(){a.touchScrolling=!0}),e(window).on("scroll resize",function(){a.viewportChanged=!0,a.touchScrolling=!1}),e(window).on("resize",function(){a.resized=!0}),d());return this}}(jQuery); \ No newline at end of file +!function(e){var i=!1,t={threshold:200,imageIdentifierPrefix:"lazy-image-",imageSelector:".lazy-image:not(.lazy-placeholder)",placeholderClass:"lazy-placeholder",defaultAspectRatio:1.777777778,loaderHtml:'
'},a={viewportChanged:!1,touchScrolling:!1,resized:!1},r=[],o=0,n=function(){r=[],e(t.imageSelector).each(function(i){if(!e(this).hasClass("loaded")){var a=o+=1;e(this).addClass(t.imageIdentifierPrefix+a);var n=parseInt(e(this).attr("data-width")),d=parseInt(e(this).attr("data-height")),s=t.defaultAspectRatio,l=e(this).attr("data-as-background");n&&d&&(s=d/n);var c=!1;e(this).next("."+t.placeholderClass).length>=1&&(c=!0),r.push({id:a,source:e(this).attr("data-src"),boundaries:{},hasPlaceholderImage:e(this).hasClass("lazyimage"),divPlaceholderExists:c,width:n,height:d,aspectRatio:s,asBackground:l,html:e(this)[0].outerHTML})}}),d(),l()},d=function(){e(r).each(function(i){if(!this.hasPlaceholderImage&&!this.asBackground&&!this.divPlaceholderExists){var a=e("."+t.imageIdentifierPrefix+this.id),o=a.attr("class");"string"==typeof o&&(o=o.replace(t.imageIdentifierPrefix+this.id,""));var n=e("
",{class:t.placeholderClass+" "+o});n.append(e("
").css({height:0,"padding-bottom":100*this.aspectRatio+"%"})),n.append(e(t.loaderHtml)),n.insertAfter(a),r[i]&&(r[i].divPlaceholderExists=!0)}})},s=function(){var i,o=(i=function(){return e.grep(r,function(i){if(void 0===i)return!1;var a=e(window).scrollTop(),r=e(window).innerHeight(),o=a-200-t.threshold,n=a+r+200+t.threshold;return i.boundaries.top>=o&&i.boundaries.top<=n||i.boundaries.top<=o&&i.boundaries.bottom<=n&&i.boundaries.bottom>=o})},a.resized?(a.resized=!1,l(i())):i());e(o).each(function(){var i=e("",{src:this.source}),a=this,o=r.map(function(e){return e.id}).indexOf(a.id);i.on("load",function(){delete r[o];var i=e("."+t.imageIdentifierPrefix+a.id),n=i.next("."+t.placeholderClass);i.attr("src",a.source),i.addClass("loaded"),a.asBackground?e("."+t.imageIdentifierPrefix+a.id).css({backgroundImage:"url("+a.source+")"}):a.hasPlaceholderImage||n.hide(),e(document).trigger("lazyimage-loaded",{type:"success",imageId:"."+t.imageIdentifierPrefix+a.id})}),i.on("error",function(){delete r[o],e(document).trigger("lazyimage-loaded",{type:"error",imageId:"."+t.imageIdentifierPrefix+a.id})})})},l=function(i){for(var a in r){var o=r[a],n=e("."+t.imageIdentifierPrefix+o.id),d=n.next("."+t.placeholderClass),s=d.length>0?d.offset().top:n.offset().top;o.boundaries={top:s,bottom:s+(d.length>0?d.outerHeight():n.outerHeight())},r[a]=o}if("function"==typeof i)return i()};e.lazyLoad=function(r){if("string"==typeof r)switch(r){case"refetchElements":n(),s()}else i||(i=!0,r&&(t=e.extend(t,r)),n(),setInterval(function(){!0!==a.viewportChanged&&!0!==a.touchScrolling||(s(),a.viewportChanged=!1,a.touchScrolling=!1)},250),e(document).on("touchmove",function(){a.touchScrolling=!0}),e(window).on("scroll resize",function(){a.viewportChanged=!0,a.touchScrolling=!1}),e(window).on("resize",function(){a.resized=!0}),s());return this}}(jQuery); \ No newline at end of file