Commit 9883615b authored by aFarkas's avatar aFarkas
Browse files

documentation + compile

Showing with 65 additions and 16 deletions
+65 -16
......@@ -124,7 +124,6 @@ In case disabled javascript is a concern you can combine the simple pattern with
<img src="image.jpg" />
</noscript>
<img src="grey.jpg" data-src="image.jpg" class="lazyload" />
<!--<![endif]-->
```
###[data-expand] attribute
......
/*! lazysizes - v0.9.0 - 2015-02-02
/*! lazysizes - v0.9.0 - 2015-02-03
Licensed MIT */
!function(a,b){a.lazySizes=b(a,a.document),"function"==typeof define&&define.amd&&define(a.lazySizes)}(window,function(a,b){"use strict";if(b.getElementsByClassName){var c,d=b.documentElement,e=/^picture$/i,f=["load","error","lazyincluded","_lazyloaded"],g=function(a,b){var c=new RegExp("(\\s|^)"+b+"(\\s|$)");return a.className.match(c)&&c},h=function(a,b){g(a,b)||(a.className+=" "+b)},i=function(a,b){var c;(c=g(a,b))&&(a.className=a.className.replace(c," "))},j=function(a,b,c){var d=c?"addEventListener":"removeEventListener";c&&j(a,b),f.forEach(function(c){a[d](c,b)})},k=function(a,c,d){var e=b.createEvent("Event");return e.initEvent(c,!0,!0),e.details=d||{},a.dispatchEvent(e),e},l=function(b,c){var d;a.HTMLPictureElement||((d=a.picturefill||a.respimage)?d({reevaluate:!0,reparse:!0,elements:[b]}):c&&c.src&&(b.src=c.src))},m=function(a,b){return getComputedStyle(a,null)[b]},n=function(a,d){for(var e=a.offsetWidth;e<c.minSize&&d&&d!=b.body&&!a._lazysizesWidth;)e=d.offsetWidth,d=d.parentNode;return e},o=function(a){var c,d,e=function(){c&&(c=!1,a())},f=function(){clearInterval(d),b.hidden||(e(),d=setInterval(e,66))};return b.addEventListener("visibilitychange",f),f(),function(a){c=!0,a===!0&&e()}},p=function(){var f,n,p,r,s,t,u,v,w,x,y,z,A=navigator.userAgent,B=a.HTMLPictureElement&&A.match(/hrome\/(\d+)/)&&40==RegExp.$1,C=/webkit/i.test(A),D=/^img$/i,E=/^iframe$/i,F=-2,G=F,H=F,I=F,J=!0,K=0,L=0,M=0,N=function(a){L--,a&&a.target&&j(a.target,N),(!a||0>L||!a.target)&&(L=0)},O=function(a,c){var e,f=a,g="hidden"!=m(a,"visibility");for(w-=c,z+=c,x-=c,y+=c;g&&(f=f.offsetParent)&&f!=d&&f!=b.body;)g=r&&4>L||(m(f,"opacity")||1)>0,g&&"visible"!=m(f,"overflow")&&(e=f.getBoundingClientRect(),g=y>e.left-1&&x<e.right+1&&z>e.top-1&&w<e.bottom+1);return g},P=function(){var a,b,d,e,g,h,i,j=f.length,k=Date.now(),l=M;if(J||U(),j){for(;j>l&&f[l];l++,M++)if((h=f[l].getAttribute("data-expand"))&&(e=1*h)||(e=I),!(L>6&&(!h||"src"in f[l])))if(L>3&&e>F&&(e=F),i!==e&&(u=innerWidth+e,v=innerHeight+e,g=-1*e,i=e),a=f[l].getBoundingClientRect(),(z=a.bottom)>=g&&(w=a.top)<=v&&(y=a.right)>=g&&(x=a.left)<=u&&(z||y||x||w)&&(r&&I==G&&3>L&&4>K&&!h||O(f[l],e)))M--,k+=2,T(f[l]),d=!0;else{if(!t&&Date.now()-k>3)return M++,t=!0,void Q();!d&&r&&!b&&3>L&&4>K&&(n[0]||c.preloadAfterLoad)&&(n[0]||!h&&(z||y||x||w||"auto"!=f[l].getAttribute(c.sizesAttr)))&&(b=n[0]||f[l])}M=0,t=!1,K++,H>I&&2>L&&K>4?(I=H,K=0,Q()):I!=G&&(I=G),b&&!d&&T(b)}},Q=o(P),R=function(a){h(a.target,c.loadedClass),i(a.target,c.loadingClass),j(a.target,R)},S=function(a,b){try{a.contentWindow.location.replace(b)}catch(c){a.setAttribute("src",b)}},T=function(a,b){var d,f,m,n,o,p,t,u,v,w,x,y=a.currentSrc||a.src,z=D.test(a.nodeName),A=a.getAttribute(c.sizesAttr)||a.getAttribute("sizes"),F="auto"==A;if(!F&&(C||r)||!z||!y||a.complete||g(a,c.errorClass)){if(!(v=k(a,"lazybeforeunveil",{force:!!b})).defaultPrevented){if(A&&(F?q.updateElem(a,!0):a.setAttribute("sizes",A)),p=a.getAttribute(c.srcsetAttr),o=a.getAttribute(c.srcAttr),z&&(t=a.parentNode,u=e.test(t.nodeName||"")),w=v.details.firesLoad||"src"in a&&(p||o||u),w&&(L++,j(a,N,!0),clearTimeout(s),s=setTimeout(N,3e3)),u)for(d=t.getElementsByTagName("source"),f=0,m=d.length;m>f;f++)(x=c.customMedia[d[f].getAttribute("media")])&&d[f].setAttribute("media",x),n=d[f].getAttribute(c.srcsetAttr),n&&d[f].setAttribute("srcset",n);p?(a.setAttribute("srcset",p),B&&A&&a.removeAttribute("src")):o&&(E.test(a.nodeName)?S(a,o):a.setAttribute("src",o)),c.addClasses&&(h(a,c.loadingClass),j(a,R,!0))}setTimeout(function(){"auto"==A&&h(a,c.autosizesClass),(p||u)&&l(a,{srcset:p,src:o}),i(a,c.lazyClass),(!w||a.complete&&y==(a.currentSrc||a.src))&&(w&&N(v),c.addClasses&&R(v)),a=null})}},U=function(){p&&!J&&(G=Math.max(Math.min(c.expand||c.threshold||120,300),9),H=4*G),J=!0},V=function(){p=!0,J=!1},W=function(){r=!0,V(),Q(!0)},X=function(){f=b.getElementsByClassName(c.lazyClass),n=b.getElementsByClassName(c.lazyClass+" "+c.preloadClass),c.scroll&&addEventListener("scroll",Q,!0),addEventListener("resize",function(){J=!1,Q()}),a.MutationObserver?new MutationObserver(Q).observe(d,{childList:!0,subtree:!0,attributes:!0}):(d.addEventListener("DOMNodeInserted",Q,!0),d.addEventListener("DOMAttrModified",Q,!0)),addEventListener("hashchange",Q,!0),["transitionstart","transitionend","load","focus","mouseover","animationend","click"].forEach(function(a){b.addEventListener(a,Q,!0)}),(r=/d$|^c/.test(b.readyState))||(addEventListener("load",W),b.addEventListener("DOMContentLoaded",Q)),setTimeout(V,666),Q(!0),Q()};return{init:X,checkElems:Q,unveil:T}}(),q=function(){var a,d=function(a,b){var c,d,f,g,h,i=a.parentNode;if(i&&(c=n(a,i),h=k(a,"lazybeforesizes",{width:c,dataAttr:!!b}),!h.defaultPrevented&&(c=h.details.width,c&&c!==a._lazysizesWidth))){if(a._lazysizesWidth=c,c+="px",a.setAttribute("sizes",c),e.test(i.nodeName||""))for(d=i.getElementsByTagName("source"),f=0,g=d.length;g>f;f++)d[f].setAttribute("sizes",c);h.details.dataAttr||l(a,h.details)}},f=function(){var b,c=a.length;if(c)for(b=0;c>b;b++)d(a[b])},g=o(f),h=function(){a=b.getElementsByClassName(c.autosizesClass),addEventListener("resize",g)};return{init:h,checkElems:g,updateElem:d}}(),r=function(){r.i||(r.i=!0,q.init(),p.init())};return function(){var b,d={lazyClass:"lazyload",loadedClass:"lazyloaded",loadingClass:"lazyloading",preloadClass:"lazypreload",scroll:!0,autosizesClass:"lazyautosizes",srcAttr:"data-src",srcsetAttr:"data-srcset",sizesAttr:"data-sizes",addClasses:!0,minSize:50,customMedia:{},init:!0};c=a.lazySizesConfig||{};for(b in d)b in c||(c[b]=d[b]);a.lazySizesConfig=c,d.init&&setTimeout(r)}(),{cfg:c,autoSizer:q,loader:p,init:r,updateAllSizes:q.updateElems,updateAllLazy:p.checkElems,unveilLazy:p.unveil,uS:q.updateElem,uP:l,aC:h,rC:i,hC:g,fire:k,gW:n}}});
\ No newline at end of file
/*! lazysizes - v0.9.0 - 2015-02-02
/*! lazysizes - v0.9.0 - 2015-02-03
Licensed MIT */
!function(){"use strict";if(window.addEventListener){var a=/\s*\|\s+|\s+\|\s*/g,b=/^(.+?)(?:\s+\[\s*(.+?)\s*\])?$/,c=function(a){var b=lazySizes.gW(a,a.parentNode);return(!a._lazysizesWidth||b>a._lazysizesWidth)&&(a._lazysizesWidth=b),a._lazysizesWidth},d=function(c,d,e){var f=document.createElement("picture"),g=d.getAttribute(lazySizesConfig.sizesAttr);c=c.split(a),f.style.display="none",e.className=lazySizesConfig.lazyClass,1!=c.length||g||(g="auto"),c.forEach(function(a){var c=document.createElement("source");g&&"auto"!=g&&c.setAttribute("sizes",g),a.match(b)&&(c.setAttribute(lazySizesConfig.srcsetAttr,RegExp.$1),RegExp.$2&&c.setAttribute("media",RegExp.$2)),f.appendChild(c)}),g&&(e.setAttribute(lazySizesConfig.sizesAttr,g),"auto"==g&&Object.defineProperty(e,"_lazybgset",{value:d,writable:!0})),f.appendChild(e),d.appendChild(f),d.removeAttribute(lazySizesConfig.sizesAttr)};addEventListener("lazybeforeunveil",function(a){var b,c,e,f,g;!a.defaultPrevented&&(b=a.target.getAttribute("data-bgset"))&&(g=a.target,c=document.createElement("img"),e=function(b){var d="load"==b.type?c.currentSrc||c.src:!1;d&&(g.style.backgroundImage="url("+d+")"),f||(lazySizes.fire(g,"_lazyloaded"),a&&a.details&&(a.details.firesLoad=!1),f=!0,a=null)},a.details.firesLoad=!0,c.addEventListener("load",e),c.addEventListener("error",e),d(b,g,c),lazySizes.loader.unveil(c))}),addEventListener("lazybeforesizes",function(a){!a.defaultPrevented&&a.target._lazybgset&&(a.details.width=c(a.target._lazybgset))})}}();
\ No newline at end of file
/*! lazysizes - v0.9.0 - 2015-02-02
/*! lazysizes - v0.9.0 - 2015-02-03
Licensed MIT */
!function(a){"use strict";var b=document.documentElement,c=function(){a.lazySizes&&!lazySizes.getCustomMedias&&(lazySizes.getCustomMedias=function(){var a=/['"]/g,b=/\s*\|\s*/g,c=/^([a-z0-9_-]+)\s*:\s*(.+)$/i,d=function(b,c){return(getComputedStyle(b,c).getPropertyValue("content")||"none").replace(a,"").trim()},e=function(a,d){a.split(b).forEach(function(a){a.match(c)&&(d[RegExp.$1]=RegExp.$2)})};return function(a,b){return a=a||{},b=b||document.querySelector("html"),e(d(b,":before"),a),e(d(b,":after"),a),a}}(),lazySizes.getCustomMedias(lazySizes.cfg.customMedia),b.removeEventListener("lazybeforeunveil",c))};a.addEventListener&&b.addEventListener("lazybeforeunveil",c),c(),setTimeout(c)}(window);
\ No newline at end of file
/*! lazysizes - v0.9.0 - 2015-02-02
/*! lazysizes - v0.9.0 - 2015-02-03
Licensed MIT */
!function(a,b){"use strict";function c(a){a.match(z)?this.urls[RegExp.$1]=t.map[RegExp.$2]||RegExp.$2:this.urls.include=t.map[a]||a}function d(a){var b,d,e;return a=a.trim(),a=t.map[a]||a,d=a.match(A),d?(e=RegExp.$1,b={condition:s.include.conditions[RegExp.$3]||RegExp.$2||null,name:RegExp.$3}):(e=a,b={condition:null,name:""}),b.urls={},(t.map[e]||e).split(y).forEach(c,b),!b.urls.include&&b.urls.amd&&(this.saved=!0,b.initial=this),b}function e(a){var b,c,e=a.getAttribute("data-include")||"",f=a.lazyInclude;return f&&f.str==e||(c={saved:!1,content:null},f={str:e,candidates:(t.map[e]||e).split(w).map(d,c)},!(b=f.candidates.length)||f.candidates[b-1].condition?(c.saved=!0,f.candidates.push({urls:{},condition:null,name:"initial",content:c})):c.saved&&1==f.candidates.length&&(c.saved=!1),f.initialContent=c,c.saved&&(c.content=a.innerHTML),a.lazyInclude=f,f.candidates.length>1?lazySizes.aC(a,"lazyconditionalinclude"):lazySizes.rC(a,"lazyconditionalinclude")),f}function f(b,c){var d=!c.condition;return c.condition&&(g(),v[c.name]?d=!0:a.matchMedia&&"string"==typeof c.condition?d=(matchMedia(c.condition)||{}).matches:"function"==typeof c.condition&&(d=c.condition(b,c))),d}function g(){var a;v||(u||(u=b.querySelector(t.contentElement)),u?(a=(getComputedStyle(u,":after").getPropertyValue("content")||"none").replace(B,""),v={},a&&(v[a]=1),a=(getComputedStyle(u,":before").getPropertyValue("content")||"none").replace(B,""),a&&(v[a]=1)):v={})}function h(a){var b,c,d=a.lazyInclude;if(d&&d.candidates)for(b=0;b<d.candidates.length&&(c=d.candidates[b],!f(a,c));b++);return c&&c!=d.current||(c=null),c}function i(a,b){var c=new XMLHttpRequest;c.addEventListener("readystatechange",function(){var a=this.DONE||4;this.readyState===a&&(b(c),c=null)},!1),c.open.apply(c,a.openArgs),c.setRequestHeader("X-Requested-With","XMLHttpRequest"),a.xhrModifier&&a.xhrModifier(c,elem,candidate),c.send(a.sendData)}function j(a,b){a=a.split("|,|"),require(a,function(){b(Array.prototype.slice.call(arguments))})}function k(a){if(!x[a]){var c=b.createElement("link"),d=b.getElementsByTagName("script")[0];c.rel="stylesheet",c.href=a,d.parentNode.insertBefore(c,d),x[a]=!0,x[c.href]=!0}}function l(a){a=a.split("|,|"),a.forEach(k)}function m(a){a&&"function"==typeof a.lazytransform&&a.lazytransform(this)}function n(a){a&&"function"==typeof a.lazyunload&&a.lazyunload(this)}function o(a){a&&"function"==typeof a.lazyload&&a.lazyload(this)}function p(b,c){var d,e,f,g=b.lazyInclude.current||null,h={candidate:c,openArgs:["GET",c.urls.include,!0],sendData:null,xhrModifier:null,content:c.content&&c.content.content||c.content,oldCandidate:g},k=lazySizes.fire(b,"lazyincludeload",h);return k.defaultPrevented?void E.d():(d=function(){var d,h=e.status,i=e.content||e.responseText,j=!(null!=i||!g||!g.urls.include),k={candidate:c,content:i,text:e.responseText||e.content,response:e.response,xml:e.responseXML,isSuccess:"status"in e?h>=200&&300>h||304===h:!0,oldCandidate:g,insert:!0,resetHTML:j},l={target:b,details:k};c.modules=f,g&&g.modules&&(g.modules.forEach(n,l),g.modules=null,k.resetHTML&&null==k.content&&c.initial&&c.initial.saved&&(k.content=c.initial.content)),f.forEach(m,l),d=lazySizes.fire(b,"lazyincludeloaded",k),k.insert&&k.isSuccess&&!d.defaultPrevented&&null!=k.content&&k.content!=b.innerHTML&&(a.jQuery?jQuery(b).html(k.content):b.innerHTML=k.content),E.d(),f.forEach(o,l),setTimeout(function(){lazySizes.fire(b,"lazyincluded",k)}),e=null,f=null},b.lazyInclude.current=c,b.setAttribute("data-currentinclude",c.name),c.urls.css&&l(c.urls.css),null==h.content&&c.urls.include?i(h,function(a){e=a,f&&d()}):e=h,c.urls.amd?j(c.urls.amd,function(a){f=a,e&&d()}):f=[],void(e&&f&&d()))}function q(a){var b,c=e(a);return c.candidates.length&&C.contains(a)?(b=h(a),b&&p(a,b),!0):void 0}function r(a){!a.defaultPrevented&&a.target.getAttribute("data-include")&&(E.q(a.target),a.details.firesLoad=!0)}if(b.getElementsByClassName){var s,t,u,v,w=/\s*,+\s+/,x={},y=/\s+/,z=/^(amd|css)\:(.+)/i,A=/(.+)\s+(\(\s*(.+)\s*\))/,B=/['"]/g,C=b.documentElement,D=b.getElementsByClassName("lazyconditionalinclude"),E=function(){var a=2,b=3,c=a,d=0,e=0,f=[],g=function(){var a,b=function(){f.length&&(d=0,f.d())};return function(){clearTimeout(a),a=setTimeout(b,999)}}();return{q:function(a){var h=null==a.getAttribute("data-lazyqueue");h&&(e++,c=b),d>c?f[h?"unshift":"push"](a):q(a)&&(d++,g())},d:function(){if(d&&d--,e>0&&(e--,e||(c=a)),!(d>c)){for(;f.length;)if(q(f.shift())){d++;break}g()}}}}(),F=function(){var a,b=function(){for(var a=0,b=D.length;b>a;a++)!lazySizes.hC(D[a],s.lazyClass)&&h(D[a])&&lazySizes.aC(D[a],s.lazyClass)};return function(c){clearTimeout(a),v=null,a=setTimeout(b,"resize"==c.type?31:0)}}();s=a.lazySizes&&lazySizes.cfg||a.lazySizesConfig,s||(s={},a.lazySizesConfig=s),s.include||(s.include={}),t=s.include,t.contentElement||(t.contentElement="html"),t.conditions||(t.conditions={}),t.map||(t.map={}),"preloadAfterLoad"in s||(s.preloadAfterLoad=!0),addEventListener("lazybeforeunveil",r,!1),addEventListener("resize",F,!1),addEventListener("lazyrefreshincludes",F,!1)}}(window,document);
\ No newline at end of file
......@@ -117,7 +117,7 @@ window.lazySizesConfig.getOptimumX = function(/*element*/){
};
```
##Background information
##<a name="compressive-picture-pattern"></a>Background information: Compressive picture pattern
From a perceived performance vs. perceived quality standpoint the best way to deal with High DPI images is to serve higher compressed candidates to clients with high resolution displays.
......@@ -158,7 +158,7 @@ Or in case you are using the [Responsive Images as a Service extension (RIaS)](.
<script>
document.addEventListener('lazyriasmodifyoptions', function(data){
data.details.quality = (window.devicePixelRatio || 1) > 1.4 ? 60 : 80;
};
});
</script>
<img
......@@ -171,3 +171,51 @@ document.addEventListener('lazyriasmodifyoptions', function(data){
Unfortunately these techniques also double the amount of generated image candidates. In case you don't have so much resources the optimumx extension in conjunction with proper image compression is the best thing you can do.
But be aware each image has different characteristics: While some images look great on a HIGH DPI device even with a ``data-optimumx="1.2"`` other will need a much higher density for a good perceived quality.
##<a name="lying-sizes"></a>Background information: Lying sizes attribute
There is also another much more lightweight way to get a similar effect. Instead of parsing and constraining the ``srcset`` to meet the ``data-optimumx`` and ``data-minx`` constraints, there is also the possibility to modify the ``sizes`` attribute instead.
A ``data-optimumx`` implementation with the ``lazybeforesizes`` event could then look something like this:
```html
<script>
document.addEventListener('lazybeforesizes', function(e){
var maxx = parseFloat(e.target.getAttribute('data-optimumx') || '', 10);
var dpr = (window.devicePixelRatio || 1);
if(maxx && maxx < (window.devicePixelRatio || 1)){
e.details.width = e.details.width * (maxx / dpr);
}
});
</script>
<img class="lazyload" data-sizes="auto" data-optimumx="1.5" data-srcset="..." />
```
Compared to the size of this plugin this is a very neat, simple and lightweight technique.
But this technique should be used with caution because the browsers algorithm is tricked and operates with wrong values, which can result in unpredictable and bad results.
In case the ``sizes`` attribute is faked to a lower value and the browser already wants to select a lower candidate, (because the device has a low or metered bandwidth) the browser might choose an unfeasible image candidate instead.
In case the ``sizes`` attribute is faked to a higher value and the browser already wants to select a higher candidate, (because the user has zoomed into this particular image) the browser might be tricked to download a much heavier image candidate than the device actually needs.
But this technique can be used to tell the browser some small lies. Normally the browser runs a simple get the nearest candidate algorithm. This can in some cases cause a poor quality on 1x devices. In case our lie is small and limited we can workaround this problem with doing much harm:
```html
<script>
//make the image sizes only 5% larger, if seen on a low DPI device
document.addEventListener('lazybeforesizes', function(e){
var dpr = (window.devicePixelRatio || 1);
if(dpr < 1.1){
e.details.width = e.details.width * 1.05;
}
});
</script>
<img class="lazyload"
data-sizes="auto"
data-srcset="image-480.jpg 480w, image-768.jpg"
style="width: 600px;"
/>
```
/*! lazysizes - v0.9.0 - 2015-02-02
/*! lazysizes - v0.9.0 - 2015-02-03
Licensed MIT */
!function(a,b){"use strict";var c,d=/^picture$/i,e=b.documentElement,f=function(){var a,b=/(([^,\s].[^\s]+)\s+(\d+)w)/g,c=/\s+\d+h/g,d=function(b,c,d,e){a.push({c:c,u:d,w:1*e})};return function(e){return a=[],e.replace(c,"").replace(b,d),a}}(),g=function(){var a=function(a,b){return a.w-b.w},b=function(b,c,d){var e={srcset:b.getAttribute(lazySizes.cfg.srcsetAttr)||""},g=f(e.srcset);return Object.defineProperty(b,c,{value:e,writable:!0}),e.cands=g,e.index=0,e.dirty=!1,g[0]&&g[0].w?(d&&(e.index=g.length-1),g.sort(a),e.cSrcset=[g[e.index].c]):(e.cSrcset=e.srcset?[e.srcset]:[],e.cands=[]),e};return function(a,c){var e,f,g,h,i="_lazyMinx"==c;if(!a[c]&&(h=a.parentNode||{},a[c]=b(a,c,i),a[c].isImg=!0,d.test(h.nodeName||"")))for(a[c].picture=!0,e=h.getElementsByTagName("source"),f=0,g=e.length;g>f;f++)b(e[f],c,i).isImg=!1;return a[c]}}(),h={_lazyOptimumx:function(){var a=function(a,b,c){var d,e;return a&&a.w?a.w>c?!1:(d=1-a.w/c,e=b/c-1,0>e-d):!0};return function(b,c){var d,e;for(d=b.index+1;d<b.cands.length&&(e=b.cands[d],e.w<=c||a(b.cands[d-1],e.w,c));d++)b.cSrcset.push(e.c),b.index=d}}(),_lazyMinx:function(a,b){for(var c,d=a.index-1;d>-1&&(c=a.cands[d],c.w>=b);)a.cSrcset.push(c.c),a.index=d,d--}},i=function(){var a=function(a,b,c,d){var e,f=a[d];f&&(e=f.index,h[d](f,b),f.dirty&&e==f.index||(f.cSrcset.join(", "),a.setAttribute(c,f.cSrcset.join(", ")),f.dirty=!0,f.cSrcset.length>=f.cands.length&&(a.removeAttribute("data-optimumx"),a.removeAttribute("data-maxdpr"))))};return function(b,c,d,e){var f,g,h,i,j=b[e];if(j.width=c,j.picture&&(g=b.parentNode))for(f=g.getElementsByTagName("source"),i=0,h=f.length;h>i;i++)a(f[i],c,d,e);a(b,c,d,e)}}(),j=function(a){var b=a.getAttribute("data-optimumx")||a.getAttribute("data-maxdpr");return b&&(b="auto"==b?c.getOptimumX(a):parseFloat(b,10)),b},k=function(){a.lazySizes&&!a.lazySizes.getOptimumX&&(lazySizes.getX=j,lazySizes.pWS=f,e.removeEventListener("lazybeforeunveil",k))};e.addEventListener("lazybeforeunveil",k),setTimeout(k),c=a.lazySizes&&lazySizes.cfg||a.lazySizesConfig,c||(c={},a.lazySizesConfig=c),"function"!=typeof c.getOptimumX&&(c.getOptimumX=function(){var b=a.devicePixelRatio||1;return b>2.4?b*=.63:b>1.9?b*=.8:b>1.4&&(b*=.9),Math.min(Math.round(100*b)/100,2)}),a.devicePixelRatio&&(addEventListener("lazybeforesizes",function(a){var b,c,d,e;a.defaultPrevented||!(b=j(a.target))||b>=devicePixelRatio||(c=g(a.target,"_lazyOptimumx"),d=a.details.width*b,d&&(c.width||0)<d&&(e=a.details.dataAttr?lazySizes.cfg.srcsetAttr:"srcset",i(a.target,d,e,"_lazyOptimumx")))}),addEventListener("lazybeforesizes",function(a){var b,c,d,e;a.defaultPrevented||a.target._lazyOptimumx||!(b=1*a.target.getAttribute("data-minx"))||b+.2<devicePixelRatio||(c=g(a.target,"_lazyMinx"),b=Math.min(b,devicePixelRatio),d=a.details.width*b,d&&(c.width||0)<d&&(e=a.details.dataAttr?lazySizes.cfg.srcsetAttr:"srcset",i(a.target,d,e,"_lazyMinx"),a.target.removeAttribute("data-minx")))}),addEventListener("lazybeforeunveil",function(a){a.target._lazyOptimumx&&(a.target._lazyOptimumx=null),a.target._lazyMinx&&(a.target._lazyMinx=null)}))}(window,document);
\ No newline at end of file
/*! lazysizes - v0.9.0 - 2015-02-02
/*! lazysizes - v0.9.0 - 2015-02-03
Licensed MIT */
!function(a){"use strict";var b,c,d,e;a.addEventListener&&(b=a.lazySizes&&lazySizes.cfg||a.lazySizesConfig||{},c=b.lazyClass||"lazyload",d=function(){var b,d;if("string"==typeof c&&(c=document.getElementsByClassName(c)),a.lazySizes)for(b=0,d=c.length;d>b;b++)lazySizes.unveilLazy(c[b])},addEventListener("beforeprint",d,!1),!("onbeforeprint"in a)&&a.matchMedia&&(e=matchMedia("print"))&&e.addListener&&e.addListener(function(){e.matches&&d()}))}(window);
\ No newline at end of file
......@@ -70,7 +70,7 @@ or element specific and functional using the ``lazyriasmodifyoptions`` event.
document.addEventListener('lazyriasmodifyoptions', function(event){
// event.details referes the placeholders/options and event.target the corresponding element
event.details.quality = (window.devicePixelRatio || 1) > 1.4 ? 65 : 80;
};
});
</script>
<img
data-src="image-w{width}-q{quality}.jpg"
......
......@@ -219,15 +219,17 @@
var x = Math.min(optimum || dpr, 2.2, dpr);
if(x < 1.2){
x *= 1.1;
x *= 1.05;
} else if(x > 1.6 && !optimum){
x *= 0.9;
x *= 0.95;
}
return x;
};
var getCandidate = function(elem, width){
var sources, i, len, media, srces;
width = Math.round(width * getX(elem));
srces = elem._lazyrias;
......
/*! lazysizes - v0.9.0 - 2015-02-02
/*! lazysizes - v0.9.0 - 2015-02-03
Licensed MIT */
!function(a,b){"use strict";function c(a,b){var c,d,e,f;d=a.parentNode,f={isPicture:!(!d||!l.test(d.nodeName||""))},e=function(b,c){var d=a.getAttribute("data-"+b);if(null!=d){if("true"==d)d=!0;else if("false"==d)d=!1;else if(k.test(d))d=parseFloat(d);else if("function"==typeof i[b])d=i[b](a,d);else if(o.test(d))try{d=JSON.parse(d)}catch(e){}f[b]=d}else b in i&&"function"!=typeof i[b]?f[b]=i[b]:c&&"function"==typeof i[b]&&(f[b]=i[b](a,d))};for(c in i)e(c);return b.replace(n,function(a,b){b in f||e(b,!0)}),f}function d(a,b){var c=[],d=function(a,c){return j[typeof b[c]]?b[c]:a};return c.srcset=[],b.absUrl&&(q.setAttribute("href",a),a=q.href),a=((b.prefix||"")+a+(b.postfix||"")).replace(n,d),b.widths.forEach(function(d){var e={u:a.replace(m,b.widthmap[d]||d),w:d};c.push(e),c.srcset.push(e.c=e.u+" "+d+"w")}),c}function e(a,b,c){a&&(a=d(a,b),a.isPicture=b.isPicture,c.setAttribute(h.srcsetAttr,a.srcset.join(", ")),Object.defineProperty(c,"_lazyrias",{value:a,writable:!0}))}function f(a,b){var d=c(a,b);return i.modifyOptions.call(a,{target:a,details:d}),lazySizes.fire(a,"lazyriasmodifyoptions",d),d}function g(a){return a.getAttribute(a.getAttribute("data-srcattr")||i.srcAttr)||a.getAttribute(h.srcsetAttr)||a.getAttribute(h.srcAttr)||""}if(b.addEventListener){var h,i,j={string:1,number:1},k=/^\-*\+*\d+\.*\d*$/,l=/^picture$/i,m=/\s*\{\s*width\s*\}\s*/i,n=/\s*\{\s*([a-z0-9]+)\s*\}\s*/gi,o=/^\[.*\]|\{.*\}$/,p=/^(?:auto|\d+(px)?)$/,q=b.createElement("a");!function(){var b,c=function(){},d={prefix:"",postfix:"",srcAttr:"data-src",absUrl:!1,modifyOptions:c,widthmap:{}};h=a.lazySizes&&lazySizes.cfg||a.lazySizesConfig,h||(h={},a.lazySizesConfig=h),h.rias||(h.rias={}),i=h.rias,"widths"in i||(i.widths=[],function(a){var b,c=0;for(a.push(96);!b||2800>b;)c+=10,c>60&&(c+=10),b=16*c,a.push(b)}(i.widths));for(b in d)b in i||(i[b]=d[b])}(),addEventListener("lazybeforeunveil",function(a){var b,c,d,j,k,l,n,o,q;if(b=a.target,!a.defaultPrevented&&(c=g(b))&&!i.disabled&&(q=b.getAttribute(h.sizesAttr)||b.getAttribute("sizes"))&&p.test(q)){if(d=f(b,c),m.test(c)||m.test(d.prefix)||m.test(d.postfix)){if(d.isPicture&&(j=b.parentNode))for(k=j.getElementsByTagName("source"),l=0,n=k.length;n>l;l++)o=g(k[l]),e(o,d,k[l]);e(c,d,b)}"auto"!=q&&r({target:b,details:{width:parseInt(q,10)}})}});var r=function(){var c=function(a,b,c,d){return Math.abs(b.w-d.w)<Math.abs(a.w-d.w)?b:a},d=function(a,b){var c;return!a._lazyrias&&lazySizes.pWS&&(c=lazySizes.pWS(a.getAttribute(h.srcsetAttr||""))).length&&(Object.defineProperty(a,"_lazyrias",{value:c,writable:!0}),b&&a.parentNode&&(c.isPicture="PICTURE"==a.parentNode.nodeName.toUpperCase())),a._lazyrias},e=function(b,e){var f,g,h,i,j;if(e*=Math.min(lazySizes.getX&&lazySizes.getX(b)||a.devicePixelRatio||1,2),j=b._lazyrias,j.isPicture&&a.matchMedia)for(g=0,f=b.parentNode.getElementsByTagName("source"),h=f.length;h>g;g++)if(d(f[g])&&!f[g].getAttribute("type")&&(!(i=f[g].getAttribute("media"))||(matchMedia(i)||{}).matches)){j=f[g]._lazyrias;break}return(!j.w||j.w<e)&&(j.w=e),j.reduce(c)},f=function(c){var g,i=c.target;return a.HTMLPictureElement||a.respimage||a.picturefill?void b.removeEventListener("lazybeforesizes",f):void((i._lazyrias||c.details.dataAttr&&d(i,!0))&&(g=e(i,c.details.width),g&&g.u&&i._lazyrias.cur!=g.u&&(i._lazyrias.cur=g.u,i.setAttribute(h.srcAttr,g.u),i.setAttribute("src",g.u))))};return b.addEventListener("lazybeforesizes",f),f}()}}(window,document);
\ No newline at end of file
!function(a,b){"use strict";function c(a,b){var c,d,e,f;d=a.parentNode,f={isPicture:!(!d||!l.test(d.nodeName||""))},e=function(b,c){var d=a.getAttribute("data-"+b);if(null!=d){if("true"==d)d=!0;else if("false"==d)d=!1;else if(k.test(d))d=parseFloat(d);else if("function"==typeof i[b])d=i[b](a,d);else if(o.test(d))try{d=JSON.parse(d)}catch(e){}f[b]=d}else b in i&&"function"!=typeof i[b]?f[b]=i[b]:c&&"function"==typeof i[b]&&(f[b]=i[b](a,d))};for(c in i)e(c);return b.replace(n,function(a,b){b in f||e(b,!0)}),f}function d(a,b){var c=[],d=function(a,c){return j[typeof b[c]]?b[c]:a};return c.srcset=[],b.absUrl&&(q.setAttribute("href",a),a=q.href),a=((b.prefix||"")+a+(b.postfix||"")).replace(n,d),b.widths.forEach(function(d){var e={u:a.replace(m,b.widthmap[d]||d),w:d};c.push(e),c.srcset.push(e.c=e.u+" "+d+"w")}),c}function e(a,b,c){a&&(a=d(a,b),a.isPicture=b.isPicture,c.setAttribute(h.srcsetAttr,a.srcset.join(", ")),Object.defineProperty(c,"_lazyrias",{value:a,writable:!0}))}function f(a,b){var d=c(a,b);return i.modifyOptions.call(a,{target:a,details:d}),lazySizes.fire(a,"lazyriasmodifyoptions",d),d}function g(a){return a.getAttribute(a.getAttribute("data-srcattr")||i.srcAttr)||a.getAttribute(h.srcsetAttr)||a.getAttribute(h.srcAttr)||""}if(b.addEventListener){var h,i,j={string:1,number:1},k=/^\-*\+*\d+\.*\d*$/,l=/^picture$/i,m=/\s*\{\s*width\s*\}\s*/i,n=/\s*\{\s*([a-z0-9]+)\s*\}\s*/gi,o=/^\[.*\]|\{.*\}$/,p=/^(?:auto|\d+(px)?)$/,q=b.createElement("a");!function(){var b,c=function(){},d={prefix:"",postfix:"",srcAttr:"data-src",absUrl:!1,modifyOptions:c,widthmap:{}};h=a.lazySizes&&lazySizes.cfg||a.lazySizesConfig,h||(h={},a.lazySizesConfig=h),h.rias||(h.rias={}),i=h.rias,"widths"in i||(i.widths=[],function(a){var b,c=0;for(a.push(96);!b||2800>b;)c+=10,c>60&&(c+=10),b=16*c,a.push(b)}(i.widths));for(b in d)b in i||(i[b]=d[b])}(),addEventListener("lazybeforeunveil",function(a){var b,c,d,j,k,l,n,o,q;if(b=a.target,!a.defaultPrevented&&(c=g(b))&&!i.disabled&&(q=b.getAttribute(h.sizesAttr)||b.getAttribute("sizes"))&&p.test(q)){if(d=f(b,c),m.test(c)||m.test(d.prefix)||m.test(d.postfix)){if(d.isPicture&&(j=b.parentNode))for(k=j.getElementsByTagName("source"),l=0,n=k.length;n>l;l++)o=g(k[l]),e(o,d,k[l]);e(c,d,b)}"auto"!=q&&r({target:b,details:{width:parseInt(q,10)}})}});var r=function(){var c=function(a,b,c,d){return Math.abs(b.w-d.w)<Math.abs(a.w-d.w)?b:a},d=function(a,b){var c;return!a._lazyrias&&lazySizes.pWS&&(c=lazySizes.pWS(a.getAttribute(h.srcsetAttr||""))).length&&(Object.defineProperty(a,"_lazyrias",{value:c,writable:!0}),b&&a.parentNode&&(c.isPicture="PICTURE"==a.parentNode.nodeName.toUpperCase())),a._lazyrias},e=function(b){var c=a.devicePixelRatio||1,d=lazySizes.getX&&lazySizes.getX(b),e=Math.min(d||c,2.2,c);return 1.2>e?e*=1.05:e>1.6&&!d&&(e*=.95),e},f=function(b,f){var g,h,i,j,k;if(f=Math.round(f*e(b)),k=b._lazyrias,k.isPicture&&a.matchMedia)for(h=0,g=b.parentNode.getElementsByTagName("source"),i=g.length;i>h;h++)if(d(g[h])&&!g[h].getAttribute("type")&&(!(j=g[h].getAttribute("media"))||(matchMedia(j)||{}).matches)){k=g[h]._lazyrias;break}return(!k.w||k.w<f)&&(k.w=f),k.reduce(c)},g=function(c){var e,i=c.target;return a.HTMLPictureElement||a.respimage||a.picturefill?void b.removeEventListener("lazybeforesizes",g):void((i._lazyrias||c.details.dataAttr&&d(i,!0))&&(e=f(i,c.details.width),e&&e.u&&i._lazyrias.cur!=e.u&&(i._lazyrias.cur=e.u,i.setAttribute(h.srcAttr,e.u),i.setAttribute("src",e.u))))};return b.addEventListener("lazybeforesizes",g),g}()}}(window,document);
\ No newline at end of file
/*! lazysizes - v0.9.0 - 2015-02-02
/*! lazysizes - v0.9.0 - 2015-02-03
Licensed MIT */
!function(a,b){"use strict";var c;a.addEventListener&&(c=a.lazySizes&&lazySizes.cfg||a.lazySizesConfig,c||(c={},a.lazySizesConfig=c),c.scroll=!1,addEventListener("scroll",function(){var c,d,e,f,g,h=function(){var a=d.scrollTop||d.pageYOffset||0,b=d.scrollLeft||d.pageXOffset||0;d=null,Math.abs(f-a)<66&&Math.abs(g-b)<66&&i()},i=function(){a.lazySizes&&lazySizes.updateAllLazy(),clearTimeout(c),clearTimeout(e),d=null};return function(j){var k=j.target==b?a:j.target;clearTimeout(c),c=setTimeout(i,44),d?k!=d&&i():(d=k,f=d.scrollTop||d.pageYOffset||0,g=d.scrollLeft||d.pageXOffset||0,clearTimeout(e),e=setTimeout(h,99)),k=null}}(),!0))}(window,document);
\ No newline at end of file
/*! lazysizes - v0.9.0 - 2015-02-02
/*! lazysizes - v0.9.0 - 2015-02-03
Licensed MIT */
!function(a,b){"use strict";function c(a,c){if(!f[a]){var d=b.createElement(c?"link":"script"),e=b.getElementsByTagName("script")[0];c?(d.rel="stylesheet",d.href=a):d.src=a,f[a]=!0,f[d.src||d.href]=!0,e.parentNode.insertBefore(d,e)}}var d,e,f={};b.addEventListener&&a.getComputedStyle&&(d=a.lazySizes&&lazySizes.cfg||a.lazySizesConfig||{},e=function(a,c){var d=b.createElement("img");d.onload=function(){d.onload=null,d.onerror=null,d=null,c()},d.onerror=d.onload,d.src=a,d&&d.complete&&d.onload&&d.onload()},addEventListener("lazybeforeunveil",function(b){var d,f,g,h;b.defaultPrevented||("none"==b.target.preload&&(b.target.preload="auto"),d=b.target.getAttribute("data-link"),d&&c(d,!0),d=b.target.getAttribute("data-script"),d&&c(d),d=b.target.getAttribute("data-require"),d&&a.require&&require([d]),g=b.target.getAttribute("data-bg"),g&&(b.details.firesLoad=!0,f=function(){b.target.style.backgroundImage="url("+g+")",b.details.firesLoad=!1,lazySizes.fire(b.target,"_lazyloaded")},e(g,f)),h=b.target.getAttribute("data-poster"),h&&(b.details.firesLoad=!0,f=function(){b.target.poster=h,b.details.firesLoad=!1,lazySizes.fire(b.target,"_lazyloaded")},e(h,f)))},!1))}(window,document);
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment