Comparing version 1.5.7-alpha1 to 1.5.7-alpha2
/*! | ||
* DLL.js v1.5.7-alpha1 (https://thednp.github.io/dll.js/) | ||
* DLL.js v1.5.7-alpha2 (https://thednp.github.io/dll.js/) | ||
* Copyright 2021 © thednp | ||
@@ -12,8 +12,8 @@ * Licensed under MIT (https://github.com/thednp/dll.js/blob/master/LICENSE) | ||
function loadMedia(mediaElement, imageCallback) { | ||
var isVideo = mediaElement.tagName === 'SOURCE'; | ||
var loadEvent = isVideo ? 'loadstart' : 'load'; | ||
var newVideo = isVideo ? document.createElement('VIDEO') : 0; | ||
var mediaObject = isVideo ? document.createElement('SOURCE') : new Image(); | ||
var loadTarget = isVideo ? newVideo : mediaObject; | ||
var src = mediaElement.getAttribute('data-src'); | ||
const isVideo = mediaElement.tagName === 'SOURCE'; | ||
const loadEvent = isVideo ? 'loadstart' : 'load'; | ||
const newVideo = isVideo ? document.createElement('VIDEO') : 0; | ||
const mediaObject = isVideo ? document.createElement('SOURCE') : new Image(); | ||
const loadTarget = isVideo ? newVideo : mediaObject; | ||
const src = mediaElement.getAttribute('data-src'); | ||
@@ -27,10 +27,10 @@ loadTarget.addEventListener(loadEvent, function loadWrapper() { | ||
} else { // background-image | ||
mediaElement.style.backgroundImage = "url(\"" + src + "\")"; | ||
mediaElement.style.backgroundImage = `url("${src}")`; | ||
} | ||
mediaElement.removeAttribute('data-src'); | ||
if (imageCallback) { imageCallback(); } | ||
if (imageCallback) imageCallback(); | ||
loadTarget.removeEventListener(loadEvent, loadWrapper); | ||
}); | ||
mediaObject.src = src; | ||
if (newVideo) { newVideo.appendChild(mediaObject); } | ||
if (newVideo) newVideo.appendChild(mediaObject); | ||
} | ||
@@ -40,6 +40,6 @@ | ||
function getMediaElements(source) { // we get images of a given object or itself | ||
var queue; | ||
var mediaItems = []; | ||
var matchedSelectors = source.querySelectorAll('[data-src]'); | ||
var elementSRC = source ? source.getAttribute('data-src') : null; // element has own data-src attribute | ||
let queue; | ||
const mediaItems = []; | ||
const matchedSelectors = source.querySelectorAll('[data-src]'); | ||
const elementSRC = source ? source.getAttribute('data-src') : null; // element has own data-src attribute | ||
@@ -57,3 +57,3 @@ if (elementSRC && !matchedSelectors) { | ||
Array.from(queue).forEach(function (x) { return mediaItems.push(x); }); | ||
Array.from(queue).forEach((x) => mediaItems.push(x)); | ||
return mediaItems; | ||
@@ -66,12 +66,12 @@ } | ||
// element | ||
var element = queryElement(elem); | ||
const element = queryElement(elem); | ||
// callback | ||
var callbackFn = typeof callback === 'function' ? callback : null; | ||
const callbackFn = typeof callback === 'function' ? callback : null; | ||
var mediaTargets = getMediaElements(element); | ||
var elementSRC = element ? element.getAttribute('data-src') : null; | ||
const mediaTargets = getMediaElements(element); | ||
const elementSRC = element ? element.getAttribute('data-src') : null; | ||
if (elementSRC || element.querySelector('[data-src]') !== null) { | ||
mediaTargets.forEach(function (x, i) { | ||
mediaTargets.forEach((x, i) => { | ||
if (i === mediaTargets.length - 1 && callbackFn) { | ||
@@ -88,8 +88,8 @@ loadMedia(x, callbackFn); | ||
function initComponent(context) { | ||
var lookup = context instanceof Element ? context : document; | ||
var DLLImages = Array.from(lookup.querySelectorAll('[data-src]')); | ||
DLLImages.map(function (x) { return new DLL(x); }); | ||
const lookup = context instanceof Element ? context : document; | ||
const DLLImages = Array.from(lookup.querySelectorAll('[data-src]')); | ||
DLLImages.map((x) => new DLL(x)); | ||
} | ||
// initialize when loaded | ||
if (document.body) { initComponent(); } | ||
if (document.body) initComponent(); | ||
else { | ||
@@ -96,0 +96,0 @@ document.addEventListener('DOMContentLoaded', function initWrapper() { |
@@ -1,2 +0,2 @@ | ||
// DLL.js v1.5.7-alpha1 | 2021 © thednp | MIT-License | ||
function e(e,t){var n="SOURCE"===e.tagName,r=n?"loadstart":"load",a=n?document.createElement("VIDEO"):0,o=n?document.createElement("SOURCE"):new Image,c=n?a:o,u=e.getAttribute("data-src");c.addEventListener(r,(function n(){"IMG"===e.tagName?e.src=u:"SOURCE"===e.tagName?(e.src=u,e.parentNode.load()):e.style.backgroundImage='url("'+u+'")',e.removeAttribute("data-src"),t&&t(),c.removeEventListener(r,n)})),o.src=u,a&&a.appendChild(o)}function t(t,n){var r,a,o,c=(r=t,o=a&&a instanceof Element?a:document,r instanceof Element?r:o.querySelector(r)),u="function"==typeof n?n:null,d=function(e){var t,n=[],r=e.querySelectorAll("[data-src]"),a=e?e.getAttribute("data-src"):null;return a&&!r?t=[e]:!a&&r?t=r:a&&r?(t=r,n.unshift(e)):a||r||(t=document.querySelectorAll("[data-src]")),Array.from(t).forEach((function(e){return n.push(e)})),n}(c);((c?c.getAttribute("data-src"):null)||null!==c.querySelector("[data-src]"))&&d.forEach((function(t,n){n===d.length-1&&u?e(t,u):e(t)}))}function n(e){var n=e instanceof Element?e:document;Array.from(n.querySelectorAll("[data-src]")).map((function(e){return new t(e)}))}document.body?n():document.addEventListener("DOMContentLoaded",(function e(){n(),document.removeEventListener("DOMContentLoaded",e)}));export default t; | ||
// DLL.js v1.5.7-alpha2 | 2021 © thednp | MIT-License | ||
function e(e,t){const n="SOURCE"===e.tagName,r=n?"loadstart":"load",a=n?document.createElement("VIDEO"):0,o=n?document.createElement("SOURCE"):new Image,c=n?a:o,u=e.getAttribute("data-src");c.addEventListener(r,(function n(){"IMG"===e.tagName?e.src=u:"SOURCE"===e.tagName?(e.src=u,e.parentNode.load()):e.style.backgroundImage=`url("${u}")`,e.removeAttribute("data-src"),t&&t(),c.removeEventListener(r,n)})),o.src=u,a&&a.appendChild(o)}function t(t,n){const r=(a=t,c=o&&o instanceof Element?o:document,a instanceof Element?a:c.querySelector(a));var a,o,c;const u="function"==typeof n?n:null,d=function(e){let t;const n=[],r=e.querySelectorAll("[data-src]"),a=e?e.getAttribute("data-src"):null;return a&&!r?t=[e]:!a&&r?t=r:a&&r?(t=r,n.unshift(e)):a||r||(t=document.querySelectorAll("[data-src]")),Array.from(t).forEach(e=>n.push(e)),n}(r);((r?r.getAttribute("data-src"):null)||null!==r.querySelector("[data-src]"))&&d.forEach((t,n)=>{n===d.length-1&&u?e(t,u):e(t)})}function n(e){const n=e instanceof Element?e:document;Array.from(n.querySelectorAll("[data-src]")).map(e=>new t(e))}document.body?n():document.addEventListener("DOMContentLoaded",(function e(){n(),document.removeEventListener("DOMContentLoaded",e)}));export default t; |
/*! | ||
* DLL.js v1.5.7-alpha1 (https://thednp.github.io/dll.js/) | ||
* DLL.js v1.5.7-alpha2 (https://thednp.github.io/dll.js/) | ||
* Copyright 2021 © thednp | ||
@@ -18,8 +18,8 @@ * Licensed under MIT (https://github.com/thednp/dll.js/blob/master/LICENSE) | ||
function loadMedia(mediaElement, imageCallback) { | ||
var isVideo = mediaElement.tagName === 'SOURCE'; | ||
var loadEvent = isVideo ? 'loadstart' : 'load'; | ||
var newVideo = isVideo ? document.createElement('VIDEO') : 0; | ||
var mediaObject = isVideo ? document.createElement('SOURCE') : new Image(); | ||
var loadTarget = isVideo ? newVideo : mediaObject; | ||
var src = mediaElement.getAttribute('data-src'); | ||
const isVideo = mediaElement.tagName === 'SOURCE'; | ||
const loadEvent = isVideo ? 'loadstart' : 'load'; | ||
const newVideo = isVideo ? document.createElement('VIDEO') : 0; | ||
const mediaObject = isVideo ? document.createElement('SOURCE') : new Image(); | ||
const loadTarget = isVideo ? newVideo : mediaObject; | ||
const src = mediaElement.getAttribute('data-src'); | ||
@@ -33,10 +33,10 @@ loadTarget.addEventListener(loadEvent, function loadWrapper() { | ||
} else { // background-image | ||
mediaElement.style.backgroundImage = "url(\"" + src + "\")"; | ||
mediaElement.style.backgroundImage = `url("${src}")`; | ||
} | ||
mediaElement.removeAttribute('data-src'); | ||
if (imageCallback) { imageCallback(); } | ||
if (imageCallback) imageCallback(); | ||
loadTarget.removeEventListener(loadEvent, loadWrapper); | ||
}); | ||
mediaObject.src = src; | ||
if (newVideo) { newVideo.appendChild(mediaObject); } | ||
if (newVideo) newVideo.appendChild(mediaObject); | ||
} | ||
@@ -46,6 +46,6 @@ | ||
function getMediaElements(source) { // we get images of a given object or itself | ||
var queue; | ||
var mediaItems = []; | ||
var matchedSelectors = source.querySelectorAll('[data-src]'); | ||
var elementSRC = source ? source.getAttribute('data-src') : null; // element has own data-src attribute | ||
let queue; | ||
const mediaItems = []; | ||
const matchedSelectors = source.querySelectorAll('[data-src]'); | ||
const elementSRC = source ? source.getAttribute('data-src') : null; // element has own data-src attribute | ||
@@ -63,3 +63,3 @@ if (elementSRC && !matchedSelectors) { | ||
Array.from(queue).forEach(function (x) { return mediaItems.push(x); }); | ||
Array.from(queue).forEach((x) => mediaItems.push(x)); | ||
return mediaItems; | ||
@@ -72,12 +72,12 @@ } | ||
// element | ||
var element = queryElement(elem); | ||
const element = queryElement(elem); | ||
// callback | ||
var callbackFn = typeof callback === 'function' ? callback : null; | ||
const callbackFn = typeof callback === 'function' ? callback : null; | ||
var mediaTargets = getMediaElements(element); | ||
var elementSRC = element ? element.getAttribute('data-src') : null; | ||
const mediaTargets = getMediaElements(element); | ||
const elementSRC = element ? element.getAttribute('data-src') : null; | ||
if (elementSRC || element.querySelector('[data-src]') !== null) { | ||
mediaTargets.forEach(function (x, i) { | ||
mediaTargets.forEach((x, i) => { | ||
if (i === mediaTargets.length - 1 && callbackFn) { | ||
@@ -94,8 +94,8 @@ loadMedia(x, callbackFn); | ||
function initComponent(context) { | ||
var lookup = context instanceof Element ? context : document; | ||
var DLLImages = Array.from(lookup.querySelectorAll('[data-src]')); | ||
DLLImages.map(function (x) { return new DLL(x); }); | ||
const lookup = context instanceof Element ? context : document; | ||
const DLLImages = Array.from(lookup.querySelectorAll('[data-src]')); | ||
DLLImages.map((x) => new DLL(x)); | ||
} | ||
// initialize when loaded | ||
if (document.body) { initComponent(); } | ||
if (document.body) initComponent(); | ||
else { | ||
@@ -102,0 +102,0 @@ document.addEventListener('DOMContentLoaded', function initWrapper() { |
@@ -1,2 +0,2 @@ | ||
// DLL.js v1.5.7-alpha1 | 2021 © thednp | MIT-License | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).dll=t()}(this,(function(){"use strict";function e(e,t){var n="SOURCE"===e.tagName,r=n?"loadstart":"load",o=n?document.createElement("VIDEO"):0,a=n?document.createElement("SOURCE"):new Image,c=n?o:a,u=e.getAttribute("data-src");c.addEventListener(r,(function n(){"IMG"===e.tagName?e.src=u:"SOURCE"===e.tagName?(e.src=u,e.parentNode.load()):e.style.backgroundImage='url("'+u+'")',e.removeAttribute("data-src"),t&&t(),c.removeEventListener(r,n)})),a.src=u,o&&o.appendChild(a)}function t(t,n){var r,o,a,c=(r=t,a=o&&o instanceof Element?o:document,r instanceof Element?r:a.querySelector(r)),u="function"==typeof n?n:null,d=function(e){var t,n=[],r=e.querySelectorAll("[data-src]"),o=e?e.getAttribute("data-src"):null;return o&&!r?t=[e]:!o&&r?t=r:o&&r?(t=r,n.unshift(e)):o||r||(t=document.querySelectorAll("[data-src]")),Array.from(t).forEach((function(e){return n.push(e)})),n}(c);((c?c.getAttribute("data-src"):null)||null!==c.querySelector("[data-src]"))&&d.forEach((function(t,n){n===d.length-1&&u?e(t,u):e(t)}))}function n(e){var n=e instanceof Element?e:document;Array.from(n.querySelectorAll("[data-src]")).map((function(e){return new t(e)}))}return document.body?n():document.addEventListener("DOMContentLoaded",(function e(){n(),document.removeEventListener("DOMContentLoaded",e)})),t})); | ||
// DLL.js v1.5.7-alpha2 | 2021 © thednp | MIT-License | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).dll=t()}(this,(function(){"use strict";function e(e,t){const n="SOURCE"===e.tagName,o=n?"loadstart":"load",r=n?document.createElement("VIDEO"):0,c=n?document.createElement("SOURCE"):new Image,a=n?r:c,d=e.getAttribute("data-src");a.addEventListener(o,(function n(){"IMG"===e.tagName?e.src=d:"SOURCE"===e.tagName?(e.src=d,e.parentNode.load()):e.style.backgroundImage=`url("${d}")`,e.removeAttribute("data-src"),t&&t(),a.removeEventListener(o,n)})),c.src=d,r&&r.appendChild(c)}function t(t,n){const o=(r=t,a=c&&c instanceof Element?c:document,r instanceof Element?r:a.querySelector(r));var r,c,a;const d="function"==typeof n?n:null,u=function(e){let t;const n=[],o=e.querySelectorAll("[data-src]"),r=e?e.getAttribute("data-src"):null;return r&&!o?t=[e]:!r&&o?t=o:r&&o?(t=o,n.unshift(e)):r||o||(t=document.querySelectorAll("[data-src]")),Array.from(t).forEach(e=>n.push(e)),n}(o);((o?o.getAttribute("data-src"):null)||null!==o.querySelector("[data-src]"))&&u.forEach((t,n)=>{n===u.length-1&&d?e(t,d):e(t)})}function n(e){const n=e instanceof Element?e:document;Array.from(n.querySelectorAll("[data-src]")).map(e=>new t(e))}return document.body?n():document.addEventListener("DOMContentLoaded",(function e(){n(),document.removeEventListener("DOMContentLoaded",e)})),t})); |
{ | ||
"name": "dll.js", | ||
"version": "1.5.7-alpha1", | ||
"version": "1.5.7-alpha2", | ||
"description": "Double Lazy Load for Images, Videos and Background Images.", | ||
@@ -20,3 +20,5 @@ "main": "dist/dll.min.js", | ||
"build-umd": "rollup --environment FORMAT:umd,MIN:false -c", | ||
"build-umd-min": "rollup --environment FORMAT:umd,MIN:true -c" | ||
"build-umd-min": "rollup --environment FORMAT:umd,MIN:true -c", | ||
"build-es5-umd": "rollup --environment FORMAT:umd,MIN:false,ES:es5 -c", | ||
"build-es5-umd-min": "rollup --environment FORMAT:umd,MIN:true,ES:es5 -c" | ||
}, | ||
@@ -23,0 +25,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23347
14
369
0