forked from dkern/jquery.lazy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.lazy.min.js
2 lines (2 loc) · 4.54 KB
/
jquery.lazy.min.js
1
2
/*! jQuery Lazy 1.7.1 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2016 Daniel 'Eisbehr' Kern */
!function(t,e){"use strict";function r(r,a,i,o,l){function u(){B=t.devicePixelRatio>1,c(i),a.delay>=0&&setTimeout(function(){f(!0)},a.delay),(a.delay<0||a.combined)&&(o.e=g(a.throttle,function(t){"resize"===t.type&&(z=w=-1),f(t.all)}),o.a=function(t){c(t),i.push.apply(i,t)},o.g=function(){return i=n(i).filter(function(){return!n(this).data(a.loadedName)})},f(),n(a.appendScroll).on("scroll."+l+" resize."+l,o.e))}function c(t){var i=a.defaultImage,o=a.placeholder,l=a.imageBase,u=a.srcsetAttribute,c=a.loaderAttribute,f=a._f||{};t=n(t).filter(function(){var t=n(this),r=h(this);return!t.data(a.handledName)&&(t.attr(a.attribute)||t.attr(u)||t.attr(c)||f[r]!=e)}).data("plugin_"+a.name,r);for(var s=0,d=t.length;d>s;s++){var A=n(t[s]),m=h(t[s]),g=A.attr(a.imageBaseAttribute)||l;m==I&&g&&A.attr(u)&&A.attr(u,b(A.attr(u),g)),f[m]==e||A.attr(c)||A.attr(c,f[m]),m==I&&i&&!A.attr(N)?A.attr(N,i):m==I||!o||A.css(C)&&"none"!=A.css(C)||A.css(C,"url('"+o+"')")}}function f(t){if(!i.length)return void(a.autoDestroy&&r.destroy());for(var e=!1,o=a.imageBase||"",l=a.srcsetAttribute,u=a.handledName,c=0,f=i.length;f>c;c++)(function(r){if(t||d(r)){var i=n(r),c=h(r),f=i.attr(a.attribute),A=i.attr(a.imageBaseAttribute)||o,m=i.attr(a.loaderAttribute);i.data(u)||a.visibleOnly&&!i.is(":visible")||!((f||i.attr(l))&&(c==I&&(A+f!=i.attr(N)||i.attr(l)!=i.attr(E))||c!=I&&A+f!=i.css(C))||m)||(e=!0,i.data(u,!0),s(i,c,A,m))}})(i[c]);e&&(i=n(i).filter(function(){return!n(this).data(u)}))}function s(t,e,r,i){++y;var o=function(){p("onError",t),v(),o=n.noop};p("beforeLoad",t);var l=a.attribute,u=a.srcsetAttribute,c=a.sizesAttribute,f=a.retinaAttribute,s=a.removeAttribute,d=a.loadedName,A=t.attr(f);if(i){var m=function(){s&&t.removeAttr(a.loaderAttribute),t.data(d,!0),p(L,t),setTimeout(v,1),m=n.noop};t.off(D).one(D,o).one(T,m),p(i,t,function(e){e?(t.off(T),m()):(t.off(D),o())})||t.error()}else{var h=n(new Image);h.one(D,o).one(T,function(){t.hide(),e==I?t.attr(F,h.attr(F)).attr(E,h.attr(E)).attr(N,h.attr(N)):t.css(C,"url('"+h.attr(N)+"')"),t[a.effect](a.effectTime),s&&(t.removeAttr(l+" "+u+" "+f+" "+a.imageBaseAttribute),c!==F&&t.removeAttr(c)),t.data(d,!0),p(L,t),h.remove(),v()});var b=(B&&A?A:t.attr(l))||"";h.attr(F,t.attr(c)).attr(E,t.attr(u)).attr(N,b?r+b:null),h.complete&&h.load()}}function d(t){var e=t.getBoundingClientRect(),r=a.scrollDirection,n=a.threshold,i=m()+n>e.top&&-n<e.bottom,o=A()+n>e.left&&-n<e.right;return"vertical"==r?i:"horizontal"==r?o:i&&o}function A(){return z>=0?z:z=n(t).width()}function m(){return w>=0?w:w=n(t).height()}function h(t){return t.tagName.toLowerCase()}function b(t,e){if(e){var r=t.split(",");t="";for(var a=0,n=r.length;n>a;a++)t+=e+r[a].trim()+(a!==n-1?",":"")}return t}function g(t,e){var n,i=0;return function(o,l){function u(){i=+new Date,e.call(r,o)}var c=+new Date-i;n&&clearTimeout(n),c>t||!a.enableThrottle||l?u():n=setTimeout(u,t-c)}}function v(){--y,i.length||y||p("onFinishedAll")}function p(t,e,n){return(t=a[t])?(t.apply(r,[].slice.call(arguments,1)),!0):!1}var y=0,z=-1,w=-1,B=!1,L="afterLoad",T="load",D="error",I="img",N="src",E="srcset",F="sizes",C="background-image";"event"==a.bind?u():n(t).on(T+"."+l,u)}function a(a,o){var l=this,u=n.extend({},l.config,o),c={},f=u.name+"-"+ ++i;return l.config=function(t,r){return r===e?u[t]:(u[t]=r,l)},l.addItems=function(t){return c.a&&c.a("string"===n.type(t)?n(t):t),l},l.getItems=function(){return c.g?c.g():{}},l.update=function(t){return c.e&&c.e({},!t),l},l.loadAll=function(){return c.e&&c.e({all:!0},!0),l},l.destroy=function(){return n(u.appendScroll).off("."+f,c.e),n(t).off("."+f),c={},e},r(l,u,a,c,f),u.chainable?a:l}var n=t.jQuery||t.Zepto,i=0;n.fn.Lazy=n.fn.lazy=function(t){return new a(this,t)},n.Lazy=n.lazy=function(t,r,i){if(n.isFunction(r)&&(i=r,r=[]),n.isFunction(i)){t=n.isArray(t)?t:[t],r=n.isArray(r)?r:[r];for(var o=a.prototype.config,l=o._f||(o._f={}),u=0,c=t.length;c>u;u++)(o[t[u]]===e||n.isFunction(o[t[u]]))&&(o[t[u]]=i);for(var f=0,s=r.length;s>f;f++)l[r[f]]=t[0]}},a.prototype.config={name:"lazy",chainable:!0,autoDestroy:!0,bind:"load",threshold:500,appendScroll:t,scrollDirection:"both",defaultImage:"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",delay:-1,attribute:"data-src",srcsetAttribute:"data-srcset",sizesAttribute:"data-sizes",retinaAttribute:"data-retina",loaderAttribute:"data-loader",imageBaseAttribute:"data-imagebase",removeAttribute:!0,handledName:"handled",loadedName:"loaded",effect:"show",effectTime:0,enableThrottle:!0,throttle:250}}(window);