-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto-lazyload-min.js
11 lines (11 loc) · 2.98 KB
/
auto-lazyload-min.js
1
2
3
4
5
6
7
8
9
10
11
/*!
* Auto Lazyload v3.1.1
* https://psxninja.github.io
*
* Copyright psxninja
* Released under the MIT license
* https://github.com/psxninja/auto-lazyload/blob/master/LICENSE
*
* Date: 2019-07-20T22:49Z
*/
!function(e){"use strict";var t=/<img.*?>/gi,a=/<iframe.*?>/gi,n=/src="(.*?)"/gi,o=["transitionend","animationend","webkitAnimationEnd","resize","scroll"],l=window.innerHeight||document.documentumentElement.clientHeight,r=window.innerWidth||document.documentumentElement.clientWidth,i=null,d=null,u=function(e,t){setTimeout(function(){e.className=e.className.replace("lazy-loading","lazy-loaded")},t>>>0),e.removeEventListener("onload",u)};window.autoLazyload={},window.autoLazyload.run=function(e){for(var t=document.querySelectorAll(".lazy-loading"),a=new IntersectionObserver(function(t,a){for(var n=0,o=t.length;n<o;n++)!1!==t[n].isIntersecting&&(t[n].target.dataset.bg&&(t[n].target.style.backgroundImage="url("+t[n].target.dataset.bg+")",u(t[n].target,e)),t[n].target.dataset.src&&(t[n].target.onload=u(t[n].target,e),t[n].target.src=t[n].target.dataset.src),a.unobserve(t[n].target))}),n=0,o=t.length;n<o;n++)a.observe(t[n]);a=t=void 0},window.autoLazyload.mount=function(e=null){var o=document.querySelectorAll(".has--lazyload");if(0!==o.length||null===d){d=window.setTimeout(function(){d=null},550);for(var l=0,r=o.length;l<r;l++){var i=document.createElement("div"),u=o[l].querySelector("noscript"),c=null;if(null!==u&&0!==u.textContent.length){u=u.textContent,t.test(u)&&(u=u.replace(t,function(e){return e.replace(n,'data-src="$1" src="data:image/gif;base64,R0lGODlhAQABAIAAAOvr6wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="')}),i.innerHTML=u,c=i.getElementsByTagName("img")),a.test(u)&&(u=u.replace(a,function(e){return e.replace(n,'data-src="$1" src="data:text/plain;charset=UTF-8,Carregando..."')}),i.innerHTML=u,c=i.getElementsByTagName("iframe"));for(var s=0,g=c.length;s<g;s++)c[s].className+=" lazy-loading";o[l].innerHTML=i.innerHTML,o[l].className=o[l].className.replace("has--lazyload",""),u=i=c=void 0}}}o=void 0,null!==e&&autoLazyload.run(e)},"IntersectionObserver"in window?(autoLazyload.mount(),document.addEventListener("DOMContentLoaded",function(){autoLazyload.run(0)},!0)):(window.autoLazyload.run=function(e){var t=document.querySelectorAll(".lazy-loading");if(0!==t.length){for(var a=0,n=t.length;a<n;a++)if(-1!==t[a].className.indexOf("lazy-loading")){var o=t[a].getBoundingClientRect();o.top>=0&&o.left>=0&&o.top<=l&&o.right<=r&&(t[a].dataset.bg&&(t[a].style.backgroundImage="url("+t[a].dataset.bg+")",u(t[a],e)),t[a].dataset.src&&(t[a].onload=u(t[a],e),t[a].src=t[a].dataset.src)),o=void 0}t=void 0}},autoLazyload.mount(),document.addEventListener("DOMContentLoaded",function(){autoLazyload.run(0);for(var e=0,t=o.length;e<t;e++)document.addEventListener(o[e],function(e){var t,a;void 0!==e.target.className&&(-1!==e.target.className.indexOf("has--lazyload")&&(autoLazyload.mount(),t=function(){autoLazyload.run()},null!==i&&clearTimeout(i),i=window.setTimeout(function(){t(),i=null},a||550)))},!0)},!0))}();