forked from mfranzke/loading-attribute-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloading-attribute-polyfill.min.js
More file actions
executable file
·6 lines (6 loc) · 2.77 KB
/
Copy pathloading-attribute-polyfill.min.js
File metadata and controls
executable file
·6 lines (6 loc) · 2.77 KB
1
2
3
4
5
6
/*
* Loading attribute polyfill - https://github.com/mfranzke/loading-attribute-polyfill
* @license Copyright(c) 2019 by Maximilian Franzke
* Credits for the initial kickstarter / script to @Sora2455, and supported by @cbirdsong, @eklingen, @DaPo, @nextgenthemes, @diogoterremoto, @dracos and @Flimm - many thanks for that !
*/
!function(e,t){"use strict";var a,r,o={rootMargin:"256px 0px",threshold:.01,lazyImage:'img[loading="lazy"]',lazyIframe:'iframe[loading="lazy"]'},n={loading:"loading"in HTMLImageElement.prototype&&"loading"in HTMLIFrameElement.prototype,scrolling:"onscroll"in window};"undefined"!=typeof NodeList&&NodeList.prototype&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),"IntersectionObserver"in window&&(a=new IntersectionObserver((function(e,t){e.forEach((function(e){if(0!==e.intersectionRatio){var a=e.target;t.unobserve(a),d(a)}}))}),o)),r="requestAnimationFrame"in window?window.requestAnimationFrame:function(e){e()};var i="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";function d(e){var t,a,r=[];"picture"===e.parentNode.tagName.toLowerCase()&&(t=e.parentNode,(a=t.querySelector("source[data-lazy-remove]"))&&t.removeChild(a),r=Array.prototype.slice.call(e.parentNode.querySelectorAll("source"))),r.push(e),r.forEach((function(e){e.dataset.lazySrcset&&(e.setAttribute("srcset",e.dataset.lazySrcset),delete e.dataset.lazySrcset)})),e.setAttribute("src",e.dataset.lazySrc),delete e.dataset.lazySrc}function c(e){var t=document.createElement("div");for(t.innerHTML=function(e){var t=e.textContent||e.innerHTML;return!n.loading&&n.scrolling&&void 0!==document.documentElement.dataset&&(void 0===a?t=t.replace(/(?:\r\n|\r|\n|\t| )src=/g,' lazyload="1" src='):("picture"===e.parentNode.tagName.toLowerCase()&&(t='<source srcset="'+i+'" data-lazy-remove="true"></source>'+t),t=t.replace(/(?:\r\n|\r|\n|\t| )srcset=/g," data-lazy-srcset=").replace(/(?:\r\n|\r|\n|\t| )src=/g,' src="'+i+'" data-lazy-src='))),t}(e);t.firstChild;)n.loading||!n.scrolling||void 0===a||void 0===document.documentElement.dataset||!t.firstChild.tagName||"img"!==t.firstChild.tagName.toLowerCase()&&"iframe"!==t.firstChild.tagName.toLowerCase()||a.observe(t.firstChild),e.parentNode.insertBefore(t.firstChild,e);e.parentNode.removeChild(e)}function s(){document.querySelectorAll("noscript."+e).forEach(c),void 0!==window.matchMedia&&window.matchMedia("print").addListener((function(e){e.matches&&document.querySelectorAll(o.lazyImage+"[data-lazy-src],"+o.lazyIframe+"[data-lazy-src]").forEach((function(e){d(e)}))}))}/comp|inter/.test(document.readyState)?r(s):"addEventListener"in document?document.addEventListener("DOMContentLoaded",(function(){r(s)})):document.attachEvent("onreadystatechange",(function(){"complete"===document.readyState&&s()}))}("loading-lazy");