From 568f100bd7b6700620c1f34802e13d0e24833e50 Mon Sep 17 00:00:00 2001 From: aFarkas Date: Thu, 18 Jun 2015 13:23:51 +0200 Subject: [PATCH] only run webp test, if browser does not support picture --- dist/picturefill.js | 3 ++- dist/picturefill.min.js | 2 +- src/picturefill.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dist/picturefill.js b/dist/picturefill.js index 95483b11..6e96ea3f 100644 --- a/dist/picturefill.js +++ b/dist/picturefill.js @@ -254,7 +254,6 @@ // test svg support types[ "image/svg+xml" ] = document.implementation.hasFeature( "http://wwwindow.w3.org/TR/SVG11/feature#Image", "1.1" ); - types[ "image/webp" ] = detectTypeSupport("image/webp", "data:image/webp;base64,UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAABBxAR/Q9ERP8DAABWUDggGAAAADABAJ0BKgEAAQADADQlpAADcAD++/1QAA==" ); /** * updates the internal vW property with the current viewport width in px @@ -1372,6 +1371,8 @@ on( window, "resize", onResize ); on( document, "readystatechange", run ); + + types[ "image/webp" ] = detectTypeSupport("image/webp", "data:image/webp;base64,UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAABBxAR/Q9ERP8DAABWUDggGAAAADABAJ0BKgEAAQADADQlpAADcAD++/1QAA==" ); })(); } diff --git a/dist/picturefill.min.js b/dist/picturefill.min.js index 24d2d313..c5f7a361 100644 --- a/dist/picturefill.min.js +++ b/dist/picturefill.min.js @@ -1,4 +1,4 @@ /*! Picturefill - v3.0.0-alpha1 - 2015-06-18 * http://scottjehl.github.io/picturefill * Copyright (c) 2015 https://github.com/scottjehl/picturefill/blob/master/Authors.txt; Licensed MIT */ -!function(a,b,c){"use strict";function d(a){return" "===a||" "===a||"\n"===a||"\f"===a||"\r"===a}function e(b,c){var d=new a.Image;return d.onerror=function(){A[b]=!1,ba()},d.onload=function(){A[b]=1===d.width,ba()},d.src=c,"pending"}function f(){M=!1,P=a.devicePixelRatio,N={},O={},t.DPR=P||1,Q.width=Math.max(a.innerWidth||0,z.clientWidth),Q.height=Math.max(a.innerHeight||0,z.clientHeight),Q.vw=Q.width/100,Q.vh=Q.height/100,s=[Q.height,Q.width,P].join("-"),Q.em=t.getEmValue(),Q.rem=Q.em}function g(a,b,c,d){var e,f,g,h;return"saveData"===B.algorithm?a>2.7?h=c+1:(f=b-c,e=Math.pow(a-.6,1.5),g=f*e,d&&(g+=.1*e),h=a+g):h=c>1?Math.sqrt(a*b):a,h>c}function h(a){var b,c=t.getSet(a),d=!1;"pending"!==c&&(d=s,c&&(b=t.setRes(c),t.applySetCandidate(b,a))),a[t.ns].evaled=d}function i(a,b){return a.res-b.res}function j(a,b,c){var d;return!c&&b&&(c=a[t.ns].sets,c=c&&c[c.length-1]),d=k(b,c),d&&(b=t.makeUrl(b),a[t.ns].curSrc=b,a[t.ns].curCan=d,d.res||aa(d,d.set.sizes)),d}function k(a,b){var c,d,e;if(a&&b)for(e=t.parseSet(b),a=t.makeUrl(a),c=0;cc;c++)e=g[c],e[t.ns]=!0,f=e.getAttribute("srcset"),f&&b.push({srcset:f,media:e.getAttribute("media"),type:e.getAttribute("type"),sizes:e.getAttribute("sizes")})}function m(a,b){function c(b){var c,d=b.exec(a.substring(m));return d?(c=d[0],m+=c.length,c):void 0}function e(){var a,c,d,e,f,i,j,k,l,m=!1,o={};for(e=0;el?m=!0:c=l):X.test(j)&&"h"===i?((d||c)&&(m=!0),0===k?m=!0:d=k):m=!0;m||(o.url=g,a&&(o.w=a),c&&(o.d=c),d&&(o.h=d),d||c||a||(o.d=1),1===o.d&&(b.has1x=!0),o.set=b,n.push(o))}function f(){for(c(T),i="",j="in descriptor";;){if(k=a.charAt(m),"in descriptor"===j)if(d(k))i&&(h.push(i),i="",j="after descriptor");else{if(","===k)return m+=1,i&&h.push(i),void e();if("("===k)i+=k,j="in parens";else{if(""===k)return i&&h.push(i),void e();i+=k}}else if("in parens"===j)if(")"===k)i+=k,j="in descriptor";else{if(""===k)return h.push(i),void e();i+=k}else if("after descriptor"===j)if(d(k));else{if(""===k)return void e();j="in descriptor",m-=1}m+=1}}for(var g,h,i,j,k,l=a.length,m=0,n=[];;){if(c(U),m>=l)return n;g=c(V),h=[],","===g.slice(-1)?(g=g.replace(W,""),e()):f()}}function n(a){function b(a){function b(){g&&(h.push(g),g="")}function e(){h[0]&&(i.push(h),h=[])}for(var f,g="",h=[],i=[],j=0,k=0,l=!1;;){if(f=a[k],f===c)return b(),e(),i;if(l){if("*"===f&&"/"===a[k+1]){l=!1,k+=2,b();continue}k+=1}else{if(d(f)){if(a[k-1]&&d(a[k-1])||!g){k+=1;continue}if(0===j){b(),k+=1;continue}f=" "}else if("("===f)j+=1;else if(")"===f)j-=1;else{if(","===f){b(),e(),k+=1;continue}if("/"===f&&"*"===a[k+1]){l=!0,k+=2;continue}}g+=f,k+=1}}}function e(a){return l.test(a)&&parseFloat(a)>=0?!0:m.test(a)?!0:"0"===a||"-0"===a||"+0"===a?!0:!1}var f,g,h,i,j,k,l=/^(?:[+-]?[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?(?:ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmin|vmax|vw)$/i,m=/^calc\((?:[0-9a-z \.\+\-\*\/\(\)]+)\)$/i;for(g=b(a),h=g.length,f=0;h>f;f++)if(i=g[f],j=i[i.length-1],e(j)){if(k=j,i.pop(),0===i.length)return k;if(i=i.join(" "),t.matchesMedia(i))return k}return"100vw"}b.createElement("picture");var o,p,q,r,s,t={},u=function(){},v=b.createElement("img"),w=v.getAttribute,x=v.setAttribute,y=v.removeAttribute,z=b.documentElement,A={},B={algorithm:""},C="data-pfsrc",D=C+"set",E=navigator.userAgent,F=/rident/.test(E)||/ecko/.test(E)&&E.match(/rv\:(\d+)/)&&RegExp.$1>35,G="currentSrc",H=/\s+\+?\d+(e\d+)?w/,I=/(\([^)]+\))?\s*(.+)/,J=a.picturefillCFG,K="position:absolute;left:0;visibility:hidden;display:block;padding:0;border:none;font-size:1em;width:1em;overflow:hidden;clip:rect(0px, 0px, 0px, 0px)",L="font-size:100%!important;",M=!0,N={},O={},P=a.devicePixelRatio,Q={px:1,"in":96},R=b.createElement("a"),S=!1,T=/^[ \t\n\r\u000c]+/,U=/^[, \t\n\r\u000c]+/,V=/^[^ \t\n\r\u000c]+/,W=/[,]+$/,X=/^\d+$/,Y=/^-?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/,Z=function(a,b,c,d){a.addEventListener?a.addEventListener(b,c,d||!1):a.attachEvent&&a.attachEvent("on"+b,c)},$=function(a){var b={};return function(c){return c in b||(b[c]=a(c)),b[c]}},_=function(){var a=/^([\d\.]+)(em|vw|px)$/,b=function(){for(var a=arguments,b=0,c=a[0];++b in a;)c=c.replace(a[b],a[++b]);return c},c=$(function(a){return"return "+b((a||"").toLowerCase(),/\band\b/g,"&&",/,/g,"||",/min-([a-z-\s]+):/g,"e.$1>=",/max-([a-z-\s]+):/g,"e.$1<=",/calc([^)]+)/g,"($1)",/(\d+[\.]*[\d]*)([a-z]+)/g,"($1 * e.$2)",/^(?!(e.[a-z]|[0-9\.&=|><\+\-\*\(\)\/])).*/gi,"")+";"});return function(b,d){var e;if(!(b in N))if(N[b]=!1,d&&(e=b.match(a)))N[b]=e[1]*Q[e[2]];else try{N[b]=new Function("e",c(b))(Q)}catch(f){}return N[b]}}(),aa=function(a,b){return a.w?(a.cWidth=t.calcListLength(b||"100vw"),a.res=a.w/a.cWidth):a.res=a.d,a},ba=function(a){var c,d,e,f=a||{};if(f.elements&&1===f.elements.nodeType&&("IMG"===f.elements.nodeName.toUpperCase()?f.elements=[f.elements]:(f.context=f.elements,f.elements=null)),c=f.elements||t.qsa(f.context||b,f.reevaluate||f.reselect?t.sel:t.selShort),e=c.length){for(t.setupRun(f),S=!0,d=0;e>d;d++)t.fillImg(c[d],f);t.teardownRun(f)}};o=a.console&&console.warn?function(a){console.warn(a)}:u,G in v||(G="src"),A["image/jpeg"]=!0,A["image/gif"]=!0,A["image/png"]=!0,A["image/svg+xml"]=b.implementation.hasFeature("http://wwwindow.w3.org/TR/SVG11/feature#Image","1.1"),A["image/webp"]=e("image/webp","data:image/webp;base64,UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAABBxAR/Q9ERP8DAABWUDggGAAAADABAJ0BKgEAAQADADQlpAADcAD++/1QAA=="),t.ns=("pf"+(new Date).getTime()).substr(0,9),t.supSrcset="srcset"in v,t.supSizes="sizes"in v,t.selShort="picture>img,img[srcset]",t.sel=t.selShort,t.cfg=B,t.supSrcset&&(t.sel+=",img["+D+"]"),t.DPR=P||1,t.u=Q,t.types=A,q=t.supSrcset&&!t.supSizes,t.setSize=u,t.makeUrl=$(function(a){return R.href=a,R.href}),t.qsa=function(a,b){return a.querySelectorAll(b)},t.matchesMedia=function(){return a.matchMedia&&(matchMedia("(min-width: 0.1em)")||{}).matches?t.matchesMedia=function(a){return!a||matchMedia(a).matches}:t.matchesMedia=t.mMQ,t.matchesMedia.apply(this,arguments)},t.mMQ=function(a){return a?_(a):!0},t.calcLength=function(a){var b=_(a,!0)||!1;return 0>b&&(b=!1),b},t.supportsType=function(a){return a?A[a]:!0},t.parseSize=$(function(a){var b=(a||"").match(I);return{media:b&&b[1],length:b&&b[2]}}),t.parseSet=function(a){return a.cands||(a.cands=m(a.srcset,a)),a.cands},t.getEmValue=function(){var a;if(!p&&(a=b.body)){var c=b.createElement("div"),d=z.style.cssText,e=a.style.cssText;c.style.cssText=K,z.style.cssText=L,a.style.cssText=L,a.appendChild(c),p=c.offsetWidth,a.removeChild(c),p=parseFloat(p,10),z.style.cssText=d,a.style.cssText=e}return p||16},t.calcListLength=function(a){if(!(a in O)||B.uT){var b=t.calcLength(n(a));O[a]=b?b:Q.width}return O[a]},t.setRes=function(a){var b;if(a){b=t.parseSet(a);for(var c=0,d=b.length;d>c;c++)aa(b[c],a.sizes)}return b},t.setRes.res=aa,t.applySetCandidate=function(a,b){if(a.length){var c,d,e,f,h,k,l,m,n,o,p=b[t.ns],q=t.DPR;if(k=p.curSrc||b[G],l=p.curCan||j(b,k,a[0].set),l&&l.set===a[0].set&&(o=F&&!b.complete&&l.res-.1>q,o||(l.cached=!0,l&&m&&l.res>=q&&(h=l))),!h)for(a.sort(i),f=a.length,h=a[f-1],d=0;f>d;d++)if(c=a[d],c.res>=q){e=d-1,h=a[e]&&(o||k!==t.makeUrl(c.url))&&g(a[e].res,c.res,q,a[e].cached)?a[e]:c;break}h&&(n=t.makeUrl(h.url),p.curSrc=n,p.curCan=h,n!==k&&t.setSrc(b,h),t.setSize(b))}},t.setSrc=function(a,b){var c;a.src=b.url,"image/svg+xml"===b.set.type&&(c=a.style.width,a.style.width=a.offsetWidth+1+"px",a.offsetWidth+1&&(a.style.width=c))},t.getSet=function(a){var b,c,d,e=!1,f=a[t.ns].sets;for(b=0;b2.7?h=c+1:(f=b-c,e=Math.pow(a-.6,1.5),g=f*e,d&&(g+=.1*e),h=a+g):h=c>1?Math.sqrt(a*b):a,h>c}function h(a){var b,c=t.getSet(a),d=!1;"pending"!==c&&(d=s,c&&(b=t.setRes(c),t.applySetCandidate(b,a))),a[t.ns].evaled=d}function i(a,b){return a.res-b.res}function j(a,b,c){var d;return!c&&b&&(c=a[t.ns].sets,c=c&&c[c.length-1]),d=k(b,c),d&&(b=t.makeUrl(b),a[t.ns].curSrc=b,a[t.ns].curCan=d,d.res||aa(d,d.set.sizes)),d}function k(a,b){var c,d,e;if(a&&b)for(e=t.parseSet(b),a=t.makeUrl(a),c=0;cc;c++)e=g[c],e[t.ns]=!0,f=e.getAttribute("srcset"),f&&b.push({srcset:f,media:e.getAttribute("media"),type:e.getAttribute("type"),sizes:e.getAttribute("sizes")})}function m(a,b){function c(b){var c,d=b.exec(a.substring(m));return d?(c=d[0],m+=c.length,c):void 0}function e(){var a,c,d,e,f,i,j,k,l,m=!1,o={};for(e=0;el?m=!0:c=l):X.test(j)&&"h"===i?((d||c)&&(m=!0),0===k?m=!0:d=k):m=!0;m||(o.url=g,a&&(o.w=a),c&&(o.d=c),d&&(o.h=d),d||c||a||(o.d=1),1===o.d&&(b.has1x=!0),o.set=b,n.push(o))}function f(){for(c(T),i="",j="in descriptor";;){if(k=a.charAt(m),"in descriptor"===j)if(d(k))i&&(h.push(i),i="",j="after descriptor");else{if(","===k)return m+=1,i&&h.push(i),void e();if("("===k)i+=k,j="in parens";else{if(""===k)return i&&h.push(i),void e();i+=k}}else if("in parens"===j)if(")"===k)i+=k,j="in descriptor";else{if(""===k)return h.push(i),void e();i+=k}else if("after descriptor"===j)if(d(k));else{if(""===k)return void e();j="in descriptor",m-=1}m+=1}}for(var g,h,i,j,k,l=a.length,m=0,n=[];;){if(c(U),m>=l)return n;g=c(V),h=[],","===g.slice(-1)?(g=g.replace(W,""),e()):f()}}function n(a){function b(a){function b(){g&&(h.push(g),g="")}function e(){h[0]&&(i.push(h),h=[])}for(var f,g="",h=[],i=[],j=0,k=0,l=!1;;){if(f=a[k],f===c)return b(),e(),i;if(l){if("*"===f&&"/"===a[k+1]){l=!1,k+=2,b();continue}k+=1}else{if(d(f)){if(a[k-1]&&d(a[k-1])||!g){k+=1;continue}if(0===j){b(),k+=1;continue}f=" "}else if("("===f)j+=1;else if(")"===f)j-=1;else{if(","===f){b(),e(),k+=1;continue}if("/"===f&&"*"===a[k+1]){l=!0,k+=2;continue}}g+=f,k+=1}}}function e(a){return l.test(a)&&parseFloat(a)>=0?!0:m.test(a)?!0:"0"===a||"-0"===a||"+0"===a?!0:!1}var f,g,h,i,j,k,l=/^(?:[+-]?[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?(?:ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmin|vmax|vw)$/i,m=/^calc\((?:[0-9a-z \.\+\-\*\/\(\)]+)\)$/i;for(g=b(a),h=g.length,f=0;h>f;f++)if(i=g[f],j=i[i.length-1],e(j)){if(k=j,i.pop(),0===i.length)return k;if(i=i.join(" "),t.matchesMedia(i))return k}return"100vw"}b.createElement("picture");var o,p,q,r,s,t={},u=function(){},v=b.createElement("img"),w=v.getAttribute,x=v.setAttribute,y=v.removeAttribute,z=b.documentElement,A={},B={algorithm:""},C="data-pfsrc",D=C+"set",E=navigator.userAgent,F=/rident/.test(E)||/ecko/.test(E)&&E.match(/rv\:(\d+)/)&&RegExp.$1>35,G="currentSrc",H=/\s+\+?\d+(e\d+)?w/,I=/(\([^)]+\))?\s*(.+)/,J=a.picturefillCFG,K="position:absolute;left:0;visibility:hidden;display:block;padding:0;border:none;font-size:1em;width:1em;overflow:hidden;clip:rect(0px, 0px, 0px, 0px)",L="font-size:100%!important;",M=!0,N={},O={},P=a.devicePixelRatio,Q={px:1,"in":96},R=b.createElement("a"),S=!1,T=/^[ \t\n\r\u000c]+/,U=/^[, \t\n\r\u000c]+/,V=/^[^ \t\n\r\u000c]+/,W=/[,]+$/,X=/^\d+$/,Y=/^-?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/,Z=function(a,b,c,d){a.addEventListener?a.addEventListener(b,c,d||!1):a.attachEvent&&a.attachEvent("on"+b,c)},$=function(a){var b={};return function(c){return c in b||(b[c]=a(c)),b[c]}},_=function(){var a=/^([\d\.]+)(em|vw|px)$/,b=function(){for(var a=arguments,b=0,c=a[0];++b in a;)c=c.replace(a[b],a[++b]);return c},c=$(function(a){return"return "+b((a||"").toLowerCase(),/\band\b/g,"&&",/,/g,"||",/min-([a-z-\s]+):/g,"e.$1>=",/max-([a-z-\s]+):/g,"e.$1<=",/calc([^)]+)/g,"($1)",/(\d+[\.]*[\d]*)([a-z]+)/g,"($1 * e.$2)",/^(?!(e.[a-z]|[0-9\.&=|><\+\-\*\(\)\/])).*/gi,"")+";"});return function(b,d){var e;if(!(b in N))if(N[b]=!1,d&&(e=b.match(a)))N[b]=e[1]*Q[e[2]];else try{N[b]=new Function("e",c(b))(Q)}catch(f){}return N[b]}}(),aa=function(a,b){return a.w?(a.cWidth=t.calcListLength(b||"100vw"),a.res=a.w/a.cWidth):a.res=a.d,a},ba=function(a){var c,d,e,f=a||{};if(f.elements&&1===f.elements.nodeType&&("IMG"===f.elements.nodeName.toUpperCase()?f.elements=[f.elements]:(f.context=f.elements,f.elements=null)),c=f.elements||t.qsa(f.context||b,f.reevaluate||f.reselect?t.sel:t.selShort),e=c.length){for(t.setupRun(f),S=!0,d=0;e>d;d++)t.fillImg(c[d],f);t.teardownRun(f)}};o=a.console&&console.warn?function(a){console.warn(a)}:u,G in v||(G="src"),A["image/jpeg"]=!0,A["image/gif"]=!0,A["image/png"]=!0,A["image/svg+xml"]=b.implementation.hasFeature("http://wwwindow.w3.org/TR/SVG11/feature#Image","1.1"),t.ns=("pf"+(new Date).getTime()).substr(0,9),t.supSrcset="srcset"in v,t.supSizes="sizes"in v,t.selShort="picture>img,img[srcset]",t.sel=t.selShort,t.cfg=B,t.supSrcset&&(t.sel+=",img["+D+"]"),t.DPR=P||1,t.u=Q,t.types=A,q=t.supSrcset&&!t.supSizes,t.setSize=u,t.makeUrl=$(function(a){return R.href=a,R.href}),t.qsa=function(a,b){return a.querySelectorAll(b)},t.matchesMedia=function(){return a.matchMedia&&(matchMedia("(min-width: 0.1em)")||{}).matches?t.matchesMedia=function(a){return!a||matchMedia(a).matches}:t.matchesMedia=t.mMQ,t.matchesMedia.apply(this,arguments)},t.mMQ=function(a){return a?_(a):!0},t.calcLength=function(a){var b=_(a,!0)||!1;return 0>b&&(b=!1),b},t.supportsType=function(a){return a?A[a]:!0},t.parseSize=$(function(a){var b=(a||"").match(I);return{media:b&&b[1],length:b&&b[2]}}),t.parseSet=function(a){return a.cands||(a.cands=m(a.srcset,a)),a.cands},t.getEmValue=function(){var a;if(!p&&(a=b.body)){var c=b.createElement("div"),d=z.style.cssText,e=a.style.cssText;c.style.cssText=K,z.style.cssText=L,a.style.cssText=L,a.appendChild(c),p=c.offsetWidth,a.removeChild(c),p=parseFloat(p,10),z.style.cssText=d,a.style.cssText=e}return p||16},t.calcListLength=function(a){if(!(a in O)||B.uT){var b=t.calcLength(n(a));O[a]=b?b:Q.width}return O[a]},t.setRes=function(a){var b;if(a){b=t.parseSet(a);for(var c=0,d=b.length;d>c;c++)aa(b[c],a.sizes)}return b},t.setRes.res=aa,t.applySetCandidate=function(a,b){if(a.length){var c,d,e,f,h,k,l,m,n,o,p=b[t.ns],q=t.DPR;if(k=p.curSrc||b[G],l=p.curCan||j(b,k,a[0].set),l&&l.set===a[0].set&&(o=F&&!b.complete&&l.res-.1>q,o||(l.cached=!0,l&&m&&l.res>=q&&(h=l))),!h)for(a.sort(i),f=a.length,h=a[f-1],d=0;f>d;d++)if(c=a[d],c.res>=q){e=d-1,h=a[e]&&(o||k!==t.makeUrl(c.url))&&g(a[e].res,c.res,q,a[e].cached)?a[e]:c;break}h&&(n=t.makeUrl(h.url),p.curSrc=n,p.curCan=h,n!==k&&t.setSrc(b,h),t.setSize(b))}},t.setSrc=function(a,b){var c;a.src=b.url,"image/svg+xml"===b.set.type&&(c=a.style.width,a.style.width=a.offsetWidth+1+"px",a.offsetWidth+1&&(a.style.width=c))},t.getSet=function(a){var b,c,d,e=!1,f=a[t.ns].sets;for(b=0;b