Skip to content

Commit

Permalink
matchmedia and media query support should not be required for picture…
Browse files Browse the repository at this point in the history
…fill 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 scottjehl#9
  • Loading branch information
scottjehl committed Mar 22, 2012
1 parent 8ea18be commit 52de779
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions picturefill.js
Expand Up @@ -12,10 +12,8 @@

/*
* Test if `<picture>` 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;
}

Expand All @@ -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 ] );
}
}
Expand Down

0 comments on commit 52de779

Please sign in to comment.