From 52de779c13994cb402ac287dcf47dafb5462e595 Mon Sep 17 00:00:00 2001 From: scottjehl Date: Thu, 22 Mar 2012 13:32:48 +0530 Subject: [PATCH] matchmedia and media query support should not be required for picturefill to run - source elements with no media attributes or media attributes specifying media types (but not queries) do not require media query support. For media attribute support in general (even in non-query supporting browsers), matchMedia polyfill is necessary, but this change ensures a non-media source element will load in JS environments. Fixes #9 --- picturefill.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/picturefill.js b/picturefill.js index 0ebcd248..17e7cd3c 100644 --- a/picturefill.js +++ b/picturefill.js @@ -12,10 +12,8 @@ /* * Test if `` is supported natively, if so, exit - no polyfill needed. - * Also, if `window.matchMedia is not defined, or if it is and media queries aren't supported ("only all" below), exit - * Note: there is a polyfill available for `matchMedia`: https://github.com/paulirish/matchMedia.js */ - if ( !!( w.document.createElement( "picture" ) && w.HTMLPictureElement ) || !w.matchMedia || !w.matchMedia( "only all" ) ){ + if ( !!( w.document.createElement( "picture" ) && w.HTMLPictureElement ) ){ return; } @@ -30,7 +28,8 @@ // See if which sources match for( var j = 0, jl = sources.length; j < jl; j++ ){ var media = sources[ j ].getAttribute( "media" ); - if( !media || w.matchMedia( media ).matches ){ + // if there's no media specified, OR w.matchMedia is supported + if( !media || ( w.matchMedia && w.matchMedia( media ).matches ) ){ matches.push( sources[ j ] ); } }