mirror of
https://github.com/Noettore/cocoa-eh-hugo-theme.git
synced 2025-10-15 11:46:41 +02:00
9 lines
2.5 KiB
JavaScript
9 lines
2.5 KiB
JavaScript
/*!
|
|
* progressively 1.1.5
|
|
* https://github.com/thinker3197/progressively
|
|
* @license MIT licensed
|
|
*
|
|
* Copyright (C) 2016 Ashish
|
|
*/
|
|
!function(e,t){"function"==typeof define&&define.amd?define(function(){return t(e)}):"object"==typeof exports?module.exports=t:e.progressively=t(e)}(this,function(e){"use strict";function t(e,t){var n={};for(var o in e)n[o]=t.hasOwnProperty(o)?t[o]:e[o];return n}function n(e){var t=e.getBoundingClientRect(),n=t.top,o=t.height;e=e.parentNode;do{if(t=e.getBoundingClientRect(),!(n<=t.bottom))return!1;if(n+o<=t.top)return!1;e=e.parentNode}while(e!==document.body&&e!==document);return n<=document.documentElement.clientHeight}function o(e,t){setTimeout(function(){var n=new Image;n.onload=function(){e.classList.remove("progressive--not-loaded"),e.classList.add("progressive--is-loaded"),e.classList.contains("progressive__bg")?e.style["background-image"]='url("'+this.src+'")':e.src=this.src,a(e)},s()<t.smBreakpoint&&e.getAttribute("data-progressive-sm")&&(e.classList.add("progressive--loaded-sm"),n.src=e.getAttribute("data-progressive-sm")),e.classList.remove("progressive--loaded-sm"),n.src=e.getAttribute("data-progressive")},t.delay)}function s(){return Math.max(document.documentElement.clientWidth,window.innerWidth||0)}function r(){c||(clearTimeout(c),c=setTimeout(function(){u.check(),u.render(),c=null},i.throttle))}var i,c,a,d,l,u={};return a=function(){},i={throttle:300,delay:100,onLoadComplete:function(){},onLoad:function(){},smBreakpoint:600},u.init=function(n){n=n||{},i=t(i,n),a=i.onLoad||a,d=[].slice.call(document.querySelectorAll(".progressive__img, .progressive__bg")),l=[],u.render(),document.addEventListener?(e.addEventListener("scroll",r,!1),e.addEventListener("resize",r,!1),e.addEventListener("load",r,!1)):(e.attachEvent("onscroll",r),e.attachEvent("onresize",r),e.attachEvent("onload",r))},u.render=function(){for(var e,t=d.length-1;t>=0;--t)e=d[t],n(e)&&(e.classList.contains("progressive--not-loaded")||e.classList.contains("progressive--loaded-sm"))&&(o(e,i),e.classList.contains("progressive--loaded-sm")&&l.push(e),d.splice(t,1));if(s()>=i.smBreakpoint)for(var r=l.length-1;r>=0;--r)e=l[r],n(e)&&(e.classList.contains("progressive--not-loaded")||e.classList.contains("progressive--loaded-sm"))&&(o(e,i),l.splice(t,1));this.check()},u.check=function(){d.length||l.length||(i.onLoadComplete(),this.drop())},u.drop=function(){document.removeEventListener?(e.removeEventListener("scroll",r),e.removeEventListener("resize",r)):(e.detachEvent("onscroll",r),e.detachEvent("onresize",r)),clearTimeout(c)},u});
|