1 line
1.6 KiB
JavaScript
1 line
1.6 KiB
JavaScript
!function(a,b){"function"==typeof define&&define.amd?define(function(){return b(a)}):"object"==typeof exports?module.exports=b:a.progressively=b(a)}(this,function(a){"use strict";function b(a,b){var c={};for(var d in a)c[d]=b.hasOwnProperty(d)?b[d]:a[d];return c}function c(a){return null===a.offsetParent}function d(a,b){if(c(a))return!1;var d=a.getBoundingClientRect();return d.top>=0&&d.left>=0&&d.right<=(window.innerWidth||document.el.clientWidth)&&d.bottom<=(window.innerHeight||document.el.clientHeight)||a.clientHeight>=window.innerHeight}function e(a){setTimeout(function(){var b=new Image;b.onload=function(){a.classList.remove("progressive--not-loaded"),a.classList.add("progressive--is-loaded"),a.src=this.src,i(a)},b.src=a.dataset.progressive},g.delay)}function f(){h||(clearTimeout(h),h=setTimeout(function(){k.check(),k.render(),h=null},g.throttle))}var g,h,i,j,k={};return i=function(){},g={throttle:300,delay:100,onLoadComplete:function(){},onLoad:function(){}},k.init=function(c){c=c||{},g=b(g,c),i=g.onLoad||i,j=[].slice.call(document.querySelectorAll(".progressive__img")),k.render(),document.addEventListener?(a.addEventListener("scroll",f,!1),a.addEventListener("load",f,!1)):(a.attachEvent("onscroll",f),a.attachEvent("onload",f))},k.render=function(){for(var a,b=j.length-1;b>=0;--b)a=j[b],d(a)&&a.classList.contains("progressive--not-loaded")&&(e(a),j.splice(b,1));this.check()},k.check=function(){j.length||(g.onLoadComplete(),this.drop())},k.drop=function(){document.removeEventListener?a.removeEventListener("scroll",f):a.detachEvent("onscroll",f),clearTimeout(h)},k}); |