@area17/a17-lazyload
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -24,1 +24,9 @@ # A17 Lazy Load Change Log | ||
* Moving repo and demo page to Github | ||
## 0.1.5 | ||
* Updates to readme | ||
## 0.1.6 | ||
* Adds namespace to config for custom attribute naming. Namespace is inserted after `data-` to the following attributes: `data-src`, `data-srcset`, `data-lazyload`, `data-lazyloaded` |
(function () { | ||
var options = { | ||
namespace: '', // add custom name to attributes ie: data-'namespace'-src | ||
pageUpdatedEventName: 'page:updated', // how your app tells the rest of the app an update happened | ||
@@ -53,5 +54,5 @@ elements: 'img[data-src], img[data-srcset], source[data-srcset], iframe[data-src], video[data-src], [data-lazyload]', // maybe you just want images? | ||
function _removeDataAttrs(el) { | ||
el.removeAttribute('data-src'); | ||
el.removeAttribute('data-srcset'); | ||
el.removeAttribute('data-lazyload'); | ||
el.removeAttribute(`data-${ options.namespace ? options.namespace + '-' : '' }src`); | ||
el.removeAttribute(`data-${ options.namespace ? options.namespace + '-' : '' }srcset`); | ||
el.removeAttribute(`data-${ options.namespace ? options.namespace + '-' : '' }lazyload`); | ||
} | ||
@@ -74,5 +75,5 @@ | ||
function _updateEl(el) { | ||
var srcset = el.getAttribute('data-srcset'); | ||
var src = el.getAttribute('data-src'); | ||
var dlazyload = el.getAttribute('data-lazyload') !== null; | ||
var srcset = el.getAttribute(`data-${ options.namespace ? options.namespace + '-' : '' }srcset`); | ||
var src = el.getAttribute(`data-${ options.namespace ? options.namespace + '-' : '' }src`); | ||
var dlazyload = el.getAttribute(`data-${ options.namespace ? options.namespace + '-' : '' }lazyload`) !== null; | ||
// | ||
@@ -93,3 +94,3 @@ if (srcset) { | ||
if (dlazyload) { | ||
el.setAttribute('data-lazyloaded',''); | ||
el.setAttribute(`data-${ options.namespace ? options.namespace + '-' : '' }lazyloaded`,''); | ||
el.removeEventListener('load', _loaded); | ||
@@ -96,0 +97,0 @@ _removeDataAttrs(el); |
@@ -1,1 +0,1 @@ | ||
!function(){var e,t,n,a,o,r={pageUpdatedEventName:"page:updated",elements:"img[data-src], img[data-srcset], source[data-srcset], iframe[data-src], video[data-src], [data-lazyload]",rootMargin:"0px",threshold:0,maxFrameCount:10,forceAutoplayVideoPlay:!0},d=[];function i(e){e.removeAttribute("data-src"),e.removeAttribute("data-srcset"),e.removeAttribute("data-lazyload")}function l(){this.removeEventListener("load",l),i(this)}function c(e){var t=e.getAttribute("data-srcset"),n=e.getAttribute("data-src"),a=null!==e.getAttribute("data-lazyload");if(t&&(e.setAttribute("srcset",t),window.picturefill&&window.picturefill({elements:[e]})),n&&(e.src=n),a&&(e.setAttribute("data-lazyloaded",""),e.removeEventListener("load",l),i(e)),e.autoplay&&e.paused)try{e.load(),e.paused&&r.forceAutoplayVideoPlay&&(e.outerHTML=e.outerHTML)}catch(o){}}function s(e){0===n&&a.disconnect();for(var t=0;t<e.length;t++){var o=e[t];o.intersectionRatio>0&&(n--,a.unobserve(o.target),o.target.addEventListener("load",l,!1),c(o.target))}}function u(){var m,v,f;if("really-old"===o){for(n=d.length,m=0;m<n;m++)d[m]&&(c(d[m]),i(d[m]));d=[]}else if("old"===o){if(t===r.maxFrameCount){for(n=d.length,m=0;m<n;m++)if(d[m]&&void 0===d[m].lazyloaded&&(v=d[m],f=void 0,(f=(v="SOURCE"===v.tagName?v.parentNode:v).getBoundingClientRect()).bottom>0&&f.right>0&&f.left<(window.innerWidth||document.documentElement.clientWidth)&&f.top<(window.innerHeight||document.documentElement.clientHeight))){var g=d[m];d[m]=void 0,g.lazyloaded=!0,g.addEventListener("load",l,!1),c(g)}for(m=0;m<n;m++)void 0===d[m]&&d.splice(m,1);n=d.length,t=-1}n>0&&(t++,e=window.requestAnimationFrame(u))}else if("new"===o)for(a=new IntersectionObserver(s,{rootMargin:r.rootMargin,threshold:r.threshold}),n=d.length,m=0;m<n;m++)d[m]&&void 0===d[m].lazyloaded&&a.observe(d[m])}function m(){if("old"===o)try{cancelAnimationFrame(e)}catch(i){}else if("new"===o)try{a.disconnect()}catch(i){}d=function(e){var t=[],n=0;for(t=[],n=e.length;n;)t[--n]=e[n];return t}(document.querySelectorAll(r.elements)),n=d.length,t=r.maxFrameCount,u()}var v=function(e){for(var t in e)e.hasOwnProperty(t)&&(r[t]=e[t]);o="addEventListener"in window&&window.requestAnimationFrame&&void 0!==typeof document.body.getBoundingClientRect?"IntersectionObserver"in window?"new":"old":"really-old",m(),r.pageUpdatedEventName&&document.addEventListener(r.pageUpdatedEventName,m,!0)};"undefined"!=typeof exports?module.exports=v:window.lazyload=v}(); | ||
!function(){var e,t,a,n,o,r={namespace:"",pageUpdatedEventName:"page:updated",elements:"img[data-src], img[data-srcset], source[data-srcset], iframe[data-src], video[data-src], [data-lazyload]",rootMargin:"0px",threshold:0,maxFrameCount:10,forceAutoplayVideoPlay:!0},d=[];function i(e){e.removeAttribute(`data-${r.namespace?r.namespace+"-":""}src`),e.removeAttribute(`data-${r.namespace?r.namespace+"-":""}srcset`),e.removeAttribute(`data-${r.namespace?r.namespace+"-":""}lazyload`)}function l(){this.removeEventListener("load",l),i(this)}function c(e){var t=e.getAttribute(`data-${r.namespace?r.namespace+"-":""}srcset`),a=e.getAttribute(`data-${r.namespace?r.namespace+"-":""}src`),n=null!==e.getAttribute(`data-${r.namespace?r.namespace+"-":""}lazyload`);if(t&&(e.setAttribute("srcset",t),window.picturefill&&window.picturefill({elements:[e]})),a&&(e.src=a),n&&(e.setAttribute(`data-${r.namespace?r.namespace+"-":""}lazyloaded`,""),e.removeEventListener("load",l),i(e)),e.autoplay&&e.paused)try{e.load(),e.paused&&r.forceAutoplayVideoPlay&&(e.outerHTML=e.outerHTML)}catch(o){}}function s(e){0===a&&n.disconnect();for(var t=0;t<e.length;t++){var o=e[t];o.intersectionRatio>0&&(a--,n.unobserve(o.target),o.target.addEventListener("load",l,!1),c(o.target))}}function m(){var u,p,v;if("really-old"===o){for(a=d.length,u=0;u<a;u++)d[u]&&(c(d[u]),i(d[u]));d=[]}else if("old"===o){if(t===r.maxFrameCount){for(a=d.length,u=0;u<a;u++)if(d[u]&&void 0===d[u].lazyloaded&&(p=d[u],v=void 0,(v=(p="SOURCE"===p.tagName?p.parentNode:p).getBoundingClientRect()).bottom>0&&v.right>0&&v.left<(window.innerWidth||document.documentElement.clientWidth)&&v.top<(window.innerHeight||document.documentElement.clientHeight))){var f=d[u];d[u]=void 0,f.lazyloaded=!0,f.addEventListener("load",l,!1),c(f)}for(u=0;u<a;u++)void 0===d[u]&&d.splice(u,1);a=d.length,t=-1}a>0&&(t++,e=window.requestAnimationFrame(m))}else if("new"===o)for(n=new IntersectionObserver(s,{rootMargin:r.rootMargin,threshold:r.threshold}),a=d.length,u=0;u<a;u++)d[u]&&void 0===d[u].lazyloaded&&n.observe(d[u])}function u(){if("old"===o)try{cancelAnimationFrame(e)}catch(i){}else if("new"===o)try{n.disconnect()}catch(i){}d=function(e){var t=[],a=0;for(t=[],a=e.length;a;)t[--a]=e[a];return t}(document.querySelectorAll(r.elements)),a=d.length,t=r.maxFrameCount,m()}var p=function(e){for(var t in e)e.hasOwnProperty(t)&&(r[t]=e[t]);o="addEventListener"in window&&window.requestAnimationFrame&&void 0!==typeof document.body.getBoundingClientRect?"IntersectionObserver"in window?"new":"old":"really-old",u(),r.pageUpdatedEventName&&document.addEventListener(r.pageUpdatedEventName,u,!0)};"undefined"!=typeof exports?module.exports=p:window.lazyload=p}(); |
{ | ||
"name": "@area17/a17-lazyload", | ||
"description": "A simple, tiny, no dependency, lazy loader - by A17", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "main": "./dist/a17-lazyload.js", |
@@ -58,4 +58,4 @@ # A17 Lazy Load | ||
* ~7kb uncompressed | ||
* ~8kb uncompressed | ||
* ~3kb minified | ||
* ~1kb minified and gzipped |
Sorry, the diff of this file is not supported yet
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
109913
240