forked from tubalmartin/riloadr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathriloadr.min.js
2 lines (2 loc) · 6.44 KB
/
riloadr.min.js
1
2
/*! Riloadr.js 1.5.1 (c) 2014 Tubal Martin - MIT license */
!function(a){"function"==typeof define&&define.amd?define(a):window.Riloadr=a()}(function(){"use strict";function rb(a){function db(){kb=xb(),W=sb(j,kb,I),Z=W[D]&&ub(j,W[D]),bb=bb||F&&tb(j),cb=G&&vb(W,bb)}function eb(){var b,a=0;if((N||F)&&Ob(_,u,Q),N&&(Ob(_,r,O),jb&&(qb=_[P],Ob(_,X,R)),A))for(;b=A[a];)Ob(ab[S](b),r,O),a++}function fb(){var b,a=0;if(!F&&(Pb(_,u,Q),N)){if(Pb(_,r,O),A)for(;b=A[a];)Pb(ab[S](b),r,O),a++;jb&&Pb(_,X,R)}}function gb(a,b){a[y]=0,a[D]=g,a[v]=hb,a[w]=a[x]=lb,a[c]=yb(a,f,W),T.splice(b,1)}function hb(){var d,e,b=this;"naturalWidth"in b?e=b.naturalWidth+b.naturalHeight:(d=new Image,d[c]=b[c],e=d[n]+d[p],d=i),+e>0&&(b[v]=b[w]=b[x]=i,b[C]&&(b[E]=b[E].replace(m,"$1$2")),N&&(b.style.visibility="visible"),v in a&&a[v][k](b),mb())}function lb(){var g,b=this,e=function(a){var d=new Image;d[v]=function(){b[c]=d[c],hb[k](b)},d[w]=b[x]=function(){lb[k](b)},d[c]=a};b[v]=b[w]=b[x]=i,w in a&&a[w][k](b),b[y]<K?(b[y]++,g=yb(b,f,b[D]?Z:W,d),e(g)):D in W&&!b[D]?(b[y]=0,b[D]=d,g=yb(b,f,Z),e(g)):mb()}function mb(){U--,0===U&&(fb(),J in a&&a[J]())}var W,Y,bb,cb,b=this,f=a.base||o,j=a.breakpoints||Nb('"breakpoints" not defined.'),l=a.name||"responsive",m=new RegExp("(^|\\s)"+l+"(\\s|$)"),s=a.defer&&("string"==typeof a.defer?{mode:a.defer,threshold:a.foldDistance,overflownElemsIds:[]}:a.defer),t=s&&s.mode.toLowerCase(),z=s&&s.threshold||100,A=s&&s.overflownElemsIds,B=a.watchViewportWidth,F=!!B,G="wider"==B,H="*"==B,I=a.ignoreLowBandwidth||g,K=a[y]||0,L=a.root||i,N=("invisible"==t||"belowfold"==t)&&!ob,O=Jb(function(){b[M]()},h),Q=Kb(function(){F&&db(),b[M](F)},h),R=Kb(function(){_[P]!==qb&&(qb=_[P],b[M]())},h),T=[],U=0,Z={};b[M]=function(a){Mb(function(b,c,e){if(!T[q]||a===d){for(a&&eb(),b=ib&&L[V]("img."+l)||L.getElementsByTagName("img"),e=0;c=b[e];)c&&!c[C]&&(ib||c[E].indexOf(l)>=0)&&((!F||F&&(a===d||!Y||G&&wb(W,Y)||H&&!vb(W,Y)))&&(T.push(c),U++),(!F||cb)&&(c[C]=d)),e++;F&&(cb&&(F=g),Y=W)}if(T[q])for(e=0;c=T[e];)c&&(!N||N&&zb(c,z))&&(gb(c,e),e--),e++;b=c=i})},pb(function(){$=ab[e],L=ab[S](L)||$,db(),eb(),!t||N?b[M]():Qb(b[M])})}function sb(a,b,c){for(var g,h,i,j,d=b,e=0,f={};g=a[e];)h=g[z],i=g[A],j=g[Y],b>0?(h&&i&&b>=h&&i>=b||h&&!i&&b>=h||i&&!h&&i>=b)&&(!j||j&&mb>=j&&(c||!c&&!nb))&&(f=g):(0>=d||d>h||d>i)&&(d=h||i||d,f=g),e++;return f}function tb(a){for(var d,b=0,c={};d=a[b];)wb(d,c)&&(c=d),b++;return c}function ub(a,b){for(var d,c=0;d=a[c];){if(d.name==b)return d;c++}}function vb(a,b){return a.name===b.name&&a[z]===b[z]&&a[A]===b[A]&&a[Y]===b[Y]&&a[F]===b[F]}function wb(a,b){var c=+a[Y]||1,d=+b[Y]||1;return a=Math.max(+a[z]||0,+a[A]||0)*(mb>=c?c:1),b=Math.max(+b[z]||0,+b[A]||0)*(mb>=d?d:1),a>b}function xb(){for(var e,a=Math,b=[_.innerWidth,bb.clientWidth,bb.offsetWidth,$.clientWidth],c=b[q],d=0;c>d;d++)isNaN(b[d])&&(b.splice(d,1),d--);return b[q]&&(e=a.max[l](a,b),isNaN(lb)||(e=a.min(lb,e))),e||lb||0}function yb(a,b,c,d){var e=(a.getAttribute("data-base")||b)+(a.getAttribute("data-src")||a.getAttribute("data-src-"+c.name)||o);return c[F]&&(e=e.split("."),e.pop(),e=e.join(".")+"."+c[F]),d&&(e+=(gb.test(e)?"&":"?")+"riloadrts="+(new Date).getTime()),e.replace(hb,c.name)}function nb(){var a=_.navigator,b=a.connection||a.mozConnection||a.webkitConnection||a.oConnection||a.msConnection||{},c=b.type||"unknown",d=+b.bandwidth||1/0;return d>0&&.1>d||/^[23]g|3|4$/.test(c+o)}function zb(a,b){return!(Ab(a,b)||Bb(a,b)||Cb(a,b)||Db(a,b))}function Ab(a,c){return Gb(p,_)+Fb(b,_)<=Eb(b,a)-c}function Bb(a,c){return Fb(b,_)>=Eb(b,a)+c+Gb(p,a)}function Cb(a,b){return Gb(n,_)+Fb(f,_)<=Eb(f,a)-b}function Db(a,b){return Fb(f,_)>=Eb(f,a)+b+Gb(n,a)}function Eb(a,c){var g,h,d={top:0,left:0},e=c&&c.ownerDocument;if(e)return typeof c[Z]!==H&&(d=c[Z]()),g=Ib(e),h={top:d[b]+(g[N]||bb[I])-(bb.clientTop||0),left:d[f]+(g[O]||bb[L])-(bb.clientLeft||0)},h[a]}function Fb(a,b){var c={top:{method:I,prop:N},left:{method:L,prop:O}},d=c[a].method,e=c[a].prop,f=Ib(b);return f?e in f?f[e]:bb[d]:b[d]}function Gb(a,b){var e,f,c={height:"Height",width:"Width"};return a=c[a],Hb(b)?bb[t+a]:(e=b[s+a],a=a.toLowerCase(),(0>=e||e==i)&&(_.getComputedStyle?f=_.getComputedStyle(b,i):bb.currentStyle&&(f=b.currentStyle),f&&(e=f[a]),(0>e||e==i)&&(e=b.style[a])),parseFloat(e)||0)}function Hb(a){return a!=i&&a==a.window}function Ib(a){return Hb(a)?a:9===a.nodeType?a.defaultView||a.parentWindow:g}function Jb(a,b){function h(){g=new Date,f=i,a[l](e,c)}var c,d,e,f,g=0;return function(){var i=new Date,j=b-(i-g);return c=arguments,e=this,0>=j?(g=i,d=a[l](e,c)):f||(f=Lb(h,j)),d}}function Kb(a,b,c){function h(){g=i,c||a[l](f,d)}var d,e,f,g;return function(){var i=c&&!g;return d=arguments,f=this,clearTimeout(g),g=Lb(h,b),i&&(e=a[l](f,d)),e}}function Lb(a,b){var c=Array[G].slice[k](arguments,2);return _.setTimeout(function(){return a[l](i,c)},b)}function Mb(a){return Lb[l](i,[a,1].concat(Array[G].slice[k](arguments,1)))}function Nb(a){throw new Error("Riloadr: "+a)}function Ob(a,b,c){a[eb](db+b,c,g)}function Pb(a,b,c){a[fb](db+b,c,g)}function Qb(a){if(ab[K]===B)Mb(a);else{var b=function(){Pb(_,j,b),Mb(a)};Ob(_,j,b)}}var $,kb,pb,qb,a="on",b="top",c="src",d=!0,e="body",f="left",g=!1,h=250,i=null,j="load",k="call",l="apply",m="error",n="width",o="",p="height",q="length",r="scroll",s="offset",t="client",u="resize",v=a+j,w=a+m,x=a+"abort",y="retries",z="minWidth",A="maxWidth",B="complete",C="riloaded",D="fallback",E="className",F="imgFormat",G="prototype",H="undefined",I=r+"Top",J=a+B,K="readyState",L=r+"Left",M=j+"Images",N="pageYOffset",O="pageXOffset",P="orientation",Q="attachEvent",R="EventListener",S="getElementById",T="documentElement",U="readystatechange",V="querySelectorAll",W="add"+R,X=P+"change",Y="minDevicePixelRatio",Z="getBoundingClientRect",_=window,ab=_.document,bb=ab[T],cb=W in ab,db=cb?o:a,eb=cb?W:Q,fb=cb?"remove"+R:"detachEvent",gb=/\?/,hb=/{breakpoint-name}/gi,ib=V in ab,jb=P in _&&a+X in _,lb=_.screen[n],mb=_.devicePixelRatio||1,nb=nb(),ob="[object OperaMini]"===Object[G].toString[k](_.operamini);return bb[E]=bb[E].replace(/(^|\s)no-js(\s|$)/,"$1$2"),rb.version="1.5.1",rb[G].riload=function(){this[M](d)},pb=function(){function h(a){if(!c){if(!ab[e])return Mb(h);for(c=d;a=f.shift();)Mb(a)}}function k(a){(cb||a.type===j||ab[K]===B)&&(l(),h())}function l(){Pb(ab,cb?a:U,k),Pb(_,j,k)}var a="DOMContentLoaded",b=g,c=g,f=[];if(ab[K]===B)Mb(h);else{if(cb)Ob(ab,a,k);else{Ob(ab,U,k);try{b=_.frameElement==i&&docElem}catch(m){}b&&b.doScroll&&function n(){if(!c){try{b.doScroll("left")}catch(a){return Lb(n,50)}l(),h()}}()}Ob(_,j,k)}return function(a){c?Mb(a):f.push(a)}}(),rb});