You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP →

vanilla-lazyload

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vanilla-lazyload - npm Package Compare versions

Comparing version

to
5.0.0

@@ -87,2 +87,9 @@ const LazyLoad = require('../src/lazyLoad');

expect(LazyLoad.prototype.update).toHaveBeenCalledTimes(2);
});
});
test("Scroll is managed", () => {
LazyLoad.prototype.handleScroll = jest.fn();
window.scrollTo(0, 1);
expect(LazyLoad.prototype.update).toHaveBeenCalled();
});

@@ -0,0 +0,0 @@ {

/*! Lazy Load 1.9.3 - MIT license - Copyright 2010-2013 Mika Tuupola */
!function(a,b,c,d){var e=a(b);a.fn.lazyload=function(f){function g(){var b=0;i.each(function(){var c=a(this);if(!j.skip_invisible||c.is(":visible"))if(a.abovethetop(this,j)||a.leftofbegin(this,j));else if(a.belowthefold(this,j)||a.rightoffold(this,j)){if(++b>j.failure_limit)return!1}else c.trigger("appear"),b=0})}var h,i=this,j={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:b,data_attribute:"original",skip_invisible:!0,appear:null,load:null,placeholder:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC"};return f&&(d!==f.failurelimit&&(f.failure_limit=f.failurelimit,delete f.failurelimit),d!==f.effectspeed&&(f.effect_speed=f.effectspeed,delete f.effectspeed),a.extend(j,f)),h=j.container===d||j.container===b?e:a(j.container),0===j.event.indexOf("scroll")&&h.bind(j.event,function(){return g()}),this.each(function(){var b=this,c=a(b);b.loaded=!1,(c.attr("src")===d||c.attr("src")===!1)&&c.is("img")&&c.attr("src",j.placeholder),c.one("appear",function(){if(!this.loaded){if(j.appear){var d=i.length;j.appear.call(b,d,j)}a("<img />").bind("load",function(){var d=c.attr("data-"+j.data_attribute);c.hide(),c.is("img")?c.attr("src",d):c.css("background-image","url('"+d+"')"),c[j.effect](j.effect_speed),b.loaded=!0;var e=a.grep(i,function(a){return!a.loaded});if(i=a(e),j.load){var f=i.length;j.load.call(b,f,j)}}).attr("src",c.attr("data-"+j.data_attribute))}}),0!==j.event.indexOf("scroll")&&c.bind(j.event,function(){b.loaded||c.trigger("appear")})}),e.bind("resize",function(){g()}),/(?:iphone|ipod|ipad).*os 5/gi.test(navigator.appVersion)&&e.bind("pageshow",function(b){b.originalEvent&&b.originalEvent.persisted&&i.each(function(){a(this).trigger("appear")})}),a(c).ready(function(){g()}),this},a.belowthefold=function(c,f){var g;return g=f.container===d||f.container===b?(b.innerHeight?b.innerHeight:e.height())+e.scrollTop():a(f.container).offset().top+a(f.container).height(),g<=a(c).offset().top-f.threshold},a.rightoffold=function(c,f){var g;return g=f.container===d||f.container===b?e.width()+e.scrollLeft():a(f.container).offset().left+a(f.container).width(),g<=a(c).offset().left-f.threshold},a.abovethetop=function(c,f){var g;return g=f.container===d||f.container===b?e.scrollTop():a(f.container).offset().top,g>=a(c).offset().top+f.threshold+a(c).height()},a.leftofbegin=function(c,f){var g;return g=f.container===d||f.container===b?e.scrollLeft():a(f.container).offset().left,g>=a(c).offset().left+f.threshold+a(c).width()},a.inviewport=function(b,c){return!(a.rightoffold(b,c)||a.leftofbegin(b,c)||a.belowthefold(b,c)||a.abovethetop(b,c))},a.extend(a.expr[":"],{"below-the-fold":function(b){return a.belowthefold(b,{threshold:0})},"above-the-top":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-screen":function(b){return a.rightoffold(b,{threshold:0})},"left-of-screen":function(b){return!a.rightoffold(b,{threshold:0})},"in-viewport":function(b){return a.inviewport(b,{threshold:0})},"above-the-fold":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-fold":function(b){return a.rightoffold(b,{threshold:0})},"left-of-fold":function(b){return!a.rightoffold(b,{threshold:0})}})}(jQuery,window,document);

@@ -1,2 +0,2 @@

!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.LazyLoad=b()}(this,function(){function a(a,b,c){function d(){return window.innerWidth||l.documentElement.clientWidth||document.body.clientWidth}function e(){return window.innerHeight||l.documentElement.clientHeight||document.body.clientHeight}function f(a){return a.getBoundingClientRect().top+m-l.documentElement.clientTop}function g(a){return a.getBoundingClientRect().left+n-l.documentElement.clientLeft}function h(){var d;return d=b===window?e()+m:f(b)+b.offsetHeight,d<=f(a)-c}function i(){var e;return e=b===window?d()+window.pageXOffset:g(b)+d(),e<=g(a)-c}function j(){var d;return d=b===window?m:f(b),d>=f(a)+c+a.offsetHeight}function k(){var d;return d=b===window?n:g(b),d>=g(a)+c+a.offsetWidth}var l,m,n;return l=a.ownerDocument,m=window.pageYOffset||l.body.scrollTop,n=window.pageXOffset||l.body.scrollLeft,!(h()||j()||i()||k())}function b(){var a=new Date;return a.getTime()}function c(a,b){var c,d={};for(c in a)a.hasOwnProperty(c)&&(d[c]=a[c]);for(c in b)b.hasOwnProperty(c)&&(d[c]=b[c]);return d}function d(a){return Array.prototype.slice.call(a)}function e(a,b){var c=a.parentElement;if("PICTURE"===c.tagName)for(var d=0;d<c.children.length;d++){var e=c.children[d];if("SOURCE"===e.tagName){var f=e.getAttribute("data-"+b);f&&e.setAttribute("srcset",f)}}}function f(a,b,c){var d=a.tagName,f=a.getAttribute("data-"+c);if("IMG"===d){e(a,b);var g=a.getAttribute("data-"+b);return g&&a.setAttribute("srcset",g),void(f&&a.setAttribute("src",f))}return"IFRAME"===d?void(f&&a.setAttribute("src",f)):void(f&&(a.style.backgroundImage="url("+f+")"))}function g(a,b){return function(){return a.apply(b,arguments)}}function h(a){this._settings=c(i,a),this._queryOriginNode=this._settings.container===window?document:this._settings.container,this._previousLoopTime=0,this._loopTimeout=null,this._handleScrollFn=g(this.handleScroll,this),window.addEventListener("resize",this._handleScrollFn),this.update()}var i={elements_selector:"img",container:window,threshold:300,throttle:150,data_src:"original",data_srcset:"original-set",class_loading:"loading",class_loaded:"loaded",skip_invisible:!0,callback_load:null,callback_error:null,callback_set:null,callback_processed:null};return h.prototype._showOnAppear=function(a){function b(){a.removeEventListener("load",c),a.classList.remove(d.class_loading),d.callback_error&&d.callback_error(a)}function c(){null!==d&&(d.callback_load&&d.callback_load(a),a.classList.remove(d.class_loading),a.classList.add(d.class_loaded),a.removeEventListener("load",c),a.removeEventListener("error",b))}var d=this._settings;"IMG"!==a.tagName&&"IFRAME"!==a.tagName||(a.addEventListener("load",c),a.addEventListener("error",b),a.classList.add(d.class_loading)),f(a,d.data_srcset,d.data_src),d.callback_set&&d.callback_set(a)},h.prototype._loopThroughElements=function(){var b,c,d=this._settings,e=this._elements,f=e?e.length:0,g=[];for(b=0;b<f;b++)c=e[b],d.skip_invisible&&null===c.offsetParent||a(c,d.container,d.threshold)&&(this._showOnAppear(c),g.push(b),c.wasProcessed=!0);for(;g.length>0;)e.splice(g.pop(),1),d.callback_processed&&d.callback_processed(e.length);0===f&&this._stopScrollHandler()},h.prototype._purgeElements=function(){var a,b,c=this._elements,d=c.length,e=[];for(a=0;a<d;a++)b=c[a],b.wasProcessed&&e.push(a);for(;e.length>0;)c.splice(e.pop(),1)},h.prototype._startScrollHandler=function(){this._isHandlingScroll||(this._isHandlingScroll=!0,this._settings.container.addEventListener("scroll",this._handleScrollFn))},h.prototype._stopScrollHandler=function(){this._isHandlingScroll&&(this._isHandlingScroll=!1,this._settings.container.removeEventListener("scroll",this._handleScrollFn))},h.prototype.handleScroll=function(){var a,c,d;this._settings&&(c=b(),d=this._settings.throttle,0!==d?(a=d-(c-this._previousLoopTime),a<=0||a>d?(this._loopTimeout&&(clearTimeout(this._loopTimeout),this._loopTimeout=null),this._previousLoopTime=c,this._loopThroughElements()):this._loopTimeout||(this._loopTimeout=setTimeout(g(function(){this._previousLoopTime=b(),this._loopTimeout=null,this._loopThroughElements()},this),a))):this._loopThroughElements())},h.prototype.update=function(){this._elements=d(this._queryOriginNode.querySelectorAll(this._settings.elements_selector)),this._purgeElements(),this._loopThroughElements(),this._startScrollHandler()},h.prototype.destroy=function(){window.removeEventListener("resize",this._handleScrollFn),this._loopTimeout&&(clearTimeout(this._loopTimeout),this._loopTimeout=null),this._stopScrollHandler(),this._elements=null,this._queryOriginNode=null,this._settings=null},h});
!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.LazyLoad=b()}(this,function(){function a(){return(new Date).getTime()}function b(a){this._settings=this._merge_objects(c,a),this._queryOriginNode=this._settings.container===window?document:this._settings.container,this._previousLoopTime=0,this._loopTimeout=null,this._boundHandleScroll=this.handleScroll.bind(this),window.addEventListener("resize",this._boundHandleScroll),this.update()}var c={elements_selector:"img",container:window,threshold:300,throttle:150,data_src:"original",data_srcset:"original-set",class_loading:"loading",class_loaded:"loaded",skip_invisible:!0,callback_load:null,callback_error:null,callback_set:null,callback_processed:null};return b.prototype={_isInsideViewport:function(a,b,c){function d(){return window.innerWidth||l.documentElement.clientWidth||document.body.clientWidth}function e(){return window.innerHeight||l.documentElement.clientHeight||document.body.clientHeight}function f(a){return a.getBoundingClientRect().top+m-l.documentElement.clientTop}function g(a){return a.getBoundingClientRect().left+n-l.documentElement.clientLeft}function h(){return(b===window?e()+m:f(b)+b.offsetHeight)<=f(a)-c}function i(){return(b===window?d()+window.pageXOffset:g(b)+d())<=g(a)-c}function j(){return(b===window?m:f(b))>=f(a)+c+a.offsetHeight}function k(){return(b===window?n:g(b))>=g(a)+c+a.offsetWidth}var l,m,n;return l=a.ownerDocument,m=window.pageYOffset||l.body.scrollTop,n=window.pageXOffset||l.body.scrollLeft,!(h()||j()||i()||k())},_merge_objects:function(a,b){var c,d={};for(c in a)a.hasOwnProperty(c)&&(d[c]=a[c]);for(c in b)b.hasOwnProperty(c)&&(d[c]=b[c]);return d},_setSourcesForPicture:function(a,b){var c=a.parentElement;if("PICTURE"===c.tagName)for(var d=0;d<c.children.length;d++){var e=c.children[d];if("SOURCE"===e.tagName){var f=e.getAttribute("data-"+b);f&&e.setAttribute("srcset",f)}}},_setSources:function(a,b,c){var d=a.tagName,e=a.getAttribute("data-"+c);if("IMG"===d){this._setSourcesForPicture(a,b);var f=a.getAttribute("data-"+b);return f&&a.setAttribute("srcset",f),void(e&&a.setAttribute("src",e))}if("IFRAME"===d)return void(e&&a.setAttribute("src",e));e&&(a.style.backgroundImage="url("+e+")")},_showOnAppear:function(a){function b(){a.removeEventListener("load",c),a.classList.remove(d.class_loading),d.callback_error&&d.callback_error(a)}function c(){null!==d&&(d.callback_load&&d.callback_load(a),a.classList.remove(d.class_loading),a.classList.add(d.class_loaded),a.removeEventListener("load",c),a.removeEventListener("error",b))}var d=this._settings;"IMG"!==a.tagName&&"IFRAME"!==a.tagName||(a.addEventListener("load",c),a.addEventListener("error",b),a.classList.add(d.class_loading)),this._setSources(a,d.data_srcset,d.data_src),d.callback_set&&d.callback_set(a)},_loopThroughElements:function(){var a,b,c=this._settings,d=this._elements,e=d?d.length:0,f=[];for(a=0;a<e;a++)b=d[a],c.skip_invisible&&null===b.offsetParent||this._isInsideViewport(b,c.container,c.threshold)&&(this._showOnAppear(b),f.push(a),b.wasProcessed=!0);for(;f.length>0;)d.splice(f.pop(),1),c.callback_processed&&c.callback_processed(d.length);0===e&&this._stopScrollHandler()},_purgeElements:function(){var a,b,c=this._elements,d=c.length,e=[];for(a=0;a<d;a++)b=c[a],b.wasProcessed&&e.push(a);for(;e.length>0;)c.splice(e.pop(),1)},_startScrollHandler:function(){this._isHandlingScroll||(this._isHandlingScroll=!0,this._settings.container.addEventListener("scroll",this._boundHandleScroll))},_stopScrollHandler:function(){this._isHandlingScroll&&(this._isHandlingScroll=!1,this._settings.container.removeEventListener("scroll",this._boundHandleScroll))},handleScroll:function(){var b,c,d;this._settings&&(c=a(),d=this._settings.throttle,0!==d?(b=d-(c-this._previousLoopTime),b<=0||b>d?(this._loopTimeout&&(clearTimeout(this._loopTimeout),this._loopTimeout=null),this._previousLoopTime=c,this._loopThroughElements()):this._loopTimeout||(this._loopTimeout=setTimeout(function(){this._previousLoopTime=a(),this._loopTimeout=null,this._loopThroughElements()}.bind(this),b))):this._loopThroughElements())},update:function(){this._elements=Array.prototype.slice.call(this._queryOriginNode.querySelectorAll(this._settings.elements_selector)),this._purgeElements(),this._loopThroughElements(),this._startScrollHandler()},destroy:function(){window.removeEventListener("resize",this._boundHandleScroll),this._loopTimeout&&(clearTimeout(this._loopTimeout),this._loopTimeout=null),this._stopScrollHandler(),this._elements=null,this._queryOriginNode=null,this._settings=null}},b});
//# sourceMappingURL=lazyload.min.js.map

@@ -0,0 +0,0 @@ module.exports = function(grunt) {

@@ -0,0 +0,0 @@ The MIT License (MIT)

{
"name": "vanilla-lazyload",
"version": "4.1.0",
"version": "5.0.0",
"description": "A fast, lightweight script to load images as they enter the viewport. Supporting responsive images (both srcset + sizes and picture).",

@@ -5,0 +5,0 @@ "main": "dist/lazyload.min.js",

@@ -0,0 +0,0 @@ # LazyLoad (aka Vanilla LazyLoad)

@@ -1,2 +0,2 @@

(function(root, factory) {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {

@@ -9,3 +9,3 @@ define([], factory);

}
}(this, function() {
}(this, function () {

@@ -28,332 +28,322 @@ var _defaultSettings = {

/*
* UTILITY FUNCTIONS
* -----------------
*/
function _now() {
var d = new Date();
return d.getTime();
}
/*
* PRIVATE FUNCTIONS *NOT RELATED* TO A SPECIFIC INSTANCE OF LAZY LOAD
* -------------------------------------------------------------------
* CONSTRUCTOR
* -----------
*/
function _isInsideViewport(element, container, threshold) {
function LazyLoad(instanceSettings) {
this._settings = this._merge_objects(_defaultSettings, instanceSettings);
this._queryOriginNode = this._settings.container === window ? document : this._settings.container;
var ownerDocument, documentTop, documentLeft;
this._previousLoopTime = 0;
this._loopTimeout = null;
this._boundHandleScroll = this.handleScroll.bind(this);
function _getDocumentWidth() {
return window.innerWidth || (ownerDocument.documentElement.clientWidth || document.body.clientWidth);
}
window.addEventListener("resize", this._boundHandleScroll);
this.update();
}
function _getDocumentHeight() {
return window.innerHeight || (ownerDocument.documentElement.clientHeight || document.body.clientHeight);
}
LazyLoad.prototype = {
function _getTopOffset(element) {
return element.getBoundingClientRect().top + documentTop - ownerDocument.documentElement.clientTop;
}
/*
* PRIVATE FUNCTIONS
* -----------------
*/
function _getLeftOffset(element) {
return element.getBoundingClientRect().left + documentLeft - ownerDocument.documentElement.clientLeft;
}
_isInsideViewport: function (element, container, threshold) {
function _isBelowViewport() {
var fold;
if (container === window) {
fold = _getDocumentHeight() + documentTop;
} else {
fold = _getTopOffset(container) + container.offsetHeight;
var ownerDocument, documentTop, documentLeft;
function _getDocumentWidth() {
return window.innerWidth || (ownerDocument.documentElement.clientWidth || document.body.clientWidth);
}
return fold <= _getTopOffset(element) - threshold;
}
function _isAtRightOfViewport() {
var fold;
if (container === window) {
fold = _getDocumentWidth() + window.pageXOffset;
} else {
fold = _getLeftOffset(container) + _getDocumentWidth();
function _getDocumentHeight() {
return window.innerHeight || (ownerDocument.documentElement.clientHeight || document.body.clientHeight);
}
return fold <= _getLeftOffset(element) - threshold;
}
function _isAboveViewport() {
var fold;
if (container === window) {
fold = documentTop;
} else {
fold = _getTopOffset(container);
function _getTopOffset(element) {
return element.getBoundingClientRect().top + documentTop - ownerDocument.documentElement.clientTop;
}
return fold >= _getTopOffset(element) + threshold + element.offsetHeight;
}
function _isAtLeftOfViewport() {
var fold;
if (container === window) {
fold = documentLeft;
} else {
fold = _getLeftOffset(container);
function _getLeftOffset(element) {
return element.getBoundingClientRect().left + documentLeft - ownerDocument.documentElement.clientLeft;
}
return fold >= _getLeftOffset(element) + threshold + element.offsetWidth;
}
ownerDocument = element.ownerDocument;
documentTop = window.pageYOffset || ownerDocument.body.scrollTop;
documentLeft = window.pageXOffset || ownerDocument.body.scrollLeft;
function _isBelowViewport() {
var fold;
if (container === window) {
fold = _getDocumentHeight() + documentTop;
} else {
fold = _getTopOffset(container) + container.offsetHeight;
}
return fold <= _getTopOffset(element) - threshold;
}
return !_isBelowViewport() && !_isAboveViewport() && !_isAtRightOfViewport() && !_isAtLeftOfViewport();
}
function _isAtRightOfViewport() {
var fold;
if (container === window) {
fold = _getDocumentWidth() + window.pageXOffset;
} else {
fold = _getLeftOffset(container) + _getDocumentWidth();
}
return fold <= _getLeftOffset(element) - threshold;
}
function _now() {
var d = new Date();
return d.getTime();
}
function _isAboveViewport() {
var fold;
if (container === window) {
fold = documentTop;
} else {
fold = _getTopOffset(container);
}
return fold >= _getTopOffset(element) + threshold + element.offsetHeight;
}
function _merge_objects(obj1, obj2) {
var obj3 = {},
propertyName;
for (propertyName in obj1) {
if (obj1.hasOwnProperty(propertyName)) {
obj3[propertyName] = obj1[propertyName];
function _isAtLeftOfViewport() {
var fold;
if (container === window) {
fold = documentLeft;
} else {
fold = _getLeftOffset(container);
}
return fold >= _getLeftOffset(element) + threshold + element.offsetWidth;
}
}
for (propertyName in obj2) {
if (obj2.hasOwnProperty(propertyName)) {
obj3[propertyName] = obj2[propertyName];
}
}
return obj3;
}
function _convertToArray(nodeSet) {
return Array.prototype.slice.call(nodeSet);
}
ownerDocument = element.ownerDocument;
documentTop = window.pageYOffset || ownerDocument.body.scrollTop;
documentLeft = window.pageXOffset || ownerDocument.body.scrollLeft;
function _setSourcesForPicture(element, srcsetDataAttribute) {
var parent = element.parentElement;
if (parent.tagName !== 'PICTURE') {
return;
}
for (var i = 0; i < parent.children.length; i++) {
var pictureChild = parent.children[i];
if (pictureChild.tagName === 'SOURCE') {
var sourceSrcset = pictureChild.getAttribute('data-' + srcsetDataAttribute);
if (sourceSrcset) {
pictureChild.setAttribute('srcset', sourceSrcset);
return !_isBelowViewport() && !_isAboveViewport() && !_isAtRightOfViewport() && !_isAtLeftOfViewport();
},
_merge_objects: function (obj1, obj2) {
var obj3 = {},
propertyName;
for (propertyName in obj1) {
if (obj1.hasOwnProperty(propertyName)) {
obj3[propertyName] = obj1[propertyName];
}
}
}
}
for (propertyName in obj2) {
if (obj2.hasOwnProperty(propertyName)) {
obj3[propertyName] = obj2[propertyName];
}
}
return obj3;
},
function _setSources(element, srcsetDataAttribute, srcDataAttribute) {
var tagName = element.tagName;
var elementSrc = element.getAttribute('data-' + srcDataAttribute);
if (tagName === "IMG") {
_setSourcesForPicture(element, srcsetDataAttribute);
var imgSrcset = element.getAttribute('data-' + srcsetDataAttribute);
if (imgSrcset) element.setAttribute("srcset", imgSrcset);
if (elementSrc) element.setAttribute("src", elementSrc);
return;
}
if (tagName === "IFRAME") {
if (elementSrc) element.setAttribute("src", elementSrc);
return;
}
if (elementSrc) element.style.backgroundImage = "url(" + elementSrc + ")";
}
_setSourcesForPicture: function (element, srcsetDataAttribute) {
var parent = element.parentElement;
if (parent.tagName !== 'PICTURE') {
return;
}
for (var i = 0; i < parent.children.length; i++) {
var pictureChild = parent.children[i];
if (pictureChild.tagName === 'SOURCE') {
var sourceSrcset = pictureChild.getAttribute('data-' + srcsetDataAttribute);
if (sourceSrcset) {
pictureChild.setAttribute('srcset', sourceSrcset);
}
}
}
},
function _bind(fn, obj) {
return function() {
return fn.apply(obj, arguments);
};
}
_setSources: function (element, srcsetDataAttribute, srcDataAttribute) {
var tagName = element.tagName;
var elementSrc = element.getAttribute('data-' + srcDataAttribute);
if (tagName === "IMG") {
this._setSourcesForPicture(element, srcsetDataAttribute);
var imgSrcset = element.getAttribute('data-' + srcsetDataAttribute);
if (imgSrcset) element.setAttribute("srcset", imgSrcset);
if (elementSrc) element.setAttribute("src", elementSrc);
return;
}
if (tagName === "IFRAME") {
if (elementSrc) element.setAttribute("src", elementSrc);
return;
}
if (elementSrc) element.style.backgroundImage = "url(" + elementSrc + ")";
},
_showOnAppear: function (element) {
var settings = this._settings;
/*
* INITIALIZER
* -----------
*/
function errorCallback() {
element.removeEventListener("load", loadCallback);
element.classList.remove(settings.class_loading);
if (settings.callback_error) {
settings.callback_error(element);
}
}
function LazyLoad(instanceSettings) {
this._settings = _merge_objects(_defaultSettings, instanceSettings);
this._queryOriginNode = this._settings.container === window ? document : this._settings.container;
function loadCallback() {
/* As this method is asynchronous, it must be protected against external destroy() calls */
if (settings === null) {
return;
}
/* Calling LOAD callback */
if (settings.callback_load) {
settings.callback_load(element);
}
element.classList.remove(settings.class_loading);
element.classList.add(settings.class_loaded);
element.removeEventListener("load", loadCallback);
element.removeEventListener("error", errorCallback);
}
this._previousLoopTime = 0;
this._loopTimeout = null;
if (element.tagName === "IMG" || element.tagName === "IFRAME") {
element.addEventListener("load", loadCallback);
element.addEventListener("error", errorCallback);
element.classList.add(settings.class_loading);
}
this._handleScrollFn = _bind(this.handleScroll, this);
this._setSources(element, settings.data_srcset, settings.data_src);
/* Calling SET callback */
if (settings.callback_set) {
settings.callback_set(element);
}
},
window.addEventListener("resize", this._handleScrollFn);
this.update();
}
_loopThroughElements: function () {
var i, element,
settings = this._settings,
elements = this._elements,
elementsLength = (!elements) ? 0 : elements.length,
processedIndexes = [];
for (i = 0; i < elementsLength; i++) {
element = elements[i];
/* If must skip_invisible and element is invisible, skip it */
if (settings.skip_invisible && (element.offsetParent === null)) {
continue;
}
if (this._isInsideViewport(element, settings.container, settings.threshold)) {
this._showOnAppear(element);
/*
* PRIVATE FUNCTIONS *RELATED* TO A SPECIFIC INSTANCE OF LAZY LOAD
* ---------------------------------------------------------------
*/
LazyLoad.prototype._showOnAppear = function(element) {
var settings = this._settings;
function errorCallback() {
element.removeEventListener("load", loadCallback);
element.classList.remove(settings.class_loading);
if (settings.callback_error) {
settings.callback_error(element);
/* Marking the element as processed. */
processedIndexes.push(i);
element.wasProcessed = true;
}
}
}
function loadCallback() {
/* As this method is asynchronous, it must be protected against external destroy() calls */
if (settings === null) {
return;
/* Removing processed elements from this._elements. */
while (processedIndexes.length > 0) {
elements.splice(processedIndexes.pop(), 1);
/* Calling the end loop callback */
if (settings.callback_processed) {
settings.callback_processed(elements.length);
}
}
/* Calling LOAD callback */
if (settings.callback_load) {
settings.callback_load(element);
/* Stop listening to scroll event when 0 elements remains */
if (elementsLength === 0) {
this._stopScrollHandler();
}
element.classList.remove(settings.class_loading);
element.classList.add(settings.class_loaded);
element.removeEventListener("load", loadCallback);
element.removeEventListener("error", errorCallback);
}
},
if (element.tagName === "IMG" || element.tagName === "IFRAME") {
element.addEventListener("load", loadCallback);
element.addEventListener("error", errorCallback);
element.classList.add(settings.class_loading);
}
_purgeElements: function () {
var i, element,
elements = this._elements,
elementsLength = elements.length,
elementsToPurge = [];
_setSources(element, settings.data_srcset, settings.data_src);
/* Calling SET callback */
if (settings.callback_set) {
settings.callback_set(element);
}
};
LazyLoad.prototype._loopThroughElements = function() {
var i, element,
settings = this._settings,
elements = this._elements,
elementsLength = (!elements) ? 0 : elements.length,
processedIndexes = [];
for (i = 0; i < elementsLength; i++) {
element = elements[i];
/* If must skip_invisible and element is invisible, skip it */
if (settings.skip_invisible && (element.offsetParent === null)) {
continue;
for (i = 0; i < elementsLength; i++) {
element = elements[i];
/* If the element has already been processed, skip it */
if (element.wasProcessed) {
elementsToPurge.push(i);
}
}
if (_isInsideViewport(element, settings.container, settings.threshold)) {
this._showOnAppear(element);
/* Removing elements to purge from this._elements. */
while (elementsToPurge.length > 0) {
elements.splice(elementsToPurge.pop(), 1);
}
},
/* Marking the element as processed. */
processedIndexes.push(i);
element.wasProcessed = true;
_startScrollHandler: function () {
if (!this._isHandlingScroll) {
this._isHandlingScroll = true;
this._settings.container.addEventListener("scroll", this._boundHandleScroll);
}
}
/* Removing processed elements from this._elements. */
while (processedIndexes.length > 0) {
elements.splice(processedIndexes.pop(), 1);
/* Calling the end loop callback */
if (settings.callback_processed) {
settings.callback_processed(elements.length);
}
}
/* Stop listening to scroll event when 0 elements remains */
if (elementsLength === 0) {
this._stopScrollHandler();
}
};
},
LazyLoad.prototype._purgeElements = function() {
var i, element,
elements = this._elements,
elementsLength = elements.length,
elementsToPurge = [];
for (i = 0; i < elementsLength; i++) {
element = elements[i];
/* If the element has already been processed, skip it */
if (element.wasProcessed) {
elementsToPurge.push(i);
_stopScrollHandler: function () {
if (this._isHandlingScroll) {
this._isHandlingScroll = false;
this._settings.container.removeEventListener("scroll", this._boundHandleScroll);
}
}
/* Removing elements to purge from this._elements. */
while (elementsToPurge.length > 0) {
elements.splice(elementsToPurge.pop(), 1);
}
};
},
LazyLoad.prototype._startScrollHandler = function() {
if (!this._isHandlingScroll) {
this._isHandlingScroll = true;
this._settings.container.addEventListener("scroll", this._handleScrollFn);
}
};
LazyLoad.prototype._stopScrollHandler = function() {
if (this._isHandlingScroll) {
this._isHandlingScroll = false;
this._settings.container.removeEventListener("scroll", this._handleScrollFn);
}
};
/*
* PUBLIC FUNCTIONS
* ----------------
*/
handleScroll: function () {
var remainingTime,
now,
throttle;
/*
* PUBLIC FUNCTIONS
* ----------------
*/
// IE8 fix for destroy() malfunctioning
if (!this._settings) {
return;
}
LazyLoad.prototype.handleScroll = function() {
var remainingTime,
now,
throttle;
now = _now();
throttle = this._settings.throttle;
// IE8 fix for destroy() malfunctioning
if (!this._settings) {
return;
}
now = _now();
throttle = this._settings.throttle;
if (throttle !== 0) {
remainingTime = throttle - (now - this._previousLoopTime);
if (remainingTime <= 0 || remainingTime > throttle) {
if (this._loopTimeout) {
clearTimeout(this._loopTimeout);
this._loopTimeout = null;
if (throttle !== 0) {
remainingTime = throttle - (now - this._previousLoopTime);
if (remainingTime <= 0 || remainingTime > throttle) {
if (this._loopTimeout) {
clearTimeout(this._loopTimeout);
this._loopTimeout = null;
}
this._previousLoopTime = now;
this._loopThroughElements();
} else if (!this._loopTimeout) {
this._loopTimeout = setTimeout(function () {
this._previousLoopTime = _now();
this._loopTimeout = null;
this._loopThroughElements();
}.bind(this), remainingTime);
}
this._previousLoopTime = now;
} else {
this._loopThroughElements();
} else if (!this._loopTimeout) {
this._loopTimeout = setTimeout(_bind(function() {
this._previousLoopTime = _now();
this._loopTimeout = null;
this._loopThroughElements();
}, this), remainingTime);
}
} else {
},
update: function () {
// Converts to array the nodeset obtained querying the DOM from _queryOriginNode with elements_selector
this._elements = Array.prototype.slice.call(this._queryOriginNode.querySelectorAll(this._settings.elements_selector));
this._purgeElements();
this._loopThroughElements();
}
};
this._startScrollHandler();
},
LazyLoad.prototype.update = function() {
this._elements = _convertToArray(this._queryOriginNode.querySelectorAll(this._settings.elements_selector));
this._purgeElements();
this._loopThroughElements();
this._startScrollHandler();
};
LazyLoad.prototype.destroy = function() {
window.removeEventListener("resize", this._handleScrollFn);
if (this._loopTimeout) {
clearTimeout(this._loopTimeout);
this._loopTimeout = null;
destroy: function () {
window.removeEventListener("resize", this._boundHandleScroll);
if (this._loopTimeout) {
clearTimeout(this._loopTimeout);
this._loopTimeout = null;
}
this._stopScrollHandler();
this._elements = null;
this._queryOriginNode = null;
this._settings = null;
}
this._stopScrollHandler();
this._elements = null;
this._queryOriginNode = null;
this._settings = null;
};
return LazyLoad;
}));

@@ -0,0 +0,0 @@ TODO

@@ -0,0 +0,0 @@ interface ILazyLoadOptions {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet