Skip to content

Commit

Permalink
Releasing 13.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Verlicchi committed Mar 2, 2020
1 parent ea2b220 commit f1e008d
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 449 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Please note that the video poster can be lazily loaded too.

## 👩‍💻 Getting started - Script

The latest, recommended version of LazyLoad is **13.0.0**.
The latest, recommended version of LazyLoad is **13.0.1**.

### To polyfill or not to polyfill IntersectionObserver?

Expand All @@ -128,14 +128,14 @@ If you prefer to load a polyfill, the regular LazyLoad behaviour is granted.
The easiest way to use LazyLoad is to include the script from a CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].0/dist/lazyload.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].1/dist/lazyload.min.js"></script>
```

Or, with the IntersectionObserver polyfill:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected]/intersection-observer.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].0/dist/lazyload.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].1/dist/lazyload.min.js"></script>
```

Then, in your javascript code:
Expand Down Expand Up @@ -168,7 +168,7 @@ Include RequireJS:
Then `require` the AMD version of LazyLoad, like this:

```js
var lazyLoadAmdUrl = "https://cdn.jsdelivr.net/npm/[email protected].0/dist/lazyload.amd.min.js";
var lazyLoadAmdUrl = "https://cdn.jsdelivr.net/npm/[email protected].1/dist/lazyload.amd.min.js";
var polyfillAmdUrl = "https://cdn.jsdelivr.net/npm/[email protected]/intersection-observer-amd.js";

/// Dynamically define the dependencies
Expand Down Expand Up @@ -214,7 +214,7 @@ Then include the script.
```html
<script
async
src="https://cdn.jsdelivr.net/npm/[email protected].0/dist/lazyload.min.js"
src="https://cdn.jsdelivr.net/npm/[email protected].1/dist/lazyload.min.js"
></script>
```
Expand Down Expand Up @@ -247,7 +247,7 @@ Then include the script.
```html
<script
async
src="https://cdn.jsdelivr.net/npm/[email protected].0/dist/lazyload.min.js"
src="https://cdn.jsdelivr.net/npm/[email protected].1/dist/lazyload.min.js"
></script>
```
Expand Down
124 changes: 62 additions & 62 deletions dist/lazyload.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ define(function () { 'use strict';
callback_finish: null,
use_native: false
};
var getInstanceSettings = (function (customSettings) {
var getInstanceSettings = function getInstanceSettings(customSettings) {
return _extends({}, defaultSettings, customSettings);
});
};

/* Creates instance and notifies it through the window element */
var createInstance = function createInstance(classObj, options) {
Expand Down Expand Up @@ -77,7 +77,7 @@ define(function () { 'use strict';
options passed in (plain object or an array) */


function autoInitialize (classObj, options) {
var autoInitialize = function autoInitialize(classObj, options) {
if (!options) {
return;
}
Expand All @@ -91,7 +91,7 @@ define(function () { 'use strict';
createInstance(classObj, optionsItem);
}
}
}
};

var dataPrefix = "data-";
var processedDataName = "was-processed";
Expand Down Expand Up @@ -137,32 +137,6 @@ define(function () { 'use strict';
});
};

var safeCallback = function safeCallback(callback, arg1, arg2, arg3) {
if (!callback) {
return;
}

if (arg3 !== undefined) {
callback(arg1, arg2, arg3);
return;
}

if (arg2 !== undefined) {
callback(arg1, arg2);
return;
}

callback(arg1);
};

var updateLoadingCount = function updateLoadingCount(instance, plusMinus) {
instance.loadingCount += plusMinus;

if (instance._elements.length === 0 && instance.loadingCount === 0) {
safeCallback(instance._settings.callback_finish, instance);
}
};

var getSourceTags = function getSourceTags(parentTag) {
var sourceTags = [];

Expand Down Expand Up @@ -234,7 +208,7 @@ define(function () { 'use strict';

if (setSourcesFunction) {
setSourcesFunction(element, settings);
updateLoadingCount(instance, 1);
instance.loadingCount += 1;
instance._elements = purgeOneElement(instance._elements, element);
return;
}
Expand All @@ -259,6 +233,24 @@ define(function () { 'use strict';
element.className = element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), " ").replace(/^\s+/, "").replace(/\s+$/, "");
};

var safeCallback = function safeCallback(callback, arg1, arg2, arg3) {
if (!callback) {
return;
}

if (arg3 !== undefined) {
callback(arg1, arg2, arg3);
return;
}

if (arg2 !== undefined) {
callback(arg1, arg2);
return;
}

callback(arg1);
};

var genericLoadEventName = "load";
var mediaLoadEventName = "loadeddata";
var errorEventName = "error";
Expand Down Expand Up @@ -291,7 +283,11 @@ define(function () { 'use strict';
removeClass(element, settings.class_loading);
addClass(element, className);
safeCallback(callback, element, instance);
updateLoadingCount(instance, -1);
instance.loadingCount -= 1;

if (instance._elements.length === 0 && instance.loadingCount === 0) {
safeCallback(settings.callback_finish, instance);
}
};

var addOneShotEventListeners = function addOneShotEventListeners(element, instance) {
Expand All @@ -309,17 +305,6 @@ define(function () { 'use strict';
};

var managedTags = ["IMG", "IFRAME", "VIDEO"];
var onEnter = function onEnter(element, entry, instance) {
var settings = instance._settings;
safeCallback(settings.callback_enter, element, entry, instance);

if (!settings.load_delay) {
revealAndUnobserve(element, instance);
return;
}

delayLoad(element, instance);
};
var revealAndUnobserve = function revealAndUnobserve(element, instance) {
var observer = instance._observer;
revealElement(element, instance);
Expand All @@ -328,16 +313,23 @@ define(function () { 'use strict';
observer.unobserve(element);
}
};
var onExit = function onExit(element, entry, instance) {
var revealElement = function revealElement(element, instance, force) {
var settings = instance._settings;
safeCallback(settings.callback_exit, element, entry, instance);

if (!settings.load_delay) {
return;
if (!force && getWasProcessedData(element)) {
return; // element has already been processed and force wasn't true
}

cancelDelayLoad(element);
if (managedTags.indexOf(element.tagName) > -1) {
addOneShotEventListeners(element, instance);
addClass(element, settings.class_loading);
}

setSources(element, instance);
setWasProcessedData(element);
safeCallback(settings.callback_reveal, element, instance);
};

var cancelDelayLoad = function cancelDelayLoad(element) {
var timeoutId = getTimeoutData(element);

Expand All @@ -362,32 +354,40 @@ define(function () { 'use strict';
}, loadDelay);
setTimeoutData(element, timeoutId);
};
var revealElement = function revealElement(element, instance, force) {

var onEnter = function onEnter(element, entry, instance) {
var settings = instance._settings;
safeCallback(settings.callback_enter, element, entry, instance);

if (!force && getWasProcessedData(element)) {
return; // element has already been processed and force wasn't true
if (!settings.load_delay) {
revealAndUnobserve(element, instance);
return;
}

if (managedTags.indexOf(element.tagName) > -1) {
addOneShotEventListeners(element, instance);
addClass(element, settings.class_loading);
delayLoad(element, instance);
};
var onExit = function onExit(element, entry, instance) {
var settings = instance._settings;
safeCallback(settings.callback_exit, element, entry, instance);

if (!settings.load_delay) {
return;
}

setSources(element, instance);
setWasProcessedData(element);
safeCallback(settings.callback_reveal, element, instance);
cancelDelayLoad(element);
};

var isIntersecting = function isIntersecting(entry) {
return entry.isIntersecting || entry.intersectionRatio > 0;
};

var getObserverSettings = function getObserverSettings(settings) {
return {
root: settings.container === document ? null : settings.container,
rootMargin: settings.thresholds || settings.threshold + "px"
};
};

var setObserver = function setObserver(instance) {
if (!supportsIntersectionObserver) {
return false;
Expand Down Expand Up @@ -416,21 +416,21 @@ define(function () { 'use strict';
});
};

var nodeSetToArray = function nodeSetToArray(nodeSet) {
return Array.prototype.slice.call(nodeSet);
};

var queryElements = function queryElements(settings) {
return settings.container.querySelectorAll(settings.elements_selector);
};

var nodeSetToArray = function nodeSetToArray(nodeSet) {
return Array.prototype.slice.call(nodeSet);
};
var getElements = function getElements(elements, settings) {
return purgeProcessedElements(nodeSetToArray(elements || queryElements(settings)));
};

var retryLazyLoad = function retryLazyLoad(instance) {
var settings = instance._settings;
var errorElements = settings.container.querySelectorAll("." + settings.class_error);
errorElements.forEach(function (element) {
nodeSetToArray(errorElements).forEach(function (element) {
removeClass(element, settings.class_error);
resetWasProcessedData(element);
});
Expand Down
2 changes: 1 addition & 1 deletion dist/lazyload.amd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f1e008d

Please sign in to comment.