From 990e04f964ef5fe49918e550cb9a51808560a1e9 Mon Sep 17 00:00:00 2001 From: aFarkas Date: Mon, 1 Dec 2014 23:49:20 +0100 Subject: [PATCH] update respimage + add new markup pattern --- README.md | 17 ++++++++++++++++- index.html | 2 +- lazysizes.js | 8 ++++++-- lazysizes.min.js | 2 +- optimumx/child.html | 2 +- rias/index.html | 16 ++++++++-------- 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 8206a31e..f3d4f2e2 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,22 @@ In case you want to save more initial image data the LQIP pattern can't be used ``` -###JS API +###SEO pattern + +In case you don't need to account for JS off or legacy browers, but still for search engines you can use a one pixel ``src`` or better a data URI and add [ImageObject schema via Microdata](http://schema.org/ImageObject) for search engines: + +```html + +my image +``` + +###JS API **lazysizes** automatically detects new elements with the class ``lazyload`` so you won't need to call or configure anything in most situations. ####JS API - options diff --git a/index.html b/index.html index 56dc27d4..199354dd 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ diff --git a/lazysizes.js b/lazysizes.js index f20843d8..8a689719 100644 --- a/lazysizes.js +++ b/lazysizes.js @@ -74,7 +74,7 @@ var imageData; if(window.picturefill){ picturefill({reevaluate: true, reparse: true, elements: [el]}); - } else if(window.respimage && !respimage._.observer){ + } else if(window.respimage){ if(full){ imageData = el[respimage._.ns]; if(imageData){ @@ -83,7 +83,7 @@ } respimage({reparse: true, elements: [el]}); } else if(!window.HTMLPictureElement && window.console && document.readyState == 'complete'){ - console.log('use a respimg polyfill: http://bit.ly/1FCts3P'); + console.log('use respimg polyfill: http://bit.ly/1FCts3P'); } } @@ -264,6 +264,10 @@ updatePolyfill(elem, {srcset: srcset, src: src}); } + if(elem.lazyload){ + elem.lazyload = 0; + } + if( lazySizesConfig.addClasses && (!isImg || (!srcset && !src) || (elem.complete && curSrc == (elem.currentSrc || elem.src))) ){ switchLoadingClass({target: elem}); } diff --git a/lazysizes.min.js b/lazysizes.min.js index 5b18a3e1..4955fa47 100644 --- a/lazysizes.min.js +++ b/lazysizes.min.js @@ -1,3 +1,3 @@ /*! lazysizes - v0.5.0 - 2014-12-01 Licensed MIT */ -!function(a){window.lazySizes=a(),"function"==typeof define&&define.amd&&define(function(){return window.lazySizes})}(function(){"use strict";function a(a,b){var c;window.picturefill?picturefill({reevaluate:!0,reparse:!0,elements:[a]}):window.respimage&&!respimage._.observer?(b&&(c=a[respimage._.ns],c&&(c[b.srcset?"srcset":"src"]=void 0)),respimage({reparse:!0,elements:[a]})):!window.HTMLPictureElement&&window.console&&"complete"==r.readyState&&console.log("use a respimg polyfill: http://bit.ly/1FCts3P")}function b(a){s++,a=d(a),x(a,J,!0),clearTimeout(A),A=setTimeout(J,5e3)}function c(){m=0,clearTimeout(l)}function d(b,c){var d,e,g,h,j,k,l,m,p,q,r=y(b,"lazybeforeunveil",{force:!!c}),s=b.currentSrc||b.src;if(!r.defaultPrevented&&(j=b.getAttribute(i.sizesAttr)||b.getAttribute("sizes"),j&&("auto"==j?f(b,!0):b.setAttribute("sizes",j),i.clearAttr&&b.removeAttribute(i.sizesAttr)),l=b.getAttribute(i.srcsetAttr),k=b.getAttribute(i.srcAttr),(p=u.test(b.nodeName||""))&&(m=b.parentNode,q=t.test(m.nodeName||"")),i.addClasses&&(n(b,i.loadingClass),p&&x(b,M,!0)),l||k)){if(q)for(d=m.getElementsByTagName("source"),e=0,g=d.length;g>e;e++)h=d[e].getAttribute(i.srcsetAttr),h&&d[e].setAttribute("srcset",h);l?(b.setAttribute("srcset",l),i.clearAttr&&b.removeAttribute(i.srcsetAttr)):k&&(b.setAttribute("src",k),i.clearAttr&&b.removeAttribute(i.srcAttr))}return w(function(){o(b,i.lazyClass),"auto"==j&&n(b,i.autosizesClass),(l||j)&&a(b,{srcset:l,src:k}),i.addClasses&&(!p||!l&&!k||b.complete&&s==(b.currentSrc||b.src))&&M({target:b})}),b}function e(){k=0,clearTimeout(j)}function f(b,c){var d,e,f,g,h,j,k,l;if(g=b.parentNode){if(d=g.offsetWidth,e=b.offsetWidth,f=e>d?e:d,!f&&!b._lazysizesWidth)for(;g&&g!=r.body&&!f;)f=g.offsetWidth,g=g.parentNode;if(l=y(b,"lazybeforesizes",{width:f,dataAttr:!!c}),!l.defaultPrevented&&(f=l.details.width,f&&f!==b._lazysizesWidth&&(!i.onlyLargerSizes||!b._lazysizesWidth||b._lazysizesWidthj;j++)h[j].setAttribute("sizes",f);l.details.dataAttr||a(b)}}}if(Date.now&&window.document.getElementsByClassName&&Object.freeze){var g,h,i,j,k,l,m,n,o,p,q,r=window.document,s=0,t=/^picture$/i,u=/^img$/i,v=40,w=window.setImmediate||window.setTimeout,x=function(a,b,c){var d=c?"addEventListener":"removeEventListener";c&&x(a,b),a[d]("load",b,!1),a[d]("error",b,!1)},y=function(a,b,c){var d=r.createEvent("Event");return d.initEvent(b,!0,!0),d.details=c||{},a.dispatchEvent(d),d};r.documentElement.classList?(n=function(a,b){a.classList.add(b)},o=function(a,b){a.classList.remove(b)},p=function(a,b){return a.classList.contains(b)}):(n=function(a,b){p(a,b)||(a.className+=" "+b)},o=function(a,b){var c;p(a,b)&&(c=new RegExp("(\\s|^)"+b+"(\\s|$)"),a.className=a.className.replace(c," "))},p=function(a,b){return a.className.match(new RegExp("(\\s|^)"+b+"(\\s|$)"))});var z,A,B,C,D,E,F,G,H,I=Date.now(),J=function(a){s--,clearTimeout(A),a&&a.target&&x(a.target,J),(!a||0>s||!a.target)&&(s=0)},K=function(){var a,b,d=function(){b=!1},e=function(){clearTimeout(a),c(),L(),setTimeout(d)};return{debounce:function(){clearTimeout(a),b=!0,a=setTimeout(e,66)},throttled:function(){var c;b||(b=!0,clearTimeout(a),c=Date.now()-I,c=c>300?9:99,a=setTimeout(e,c))}}}(),L=function(){var a,c,e;if(z=g.length,I=Date.now(),z){for(B=window.innerWidth+v,C=window.innerHeight+v,H=-1*v;z>m;m++)if(a=g[m].getBoundingClientRect(),(G=a.bottom)>=H&&(D=a.top)<=C&&(F=a.right)>=H&&(E=a.left)<=B&&(G||F||E||D)&&(!q||"hidden"!=getComputedStyle(g[m],null).visibility))d(g[m]),e=!0;else{if(z-1>m&&Date.now()-I>9){c=!1,l=setTimeout(L,4);break}!e&&q&&!c&&i.preloadAfterLoad&&2>s&&(G||F||E||D||"auto"!=g[m].getAttribute(i.sizesAttr))&&(c=g[m])}c&&!e&&b(c)}},M=function(a){n(a.target,a.target.getAttribute("data-loadedclass")||i.loadedClass),o(a.target,i.loadingClass)},N=function(){var a,b=function(){clearTimeout(a),e(),O()};return function(){clearTimeout(a),clearTimeout(j),a=setTimeout(b,99)}}(),O=function(){var a,b,c,d=h.length;if(d)for(b=Date.now(),c=k||0,a=c+3,e();d>c;c++)if(f(h[c]),c>a&&d-1>c&&Date.now()-b>9){k=c+1,j=setTimeout(O,4);break}},P=r.documentElement,Q=function(){v=600,r.addEventListener("load",K.throttled,!0),q=!0},R=function(){i.mutation&&(window.MutationObserver?new MutationObserver(K.throttled).observe(P,{childList:!0,subtree:!0,attributes:!0}):(P.addEventListener("DOMNodeInserted",K.throttled,!0),P.addEventListener("DOMAttrModified",K.throttled,!0))),i.hover&&r.addEventListener("mouseover",K.throttled,!0),r.addEventListener("focus",K.throttled,!0),window.addEventListener("hashchange",K.throttled,!0),"onmozfullscreenchange"in P?window.addEventListener("mozfullscreenchange",K.throttled,!0):"onwebkitfullscreenchange"in P?window.addEventListener("webkitfullscreenchange",K.throttled,!0):window.addEventListener("fullscreenchange",K.throttled,!0),i.cssanimation&&(r.addEventListener("animationstart",K.throttled,!0),r.addEventListener("transitionstart",K.throttled,!0))};return i=window.lazySizesConfig||{},function(){var a,b={mutation:!0,hover:!0,cssanimation:!0,addClasses:!1,lazyClass:"lazyload",loadedClass:"lazyloaded",loadingClass:"lazyloading",scroll:!0,autosizesClass:"lazyautosizes",srcAttr:"data-src",srcsetAttr:"data-srcset",sizesAttr:"data-sizes",preloadAfterLoad:!1,onlyLargerSizes:!0};for(a in b)a in i||(i[a]=b[a])}(),setTimeout(function(){g=r.getElementsByClassName(i.lazyClass),h=r.getElementsByClassName(i.autosizesClass),i.scroll&&addEventListener("scroll",K.throttled,!0),addEventListener("resize",K.debounce,!1),addEventListener("resize",N,!1),/^i|^loade|c/.test(r.readyState)?R():r.addEventListener("DOMContentLoaded",R,!1),"complete"==r.readyState?Q():(addEventListener("load",Q,!1),r.addEventListener("readystatechange",K.throttled,!1)),K.throttled(),o(P,"no-js")}),{cfg:i,updateAllSizes:N,updateAllLazy:K.throttled,unveilLazy:function(a){p(a,i.lazyClass)&&d(a)},updateSizes:f,updatePolyfill:a}}}); \ No newline at end of file +!function(a){window.lazySizes=a(),"function"==typeof define&&define.amd&&define(function(){return window.lazySizes})}(function(){"use strict";function a(a,b){var c;window.picturefill?picturefill({reevaluate:!0,reparse:!0,elements:[a]}):window.respimage?(b&&(c=a[respimage._.ns],c&&(c[b.srcset?"srcset":"src"]=void 0)),respimage({reparse:!0,elements:[a]})):!window.HTMLPictureElement&&window.console&&"complete"==r.readyState&&console.log("use respimg polyfill: http://bit.ly/1FCts3P")}function b(a){s++,a=d(a),x(a,J,!0),clearTimeout(A),A=setTimeout(J,5e3)}function c(){m=0,clearTimeout(l)}function d(b,c){var d,e,g,h,j,k,l,m,p,q,r=y(b,"lazybeforeunveil",{force:!!c}),s=b.currentSrc||b.src;if(!r.defaultPrevented&&(j=b.getAttribute(i.sizesAttr)||b.getAttribute("sizes"),j&&("auto"==j?f(b,!0):b.setAttribute("sizes",j),i.clearAttr&&b.removeAttribute(i.sizesAttr)),l=b.getAttribute(i.srcsetAttr),k=b.getAttribute(i.srcAttr),(p=u.test(b.nodeName||""))&&(m=b.parentNode,q=t.test(m.nodeName||"")),i.addClasses&&(n(b,i.loadingClass),p&&x(b,M,!0)),l||k)){if(q)for(d=m.getElementsByTagName("source"),e=0,g=d.length;g>e;e++)h=d[e].getAttribute(i.srcsetAttr),h&&d[e].setAttribute("srcset",h);l?(b.setAttribute("srcset",l),i.clearAttr&&b.removeAttribute(i.srcsetAttr)):k&&(b.setAttribute("src",k),i.clearAttr&&b.removeAttribute(i.srcAttr))}return w(function(){o(b,i.lazyClass),"auto"==j&&n(b,i.autosizesClass),(l||j)&&a(b,{srcset:l,src:k}),b.lazyload&&(b.lazyload=0),i.addClasses&&(!p||!l&&!k||b.complete&&s==(b.currentSrc||b.src))&&M({target:b})}),b}function e(){k=0,clearTimeout(j)}function f(b,c){var d,e,f,g,h,j,k,l;if(g=b.parentNode){if(d=g.offsetWidth,e=b.offsetWidth,f=e>d?e:d,!f&&!b._lazysizesWidth)for(;g&&g!=r.body&&!f;)f=g.offsetWidth,g=g.parentNode;if(l=y(b,"lazybeforesizes",{width:f,dataAttr:!!c}),!l.defaultPrevented&&(f=l.details.width,f&&f!==b._lazysizesWidth&&(!i.onlyLargerSizes||!b._lazysizesWidth||b._lazysizesWidthj;j++)h[j].setAttribute("sizes",f);l.details.dataAttr||a(b)}}}if(Date.now&&window.document.getElementsByClassName&&Object.freeze){var g,h,i,j,k,l,m,n,o,p,q,r=window.document,s=0,t=/^picture$/i,u=/^img$/i,v=40,w=window.setImmediate||window.setTimeout,x=function(a,b,c){var d=c?"addEventListener":"removeEventListener";c&&x(a,b),a[d]("load",b,!1),a[d]("error",b,!1)},y=function(a,b,c){var d=r.createEvent("Event");return d.initEvent(b,!0,!0),d.details=c||{},a.dispatchEvent(d),d};r.documentElement.classList?(n=function(a,b){a.classList.add(b)},o=function(a,b){a.classList.remove(b)},p=function(a,b){return a.classList.contains(b)}):(n=function(a,b){p(a,b)||(a.className+=" "+b)},o=function(a,b){var c;p(a,b)&&(c=new RegExp("(\\s|^)"+b+"(\\s|$)"),a.className=a.className.replace(c," "))},p=function(a,b){return a.className.match(new RegExp("(\\s|^)"+b+"(\\s|$)"))});var z,A,B,C,D,E,F,G,H,I=Date.now(),J=function(a){s--,clearTimeout(A),a&&a.target&&x(a.target,J),(!a||0>s||!a.target)&&(s=0)},K=function(){var a,b,d=function(){b=!1},e=function(){clearTimeout(a),c(),L(),setTimeout(d)};return{debounce:function(){clearTimeout(a),b=!0,a=setTimeout(e,66)},throttled:function(){var c;b||(b=!0,clearTimeout(a),c=Date.now()-I,c=c>300?9:99,a=setTimeout(e,c))}}}(),L=function(){var a,c,e;if(z=g.length,I=Date.now(),z){for(B=window.innerWidth+v,C=window.innerHeight+v,H=-1*v;z>m;m++)if(a=g[m].getBoundingClientRect(),(G=a.bottom)>=H&&(D=a.top)<=C&&(F=a.right)>=H&&(E=a.left)<=B&&(G||F||E||D)&&(!q||"hidden"!=getComputedStyle(g[m],null).visibility))d(g[m]),e=!0;else{if(z-1>m&&Date.now()-I>9){c=!1,l=setTimeout(L,4);break}!e&&q&&!c&&i.preloadAfterLoad&&2>s&&(G||F||E||D||"auto"!=g[m].getAttribute(i.sizesAttr))&&(c=g[m])}c&&!e&&b(c)}},M=function(a){n(a.target,a.target.getAttribute("data-loadedclass")||i.loadedClass),o(a.target,i.loadingClass)},N=function(){var a,b=function(){clearTimeout(a),e(),O()};return function(){clearTimeout(a),clearTimeout(j),a=setTimeout(b,99)}}(),O=function(){var a,b,c,d=h.length;if(d)for(b=Date.now(),c=k||0,a=c+3,e();d>c;c++)if(f(h[c]),c>a&&d-1>c&&Date.now()-b>9){k=c+1,j=setTimeout(O,4);break}},P=r.documentElement,Q=function(){v=600,r.addEventListener("load",K.throttled,!0),q=!0},R=function(){i.mutation&&(window.MutationObserver?new MutationObserver(K.throttled).observe(P,{childList:!0,subtree:!0,attributes:!0}):(P.addEventListener("DOMNodeInserted",K.throttled,!0),P.addEventListener("DOMAttrModified",K.throttled,!0))),i.hover&&r.addEventListener("mouseover",K.throttled,!0),r.addEventListener("focus",K.throttled,!0),window.addEventListener("hashchange",K.throttled,!0),"onmozfullscreenchange"in P?window.addEventListener("mozfullscreenchange",K.throttled,!0):"onwebkitfullscreenchange"in P?window.addEventListener("webkitfullscreenchange",K.throttled,!0):window.addEventListener("fullscreenchange",K.throttled,!0),i.cssanimation&&(r.addEventListener("animationstart",K.throttled,!0),r.addEventListener("transitionstart",K.throttled,!0))};return i=window.lazySizesConfig||{},function(){var a,b={mutation:!0,hover:!0,cssanimation:!0,addClasses:!1,lazyClass:"lazyload",loadedClass:"lazyloaded",loadingClass:"lazyloading",scroll:!0,autosizesClass:"lazyautosizes",srcAttr:"data-src",srcsetAttr:"data-srcset",sizesAttr:"data-sizes",preloadAfterLoad:!1,onlyLargerSizes:!0};for(a in b)a in i||(i[a]=b[a])}(),setTimeout(function(){g=r.getElementsByClassName(i.lazyClass),h=r.getElementsByClassName(i.autosizesClass),i.scroll&&addEventListener("scroll",K.throttled,!0),addEventListener("resize",K.debounce,!1),addEventListener("resize",N,!1),/^i|^loade|c/.test(r.readyState)?R():r.addEventListener("DOMContentLoaded",R,!1),"complete"==r.readyState?Q():(addEventListener("load",Q,!1),r.addEventListener("readystatechange",K.throttled,!1)),K.throttled(),o(P,"no-js")}),{cfg:i,updateAllSizes:N,updateAllLazy:K.throttled,unveilLazy:function(a){p(a,i.lazyClass)&&d(a)},updateSizes:f,updatePolyfill:a}}}); \ No newline at end of file diff --git a/optimumx/child.html b/optimumx/child.html index 2a75e93f..11c5f86b 100644 --- a/optimumx/child.html +++ b/optimumx/child.html @@ -753,7 +753,7 @@ - +