vanilla-lazyload
Advanced tools
Comparing version 10.3.5 to 10.4.1
@@ -56,6 +56,4 @@ import {setSources, setSourcesForPicture} from "../src/lazyLoad.setSources"; | ||
test("...with initial values in src and srcset and empty data-*", () => { | ||
img.dataset = { | ||
"src": "", | ||
"srcset": "" | ||
}; | ||
img.setAttribute("data-src", ""); | ||
img.setAttribute("data-srcset", ""); | ||
img.setAttribute("src", img200); | ||
@@ -62,0 +60,0 @@ img.setAttribute("srcset", img400); |
@@ -5,2 +5,14 @@ # CHANGELOG | ||
#### 10.4.1 | ||
Updated `dist` folder. | ||
#### 10.4.0 | ||
Added the `callback_enter` callback, which is called whenevery any element managed by LazyLoad enters the viewport, as requested in #159. Thanks to @alvarotrigo. | ||
#### 10.3.6 | ||
Fixed tests to match dataset revert made in 10.3 and 8.2 (oopsy). | ||
#### 10.3.5 | ||
@@ -62,2 +74,6 @@ | ||
#### 8.5.2 | ||
Fixed a bug that could occur on older versions of IE when trying to access an image's parent node. | ||
#### 8.5.1 | ||
@@ -64,0 +80,0 @@ |
@@ -18,3 +18,4 @@ (function (global, factory) { | ||
callback_error: null, | ||
callback_set: null | ||
callback_set: null, | ||
callback_enter: null | ||
}; | ||
@@ -164,2 +165,3 @@ | ||
var revealElement = function (element, settings) { | ||
callCallback(settings.callback_enter, element); | ||
if (["IMG", "IFRAME"].indexOf(element.tagName) > -1) { | ||
@@ -166,0 +168,0 @@ addOneShotListeners(element, settings); |
@@ -21,3 +21,4 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
callback_error: null, | ||
callback_set: null | ||
callback_set: null, | ||
callback_enter: null | ||
}; | ||
@@ -169,2 +170,3 @@ | ||
var revealElement = function revealElement(element, settings) { | ||
callCallback(settings.callback_enter, element); | ||
if (["IMG", "IFRAME"].indexOf(element.tagName) > -1) { | ||
@@ -171,0 +173,0 @@ addOneShotListeners(element, settings); |
@@ -1,1 +0,1 @@ | ||
var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(e,t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.LazyLoad=t()}(this,function(){"use strict";var e={elements_selector:"img",container:document,threshold:300,data_src:"src",data_srcset:"srcset",class_loading:"loading",class_loaded:"loaded",class_error:"error",callback_load:null,callback_error:null,callback_set:null},t=function(e,t){return e.getAttribute("data-"+t)},n=function(e,t,n){return e.setAttribute("data-"+t,n)},r=function(e){return e.filter(function(e){return!t(e,"was-processed")})},s=function(e,t){var n,r=new e(t);try{n=new CustomEvent("LazyLoad::Initialized",{detail:{instance:r}})}catch(e){(n=document.createEvent("CustomEvent")).initCustomEvent("LazyLoad::Initialized",!1,!1,{instance:r})}window.dispatchEvent(n)},o=function(e,n){var r=n.data_srcset,s=e.parentNode;if("PICTURE"===s.tagName)for(var o,a=0;o=s.children[a];a+=1)if("SOURCE"===o.tagName){var i=t(o,r);i&&o.setAttribute("srcset",i)}},a=function(e,n){var r=n.data_src,s=n.data_srcset,a=e.tagName,i=t(e,r);if("IMG"===a){o(e,n);var c=t(e,s);return c&&e.setAttribute("srcset",c),void(i&&e.setAttribute("src",i))}"IFRAME"!==a?i&&(e.style.backgroundImage='url("'+i+'")'):i&&e.setAttribute("src",i)},i="classList"in document.createElement("p"),c=function(e,t){i?e.classList.add(t):e.className+=(e.className?" ":"")+t},l=function(e,t){i?e.classList.remove(t):e.className=e.className.replace(new RegExp("(^|\\s+)"+t+"(\\s+|$)")," ").replace(/^\s+/,"").replace(/\s+$/,"")},u=function(e,t){e&&e(t)},d=function(e,t,n){e.removeEventListener("load",t),e.removeEventListener("error",n)},f=function(e,t){var n=function n(s){v(s,!0,t),d(e,n,r)},r=function r(s){v(s,!1,t),d(e,n,r)};e.addEventListener("load",n),e.addEventListener("error",r)},v=function(e,t,n){var r=e.target;l(r,n.class_loading),c(r,t?n.class_loaded:n.class_error),u(t?n.callback_load:n.callback_error,r)},_=function(e,t){["IMG","IFRAME"].indexOf(e.tagName)>-1&&(f(e,t),c(e,t.class_loading)),a(e,t),n(e,"was-processed",!0),u(t.callback_set,e)},m=function(t,n){this._settings=_extends({},e,t),this._setObserver(),this.update(n)};m.prototype={_setObserver:function(){var e=this;if("IntersectionObserver"in window){var t=this._settings;this._observer=new IntersectionObserver(function(n){n.forEach(function(n){if(n.intersectionRatio>0){var r=n.target;_(r,t),e._observer.unobserve(r)}}),e._elements=r(e._elements)},{root:t.container===document?null:t.container,rootMargin:t.threshold+"px"})}},update:function(e){var t=this,n=this._settings,s=e||n.container.querySelectorAll(n.elements_selector);this._elements=r(Array.prototype.slice.call(s)),this._observer?this._elements.forEach(function(e){t._observer.observe(e)}):(this._elements.forEach(function(e){_(e,n)}),this._elements=r(this._elements))},destroy:function(){var e=this;this._observer&&(r(this._elements).forEach(function(t){e._observer.unobserve(t)}),this._observer=null),this._elements=null,this._settings=null}};var b=window.lazyLoadOptions;return b&&function(e,t){if(t.length)for(var n,r=0;n=t[r];r+=1)s(e,n);else s(e,t)}(m,b),m}); | ||
var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(e,t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.LazyLoad=t()}(this,function(){"use strict";var e={elements_selector:"img",container:document,threshold:300,data_src:"src",data_srcset:"srcset",class_loading:"loading",class_loaded:"loaded",class_error:"error",callback_load:null,callback_error:null,callback_set:null,callback_enter:null},t=function(e,t){return e.getAttribute("data-"+t)},n=function(e,t,n){return e.setAttribute("data-"+t,n)},r=function(e){return e.filter(function(e){return!t(e,"was-processed")})},s=function(e,t){var n,r=new e(t);try{n=new CustomEvent("LazyLoad::Initialized",{detail:{instance:r}})}catch(e){(n=document.createEvent("CustomEvent")).initCustomEvent("LazyLoad::Initialized",!1,!1,{instance:r})}window.dispatchEvent(n)},o=function(e,n){var r=n.data_srcset,s=e.parentNode;if("PICTURE"===s.tagName)for(var o,a=0;o=s.children[a];a+=1)if("SOURCE"===o.tagName){var i=t(o,r);i&&o.setAttribute("srcset",i)}},a=function(e,n){var r=n.data_src,s=n.data_srcset,a=e.tagName,i=t(e,r);if("IMG"===a){o(e,n);var c=t(e,s);return c&&e.setAttribute("srcset",c),void(i&&e.setAttribute("src",i))}"IFRAME"!==a?i&&(e.style.backgroundImage='url("'+i+'")'):i&&e.setAttribute("src",i)},i="classList"in document.createElement("p"),c=function(e,t){i?e.classList.add(t):e.className+=(e.className?" ":"")+t},l=function(e,t){i?e.classList.remove(t):e.className=e.className.replace(new RegExp("(^|\\s+)"+t+"(\\s+|$)")," ").replace(/^\s+/,"").replace(/\s+$/,"")},u=function(e,t){e&&e(t)},d=function(e,t,n){e.removeEventListener("load",t),e.removeEventListener("error",n)},f=function(e,t){var n=function n(s){_(s,!0,t),d(e,n,r)},r=function r(s){_(s,!1,t),d(e,n,r)};e.addEventListener("load",n),e.addEventListener("error",r)},_=function(e,t,n){var r=e.target;l(r,n.class_loading),c(r,t?n.class_loaded:n.class_error),u(t?n.callback_load:n.callback_error,r)},v=function(e,t){u(t.callback_enter,e),["IMG","IFRAME"].indexOf(e.tagName)>-1&&(f(e,t),c(e,t.class_loading)),a(e,t),n(e,"was-processed",!0),u(t.callback_set,e)},m=function(t,n){this._settings=_extends({},e,t),this._setObserver(),this.update(n)};m.prototype={_setObserver:function(){var e=this;if("IntersectionObserver"in window){var t=this._settings;this._observer=new IntersectionObserver(function(n){n.forEach(function(n){if(n.intersectionRatio>0){var r=n.target;v(r,t),e._observer.unobserve(r)}}),e._elements=r(e._elements)},{root:t.container===document?null:t.container,rootMargin:t.threshold+"px"})}},update:function(e){var t=this,n=this._settings,s=e||n.container.querySelectorAll(n.elements_selector);this._elements=r(Array.prototype.slice.call(s)),this._observer?this._elements.forEach(function(e){t._observer.observe(e)}):(this._elements.forEach(function(e){v(e,n)}),this._elements=r(this._elements))},destroy:function(){var e=this;this._observer&&(r(this._elements).forEach(function(t){e._observer.unobserve(t)}),this._observer=null),this._elements=null,this._settings=null}};var b=window.lazyLoadOptions;return b&&function(e,t){if(t.length)for(var n,r=0;n=t[r];r+=1)s(e,n);else s(e,t)}(m,b),m}); |
var gulp = require("gulp"); | ||
var uglify = require("gulp-uglify"); | ||
var eslint = require("gulp-eslint"); | ||
var rollup = require("gulp-rollup"); | ||
var rename = require("gulp-rename"); | ||
var babel = require("gulp-babel"); | ||
var rollup = require("gulp-rollup"); | ||
var uglify = require("gulp-uglify"); | ||
var destFolder = "./dist"; | ||
@@ -27,3 +28,3 @@ | ||
.pipe(rename("lazyload.js")) | ||
.pipe(gulp.dest(destFolder)) // --> writing babelized | ||
.pipe(gulp.dest(destFolder)) // --> writing babelized ES5 | ||
// ----------- minifying -------------- | ||
@@ -30,0 +31,0 @@ .pipe(uglify()) |
{ | ||
"name": "vanilla-lazyload", | ||
"version": "10.3.5", | ||
"version": "10.4.1", | ||
"description": "A fast, lightweight script to load images as they enter the viewport. SEO friendly, it supports responsive images (both srcset + sizes and picture) and progressive JPEG", | ||
@@ -9,3 +9,2 @@ "main": "dist/lazyload.min.js", | ||
"babel-plugin-transform-object-assign": "^6.22.0", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
@@ -12,0 +11,0 @@ "gulp": "^3.9.1", |
@@ -17,3 +17,3 @@ LazyLoad is a fast, lightweight and flexible script that _speeds up your web application_ by **loading images only as they enter the viewport**. LazyLoad is written in plain (vanilla) Javascript featuring the [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API), it supports [responsive images](https://alistapart.com/article/responsive-images-in-practice), it's SEO friendly and it has some other [notable features](#notable-features). | ||
```html | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/vanilla-lazyload/8.5.0/lazyload.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/vanilla-lazyload/8.5.2/lazyload.min.js"></script> | ||
``` | ||
@@ -26,3 +26,3 @@ | ||
```html | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/vanilla-lazyload/10.3.3/lazyload.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/vanilla-lazyload/10.3.5/lazyload.min.js"></script> | ||
``` | ||
@@ -39,5 +39,5 @@ | ||
var s = d.createElement("script"); s.async = true; | ||
var v = !("IntersectionObserver" in w) ? "8.5.0" : "10.3.3"; | ||
var v = !("IntersectionObserver" in w) ? "8.5.2" : "10.3.5"; | ||
s.src = "https://cdnjs.cloudflare.com/ajax/libs/vanilla-lazyload/" + v + "/lazyload.min.js"; | ||
w.lazyLoadOptions = {}; // Your options here. See "recipes" for more information aboyt async. | ||
w.lazyLoadOptions = {}; // Your options here. See "recipes" for more information about async. | ||
b.appendChild(s); | ||
@@ -52,8 +52,12 @@ }(window, document)); | ||
If you prefer to install LazyLoad locally in your project, you can either: | ||
- [download it from the `dist` folder](https://github.com/verlok/lazyload/tree/master/dist) | ||
- **download it** from the [`dist` folder](https://github.com/verlok/lazyload/tree/master/dist) | ||
The file you typically want to use is `lazyload.min.js` | ||
If you prefer the ES2015 version, use `lazyload.es2015.js` | ||
- install it with `npm install --save vanilla-lazyload` | ||
- install it with `bower install vanilla-lazyload` | ||
- **install it with npm** | ||
Recommended version `npm install vanilla-lazyload@8.2.0` | ||
Latest version `npm install vanilla-lazyload` | ||
- **install it with bower** | ||
Recommended version `bower install vanilla-lazyload#8.2.0` | ||
Latest version `bower install vanilla-lazyload` | ||
### Async script | ||
@@ -60,0 +64,0 @@ |
@@ -12,3 +12,4 @@ export default { | ||
callback_error: null, | ||
callback_set: null | ||
callback_set: null, | ||
callback_enter: null | ||
}; |
@@ -40,2 +40,3 @@ import {setSources} from "./lazyload.setSources"; | ||
export default function (element, settings) { | ||
callCallback(settings.callback_enter, element); | ||
if (["IMG", "IFRAME"].indexOf(element.tagName) > -1) { | ||
@@ -42,0 +43,0 @@ addOneShotListeners(element, settings); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
893846
10
973
524