-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
2 lines (2 loc) · 2.7 KB
/
index.js
1
2
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@djforth/utilities")):"function"==typeof define&&define.amd?define(["@djforth/utilities"],e):(t=t||self).LazyloadPolyfill=e(t.DJForthUtilities)}(this,function(b){"use strict";function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function m(a){for(var t=1;t<arguments.length;t++){var c=null!=arguments[t]?arguments[t]:{};t%2?e(Object(c),!0).forEach(function(t){var e,r,n;e=a,n=c[r=t],r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(c)):e(Object(c)).forEach(function(t){Object.defineProperty(a,t,Object.getOwnPropertyDescriptor(c,t))})}return a}function y(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function i(t,r){t.forEach(function(t){var e=function(t){return t.replace(/[A-Z]/g,function(t){return"-".concat(t.toLowerCase())})}(t);r.removeAttribute("data-".concat(e))})}function g(t,e,r){var n=t.src,a=t.srcset,c=r.dataset[n];r.setAttribute("src",c),r.setAttribute("loading","lazy"),function(t,e){if(e.hasAttribute("data-".concat(t))){var r=e.dataset[t];e.setAttribute("srcset",r)}}(a,r),i([n,a],r),e(r)}function v(t,e,r){!function(t,e){t.insertAdjacentHTML("beforeend",e)}(r,function(t){var e=t.src,r=t.alt;return'<img src="'.concat(e,'" alt="').concat(r,'" loading="lazy" />')}(function(t,e){var r=t.src,n=t.alt;return{alt:e.dataset[n],src:e.dataset[r]}}(t,r)));var n=t.src,a=t.alt;i([n,a],r),e(r)}function h(t,e){e.classList.remove(t)}var O={selector:"img.lozad, iframe.lozad, picture.lozad",imgData:{src:"src",srcset:"srcset"},removeClass:"lozad",picData:{src:"iesrc",alt:"alt"}};return function(t){var e=m({},O,{},t),r=e.selector,n=e.imgData,a=e.removeClass,c=e.picData,i=y(document.querySelectorAll(r));if(!b.checkElements.apply(void 0,y(i)))return null;var o=b.curry(h,a),s=b.curry(g,n,o),u=b.curry(v,c,o),f=function(t){return t.reduce(function(t,e){var r=t.iframes,n=t.images,a=t.pictures;switch(e.tagName){case"PICTURE":a.push(e);break;case"IFRAME":r.push(e);break;case"IMG":n.push(e)}return{iframes:r,images:n,pictures:a}},{iframes:[],images:[],pictures:[]})}(i),l=f.iframes,p=f.images,d=f.pictures;p.concat(l).forEach(s),d.forEach(u)}});
//# sourceMappingURL=index.js.map