itsericwoodward-site-v2/src/assets/scripts/3-lazy-progressive-enhancem...

10 lines
1.4 KiB
JavaScript

// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT
/*
lazy-progressive-enhancement.js v1.0.0
https://github.com/tvler/lazy-progressive-enhancement
The MIT License (MIT)
Copyright (c) 2016 Tyler Deitz
*/
function loadMedia(t,e,n){"use strict";function r(t){if(t==null){t=document.querySelectorAll("noscript")}else if(t instanceof Element){t=[t]}else if(typeof t==="string"){t=document.querySelectorAll(t)}return t}function i(t,e){return window.setInterval(function(){var n=t.getBoundingClientRect(),r=150;if(n.bottom>= -r&&n.top-window.innerHeight<r&&n.right>= -r&&n.left-window.innerWidth<r){window.clearInterval(t.getAttribute("data-intervalid"));t.srcset=t.getAttribute("data-srcset");t.src=t.getAttribute("data-src");e&&e()}},100)}function a(t){var a,A,l="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";for(var d=0;d<(t=r(t)).length;d+=1){A=new DOMParser().parseFromString((a=t[d]).textContent,"text/html").body.firstElementChild;if(n){A.setAttribute("data-src",A.getAttribute("src"));A.setAttribute("data-srcset",A.getAttribute("srcset")||"");A.src=A.srcset=l;a.parentElement.replaceChild(A,a);A.setAttribute("data-intervalid",i(A,e&&e.bind(A)))}else{A.onload=e;a.parentElement.replaceChild(A,a)}}}var A=function(){a(t)};if(document.readyState!=="loading"){A()}else{document.addEventListener("DOMContentLoaded",A)}}
// @license-end