wonderdome-site/assets/scripts/2-lazy-progressive-enhancem...

9 lines
1.3 KiB
JavaScript
Executable File

/* @license
lazy-progressive-enhancement.js
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++){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)}}