From 109be771701145e11a477f32aff7321a66606891 Mon Sep 17 00:00:00 2001 From: aFarkas Date: Thu, 25 Sep 2014 10:24:03 +0200 Subject: [PATCH] matchesMedia proposal --- dist/picturefill.js | 70 ++++++++++------------------------------- dist/picturefill.min.js | 4 +-- gruntfile.js | 2 +- src/picturefill.js | 22 +++++++++---- 4 files changed, 36 insertions(+), 62 deletions(-) diff --git a/dist/picturefill.js b/dist/picturefill.js index ccc6f1c0..3941d5e9 100644 --- a/dist/picturefill.js +++ b/dist/picturefill.js @@ -1,52 +1,6 @@ -/*! Picturefill - v2.1.0 - 2014-09-24 +/*! Picturefill - v2.1.0 - 2014-09-25 * http://scottjehl.github.io/picturefill * Copyright (c) 2014 https://github.com/scottjehl/picturefill/blob/master/Authors.txt; Licensed MIT */ -/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas, David Knight. Dual MIT/BSD license */ - -window.matchMedia || (window.matchMedia = function() { - "use strict"; - - // For browsers that support matchMedium api such as IE 9 and webkit - var styleMedia = (window.styleMedia || window.media); - - // For those that don't support matchMedium - if (!styleMedia) { - var style = document.createElement('style'), - script = document.getElementsByTagName('script')[0], - info = null; - - style.type = 'text/css'; - style.id = 'matchmediajs-test'; - - script.parentNode.insertBefore(style, script); - - // 'style.currentStyle' is used by IE <= 8 and 'window.getComputedStyle' for all other browsers - info = ('getComputedStyle' in window) && window.getComputedStyle(style, null) || style.currentStyle; - - styleMedia = { - matchMedium: function(media) { - var text = '@media ' + media + '{ #matchmediajs-test { width: 1px; } }'; - - // 'style.styleSheet' is used by IE <= 8 and 'style.textContent' for all other browsers - if (style.styleSheet) { - style.styleSheet.cssText = text; - } else { - style.textContent = text; - } - - // Test if media query is true or false - return info.width === '1px'; - } - }; - } - - return function(media) { - return { - matches: styleMedia.matchMedium(media || 'all'), - media: media || 'all' - }; - }; -}()); /*! Picturefill - Responsive Images that work today. * Author: Scott Jehl, Filament Group, 2012 ( new proposal implemented by Shawn Jansepar ) * License: MIT/GPLv2 @@ -124,8 +78,22 @@ window.matchMedia || (window.matchMedia = function() { /** * Shortcut method for matchMedia ( for easy overriding in tests ) */ - pf.matchesMedia = function( media ) { - return !media || ( w.matchMedia && w.matchMedia( media ).matches ); + var matchMediaTest = "(min-width: 0.1em)"; + var Mod = w.Modernizr; + pf.matchesMedia = function() { + if ( w.matchMedia && w.matchMedia( matchMediaTest).matches ) { + pf.matchesMedia = function( media ) { + return !media || ( w.matchMedia( media ).matches ); + }; + } else if ( Mod && Mod.mq && Mod.mq( matchMediaTest ) ) { + pf.matchesMedia = function( media ) { + return !media || ( Mod.mq( matchMediaTest ) ); + }; + } else { + pf.matchesMedia = pf.mMQ; + } + + return pf.matchesMedia.apply( this, arguments ); }; pf.vW = 0; @@ -175,10 +143,6 @@ window.matchMedia || (window.matchMedia = function() { return ret; }; - if ( !pf.matchesMedia( "(min-width: 0.1em)" ) ) { - pf.matchesMedia = pf.mMQ; - } - /** * Shortcut property for `devicePixelRatio` ( for easy overriding in tests ) */ diff --git a/dist/picturefill.min.js b/dist/picturefill.min.js index 6288176d..f7466c3f 100644 --- a/dist/picturefill.min.js +++ b/dist/picturefill.min.js @@ -1,4 +1,4 @@ -/*! Picturefill - v2.1.0 - 2014-09-24 +/*! Picturefill - v2.1.0 - 2014-09-25 * http://scottjehl.github.io/picturefill * Copyright (c) 2014 https://github.com/scottjehl/picturefill/blob/master/Authors.txt; Licensed MIT */ -window.matchMedia||(window.matchMedia=function(){"use strict";var a=window.styleMedia||window.media;if(!a){var b=document.createElement("style"),c=document.getElementsByTagName("script")[0],d=null;b.type="text/css",b.id="matchmediajs-test",c.parentNode.insertBefore(b,c),d="getComputedStyle"in window&&window.getComputedStyle(b,null)||b.currentStyle,a={matchMedium:function(a){var c="@media "+a+"{ #matchmediajs-test { width: 1px; } }";return b.styleSheet?b.styleSheet.cssText=c:b.textContent=c,"1px"===d.width}}}return function(b){return{matches:a.matchMedium(b||"all"),media:b||"all"}}}()),function(a,b){"use strict";function c(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")}function d(){m.vW=a.innerWidth||p.clientWidth}function e(a){if(!(a in B)){var b={val:1,type:"x"},d=c(a||"");d&&(d.match(C)?(b.val=1*RegExp.$1,b.type=RegExp.$2):b=!1),B[a]=b}return B[a]}function f(a,c,d){var e=b.createElement("img");a[m.ns].loadGC=function(){a&&(a[m.ns].loadGC=null,a=null,e=null)},e.onload=function(){a&&(d(),m.addDimensions(a,e,c),a[m.ns].loadGC())},e.onerror=a[m.ns].loadGC,e.onabort=a[m.ns].loadGC,e.src=c.url}function g(a,b){return a.res-b.res}function h(a,b){var c,d,e,f,g=a.getElementsByTagName("source");for(c=0,d=g.length;d>c;c++)e=g[c],f=e.getAttribute("srcset"),f&&b.push({srcset:f,media:e.getAttribute("media"),type:e.getAttribute("type"),sizes:e.getAttribute("sizes")})}b.createElement("picture");var i,j,k,l,m={},n=function(){},o=b.createElement("img"),p=b.documentElement,q={};m.ns=("pf"+(new Date).getTime()).substr(0,9),k="data-pfsrcset",l="currentSrc"in o,m.isReady=!1,m.srcsetSupported="srcset"in o,m.sizesSupported="sizes"in o,m.shortSelector="picture > img, img[srcset]",m.selector=m.shortSelector,m.options={resQuantifier:1},m.srcsetSupported&&(m.selector+=", img["+m.srcsetAttr+"]");var r=b.createElement("a");m.makeUrl=function(a){return r.href=a,r.href},m.qsa=function(a,b){return a.querySelectorAll(b)};var s=a.console&&"function"==typeof console.warn?function(a){console.warn(a)}:n;m.isSSL="https:"===a.location.protocol,m.matchesMedia=function(b){return!b||a.matchMedia&&a.matchMedia(b).matches},m.vW=0;var t={minw:/\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/,maxw:/\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/},u={};m.mMQ=function(a){var b,c,d=!1;return a?(u[a]||(b=a.match(t.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),c=a.match(t.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),b&&(b=parseFloat(b,10)*(b.indexOf("em")>0?m.getEmValue():1)),c&&(c=parseFloat(c,10)*(c.indexOf("em")>0?m.getEmValue():1)),u[a]={min:b,max:c}),b=u[a].min,c=u[a].max,(b&&m.vW>=b||c&&m.vW<=c)&&(d=!0),d):!0},m.matchesMedia("(min-width: 0.1em)")||(m.matchesMedia=m.mMQ),m.DPR=a.devicePixelRatio||1;var v={},w=/^([\d\.\-]+)(em|vw|px|%)$/,x="position: absolute; left: 0; visibility: hidden; display: block; padding: 0; margin: 0; border: none;font-size:1em;width:1em;";m.calcLength=function(a){var c,d,e=a,f=!1;if(!(e in v)){if(d=a.match(w))d[1]=parseFloat(d[1],10),f=!d[1]||d[1]<=0||"%"===d[2]?!1:"vw"===d[2]?m.vW*d[1]/100:"em"===d[2]?m.getEmValue()*d[1]:d[1];else if(a.indexOf("calc")>-1||parseInt(a,10)){a=a.replace("vw","%"),j||(j=b.createElement("div"),j.style.cssText=x),i||(i=!0,p.insertBefore(j,p.firstChild)),j.style.width=0;try{j.style.width=a}catch(g){c=!0}f=j.offsetWidth,(c||0>=f)&&(f=!1)}v[e]=f}return v[e]},m.types=q,q["image/jpeg"]=!0,q["image/gif"]=!0,q["image/png"]=!0,q["image/svg+xml"]=b.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1"),m.createImageTest=function(a,c){var d=b.createElement("img"),e=function(){m.isReady&&m.fillImgs(),d=null};q[a]="pending",d.onerror=function(){q[a]=!1,e()},d.onload=function(){q[a]=1===d.width,e()},d.src=c},m.verifyTypeSupport=function(a){return a?q[a]:!0};var y=/(\([^)]+\))?\s*(.+)/,z={};m.parseSize=function(a){var b;return z[a]||(b=(a||"").match(y),z[a]={media:b&&b[1],length:b&&b[2]}),z[a]},m.parseSet=function(a){if(!a.candidates){var b,c,d,f,g,h=a.srcset;for(a.candidates=[];h;)h=h.replace(/^\s+/g,""),b=h.search(/\s/g),d=null,-1!==b?(c=h.slice(0,b),f=c.charAt(c.length-1),(","===f||""===c)&&(c=c.replace(/,+$/,""),d=""),h=h.slice(b+1),null===d&&(g=h.indexOf(","),-1!==g?(d=h.slice(0,g),h=h.slice(g+1)):(d=h,h=""))):(c=h,h=""),c&&(d=e(d))&&a.candidates.push({url:c.replace(/^,+/,""),desc:d,set:a})}return a.candidates};var A,B={},C=/^([e\d\.]+)(w|x)$/;m.getEmValue=function(){if(!A&&b.body){var a=b.createElement("div"),c=b.body,d=p.style.fontSize,e=c&&c.style.fontSize;a.style.cssText=x,p.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(a),A=a.offsetWidth,c.removeChild(a),A=parseFloat(A,10),p.style.fontSize=d,c.style.fontSize=e}return A||16},m.calcLengthFromList=function(a){var b,d,e,f,g,h,i=c(a).split(/\s*,\s*/),j=!1;for(g=0,h=i.length;h>g&&(b=i[g],d=m.parseSize(b),e=d.length,f=d.media,!e||!m.matchesMedia(f)||(j=m.calcLength(e))===!1);g++);return j===!1?m.vW:j},m.setResolution=function(a,b){var c=a.desc;return"w"===c.type?(a.cWidth=m.calcLengthFromList(b||"100vw"),a.res=c.val/a.cWidth):a.res=c.val,a},m.prepareCandidates=function(a){var b,c;if(a){b=m.parseSet(a);for(var d=0,e=b.length;e>d;d++)c=b[d],c.descriptor&&c.descriptor.skip||m.setResolution(c,a.sizes)}return b},m.applyCandidateFromSet=function(a,b){var c,d,e,f,h,i=m.DPR*m.options.resQuantifier,j=b[m.ns].curCandidate;if(!(j&&a[0]&&j.set===a[0].set&&j.res>=i)){a.sort(g),d=a.length,e=a[d-1];for(var k=0;d>k;k++)if(c=a[k],c.res>=i){e=c;break}f=b[m.ns].curSrc||b.currentSrc||b.src,e&&((h=m.makeUrl(e.url))!==f?m.isSSL&&!e.url.indexOf("http:")?s("insecure: "+h):m.loadImg(b,e,h):"w"===e.desc.type&&m.addDimensions(b,null,e))}},m.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))},m.loadImg=function(a,b,c){var d=a[m.ns].loadGC,e=!a.complete||!a.getAttribute("src"),g=!1,h=function(){g||(g=!0,m.setSrc(a,b))};d&&d(),l||(a.currentSrc=c),a[m.ns].curSrc=c,a[m.ns].curCandidate=b,(m.options.addDimensions||!e)&&f(a,b,h),e&&h()},m.addDimensions=function(a,b,c){m.options.addDimensions&&!a[m.ns].dims&&(b&&(a[m.ns].nW=b.naturalWidth||b.width,a[m.ns].nH=b.naturalHeight||b.height),"x"===c.desc.type?a.setAttribute("width",parseInt(a[m.ns].nW/c.res/m.options.resQuantifier,10)):"w"===c.desc.type&&a.setAttribute("width",parseInt(c.cWidth,10)))},m.applyBestCandidate=function(a){var b,c=m.getSet(a);"pending"!==c&&(c&&(b=m.prepareCandidates(c),m.applyCandidateFromSet(b,a)),a[m.ns].evaluated=!0)},m.getSet=function(a){var b,c,d,e=!1,f=a[m.ns].sets;for(b=0;bd;d++)m.fillImg(c[d],g);m.teardownRun(g)}};a.HTMLPictureElement&&(G=n,m.fillImg=n),G._=m,m.fillImgs=G,G.setOptions=function(a,b){m.options[a]!==b&&(m.options[a]=b,F&&m.fillImgs({reevaluate:!0}))},a.HTMLPictureElement||(!function(){var c=a.attachEvent?/^loade|^c/:/^loade|^c|^i/,d=function(){b.body&&(c.test(b.readyState||"")&&(clearInterval(e),m.isReady=!0),m.fillImgs())},e=setInterval(d,333),f=function(){m.fillImgs({reevaluate:!0})},g=function(){a.clearTimeout(E),E=a.setTimeout(f,99)};a.addEventListener?a.addEventListener("resize",g,!1):a.attachEvent&&a.attachEvent("onresize",g),setTimeout(d,b.body?9:99)}(),d(),m.createImageTest("image/webp","data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=")),"object"==typeof module&&"object"==typeof module.exports?module.exports=G:"function"==typeof define&&define.amd?(a.picturefill=G,define(function(){return G})):"object"==typeof a&&(a.picturefill=G)}(this,this.document); \ No newline at end of file +!function(a,b){"use strict";function c(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")}function d(){m.vW=a.innerWidth||p.clientWidth}function e(a){if(!(a in D)){var b={val:1,type:"x"},d=c(a||"");d&&(d.match(E)?(b.val=1*RegExp.$1,b.type=RegExp.$2):b=!1),D[a]=b}return D[a]}function f(a,c,d){var e=b.createElement("img");a[m.ns].loadGC=function(){a&&(a[m.ns].loadGC=null,a=null,e=null)},e.onload=function(){a&&(d(),m.addDimensions(a,e,c),a[m.ns].loadGC())},e.onerror=a[m.ns].loadGC,e.onabort=a[m.ns].loadGC,e.src=c.url}function g(a,b){return a.res-b.res}function h(a,b){var c,d,e,f,g=a.getElementsByTagName("source");for(c=0,d=g.length;d>c;c++)e=g[c],f=e.getAttribute("srcset"),f&&b.push({srcset:f,media:e.getAttribute("media"),type:e.getAttribute("type"),sizes:e.getAttribute("sizes")})}b.createElement("picture");var i,j,k,l,m={},n=function(){},o=b.createElement("img"),p=b.documentElement,q={};m.ns=("pf"+(new Date).getTime()).substr(0,9),k="data-pfsrcset",l="currentSrc"in o,m.isReady=!1,m.srcsetSupported="srcset"in o,m.sizesSupported="sizes"in o,m.shortSelector="picture > img, img[srcset]",m.selector=m.shortSelector,m.options={resQuantifier:1},m.srcsetSupported&&(m.selector+=", img["+m.srcsetAttr+"]");var r=b.createElement("a");m.makeUrl=function(a){return r.href=a,r.href},m.qsa=function(a,b){return a.querySelectorAll(b)};var s=a.console&&"function"==typeof console.warn?function(a){console.warn(a)}:n;m.isSSL="https:"===a.location.protocol;var t="(min-width: 0.1em)",u=a.Modernizr;m.matchesMedia=function(){return m.matchesMedia=a.matchMedia&&a.matchMedia(t).matches?function(b){return!b||a.matchMedia(b).matches}:u&&u.mq&&u.mq(t)?function(a){return!a||u.mq(t)}:m.mMQ,m.matchesMedia.apply(this,arguments)},m.vW=0;var v={minw:/\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/,maxw:/\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/},w={};m.mMQ=function(a){var b,c,d=!1;return a?(w[a]||(b=a.match(v.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),c=a.match(v.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),b&&(b=parseFloat(b,10)*(b.indexOf("em")>0?m.getEmValue():1)),c&&(c=parseFloat(c,10)*(c.indexOf("em")>0?m.getEmValue():1)),w[a]={min:b,max:c}),b=w[a].min,c=w[a].max,(b&&m.vW>=b||c&&m.vW<=c)&&(d=!0),d):!0},m.DPR=a.devicePixelRatio||1;var x={},y=/^([\d\.\-]+)(em|vw|px|%)$/,z="position: absolute; left: 0; visibility: hidden; display: block; padding: 0; margin: 0; border: none;font-size:1em;width:1em;";m.calcLength=function(a){var c,d,e=a,f=!1;if(!(e in x)){if(d=a.match(y))d[1]=parseFloat(d[1],10),f=!d[1]||d[1]<=0||"%"===d[2]?!1:"vw"===d[2]?m.vW*d[1]/100:"em"===d[2]?m.getEmValue()*d[1]:d[1];else if(a.indexOf("calc")>-1||parseInt(a,10)){a=a.replace("vw","%"),j||(j=b.createElement("div"),j.style.cssText=z),i||(i=!0,p.insertBefore(j,p.firstChild)),j.style.width=0;try{j.style.width=a}catch(g){c=!0}f=j.offsetWidth,(c||0>=f)&&(f=!1)}x[e]=f}return x[e]},m.types=q,q["image/jpeg"]=!0,q["image/gif"]=!0,q["image/png"]=!0,q["image/svg+xml"]=b.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1"),m.createImageTest=function(a,c){var d=b.createElement("img"),e=function(){m.isReady&&m.fillImgs(),d=null};q[a]="pending",d.onerror=function(){q[a]=!1,e()},d.onload=function(){q[a]=1===d.width,e()},d.src=c},m.verifyTypeSupport=function(a){return a?q[a]:!0};var A=/(\([^)]+\))?\s*(.+)/,B={};m.parseSize=function(a){var b;return B[a]||(b=(a||"").match(A),B[a]={media:b&&b[1],length:b&&b[2]}),B[a]},m.parseSet=function(a){if(!a.candidates){var b,c,d,f,g,h=a.srcset;for(a.candidates=[];h;)h=h.replace(/^\s+/g,""),b=h.search(/\s/g),d=null,-1!==b?(c=h.slice(0,b),f=c.charAt(c.length-1),(","===f||""===c)&&(c=c.replace(/,+$/,""),d=""),h=h.slice(b+1),null===d&&(g=h.indexOf(","),-1!==g?(d=h.slice(0,g),h=h.slice(g+1)):(d=h,h=""))):(c=h,h=""),c&&(d=e(d))&&a.candidates.push({url:c.replace(/^,+/,""),desc:d,set:a})}return a.candidates};var C,D={},E=/^([e\d\.]+)(w|x)$/;m.getEmValue=function(){if(!C&&b.body){var a=b.createElement("div"),c=b.body,d=p.style.fontSize,e=c&&c.style.fontSize;a.style.cssText=z,p.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(a),C=a.offsetWidth,c.removeChild(a),C=parseFloat(C,10),p.style.fontSize=d,c.style.fontSize=e}return C||16},m.calcLengthFromList=function(a){var b,d,e,f,g,h,i=c(a).split(/\s*,\s*/),j=!1;for(g=0,h=i.length;h>g&&(b=i[g],d=m.parseSize(b),e=d.length,f=d.media,!e||!m.matchesMedia(f)||(j=m.calcLength(e))===!1);g++);return j===!1?m.vW:j},m.setResolution=function(a,b){var c=a.desc;return"w"===c.type?(a.cWidth=m.calcLengthFromList(b||"100vw"),a.res=c.val/a.cWidth):a.res=c.val,a},m.prepareCandidates=function(a){var b,c;if(a){b=m.parseSet(a);for(var d=0,e=b.length;e>d;d++)c=b[d],c.descriptor&&c.descriptor.skip||m.setResolution(c,a.sizes)}return b},m.applyCandidateFromSet=function(a,b){var c,d,e,f,h,i=m.DPR*m.options.resQuantifier,j=b[m.ns].curCandidate;if(!(j&&a[0]&&j.set===a[0].set&&j.res>=i)){a.sort(g),d=a.length,e=a[d-1];for(var k=0;d>k;k++)if(c=a[k],c.res>=i){e=c;break}f=b[m.ns].curSrc||b.currentSrc||b.src,e&&((h=m.makeUrl(e.url))!==f?m.isSSL&&!e.url.indexOf("http:")?s("insecure: "+h):m.loadImg(b,e,h):"w"===e.desc.type&&m.addDimensions(b,null,e))}},m.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))},m.loadImg=function(a,b,c){var d=a[m.ns].loadGC,e=!a.complete||!a.getAttribute("src"),g=!1,h=function(){g||(g=!0,m.setSrc(a,b))};d&&d(),l||(a.currentSrc=c),a[m.ns].curSrc=c,a[m.ns].curCandidate=b,(m.options.addDimensions||!e)&&f(a,b,h),e&&h()},m.addDimensions=function(a,b,c){m.options.addDimensions&&!a[m.ns].dims&&(b&&(a[m.ns].nW=b.naturalWidth||b.width,a[m.ns].nH=b.naturalHeight||b.height),"x"===c.desc.type?a.setAttribute("width",parseInt(a[m.ns].nW/c.res/m.options.resQuantifier,10)):"w"===c.desc.type&&a.setAttribute("width",parseInt(c.cWidth,10)))},m.applyBestCandidate=function(a){var b,c=m.getSet(a);"pending"!==c&&(c&&(b=m.prepareCandidates(c),m.applyCandidateFromSet(b,a)),a[m.ns].evaluated=!0)},m.getSet=function(a){var b,c,d,e=!1,f=a[m.ns].sets;for(b=0;bd;d++)m.fillImg(c[d],g);m.teardownRun(g)}};a.HTMLPictureElement&&(I=n,m.fillImg=n),I._=m,m.fillImgs=I,I.setOptions=function(a,b){m.options[a]!==b&&(m.options[a]=b,H&&m.fillImgs({reevaluate:!0}))},a.HTMLPictureElement||(!function(){var c=a.attachEvent?/^loade|^c/:/^loade|^c|^i/,d=function(){b.body&&(c.test(b.readyState||"")&&(clearInterval(e),m.isReady=!0),m.fillImgs())},e=setInterval(d,333),f=function(){m.fillImgs({reevaluate:!0})},g=function(){a.clearTimeout(G),G=a.setTimeout(f,99)};a.addEventListener?a.addEventListener("resize",g,!1):a.attachEvent&&a.attachEvent("onresize",g),setTimeout(d,b.body?9:99)}(),d(),m.createImageTest("image/webp","data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=")),"object"==typeof module&&"object"==typeof module.exports?module.exports=I:"function"==typeof define&&define.amd?(a.picturefill=I,define(function(){return I})):"object"==typeof a&&(a.picturefill=I)}(this,this.document); \ No newline at end of file diff --git a/gruntfile.js b/gruntfile.js index 8bf2946f..5b968a4d 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -25,7 +25,7 @@ stripBanners: true }, dist: { - src: [ "src/external/matchmedia.js", "src/picturefill.js" ], + src: [ "src/picturefill.js" ], dest: "dist/picturefill.js" } }, diff --git a/src/picturefill.js b/src/picturefill.js index 7e54aea4..ff4442b3 100644 --- a/src/picturefill.js +++ b/src/picturefill.js @@ -75,8 +75,22 @@ /** * Shortcut method for matchMedia ( for easy overriding in tests ) */ - pf.matchesMedia = function( media ) { - return !media || ( w.matchMedia && w.matchMedia( media ).matches ); + var matchMediaTest = "(min-width: 0.1em)"; + var Mod = w.Modernizr; + pf.matchesMedia = function() { + if ( w.matchMedia && w.matchMedia( matchMediaTest).matches ) { + pf.matchesMedia = function( media ) { + return !media || ( w.matchMedia( media ).matches ); + }; + } else if ( Mod && Mod.mq && Mod.mq( matchMediaTest ) ) { + pf.matchesMedia = function( media ) { + return !media || ( Mod.mq( matchMediaTest ) ); + }; + } else { + pf.matchesMedia = pf.mMQ; + } + + return pf.matchesMedia.apply( this, arguments ); }; pf.vW = 0; @@ -126,10 +140,6 @@ return ret; }; - if ( !pf.matchesMedia( "(min-width: 0.1em)" ) ) { - pf.matchesMedia = pf.mMQ; - } - /** * Shortcut property for `devicePixelRatio` ( for easy overriding in tests ) */