-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloading-attribute-polyfill-with-serviceworker.module.js
2 lines (2 loc) · 1.59 KB
/
loading-attribute-polyfill-with-serviceworker.module.js
1
2
const e="loading"in HTMLImageElement.prototype,t="loading"in HTMLIFrameElement.prototype;let o;function n(e){return e.replace(/(&|&)?(loading=lazy|image-width=\d*|image-height=\d*)/gi,"")}function a(e){let t=[e];"picture"===e.parentNode.tagName.toLowerCase()&&(t=Array.prototype.slice.call(e.parentNode.querySelectorAll("source"))),t.push(e);for(const e of t)e.hasAttribute("srcset")&&(e.srcset=n(e.srcset)),e.src=n(e.src),e.dataset.loadingLazy="loading"}function r(n){var r,i;if("img"===(null==(r=n.tagName)?void 0:r.toLowerCase())&&e||"iframe"===(null==(i=n.tagName)?void 0:i.toLowerCase())&&t)return!1;void 0===o?a(n):(n.dataset.loadingLazy="registered",o.observe(n))}window,window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),"IntersectionObserver"in window&&(o=new IntersectionObserver(function(e,t){for(const o of e){if(0===o.intersectionRatio)continue;const e=o.target;t.unobserve(e),a(e)}},{rootMargin:"0px 0px 256px 0px",threshold:.01}));const i=()=>{for(const e of document.querySelectorAll('img[loading="lazy"],iframe[loading="lazy"]'))r(e);void 0!==window.matchMedia&&window.matchMedia("print").addListener(e=>{if(e.matches)for(const e of document.querySelectorAll('img[loading="lazy"],iframe[loading="lazy"]'))a(e)})};/comp|inter/.test(document.readyState)?i():"addEventListener"in document?document.addEventListener("DOMContentLoaded",()=>{i()}):document.attachEvent("onreadystatechange",()=>{"complete"===document.readyState&&i()});const d={prepareElement:r};export{d as default};
//# sourceMappingURL=loading-attribute-polyfill-with-serviceworker.module.js.map