From 59566bfe0a2fd591271de86b6bf5d9143107450e Mon Sep 17 00:00:00 2001 From: Jeff Sisson Date: Tue, 3 Feb 2015 22:16:44 -0500 Subject: [PATCH] changed whitespace to match existing style, and added test case for parentless srcset img element --- dist/picturefill.js | 2 +- src/picturefill.js | 2 +- tests/tests.js | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dist/picturefill.js b/dist/picturefill.js index 2f5e3cfa..f4ace9c9 100644 --- a/dist/picturefill.js +++ b/dist/picturefill.js @@ -601,7 +601,7 @@ window.matchMedia || (window.matchMedia = function() { } // Cache and remove `srcset` if present and we’re going to be doing `picture`/`srcset`/`sizes` polyfilling to it. - if ( (parent && parent.nodeName.toUpperCase() === "PICTURE") || + if ( ( parent && parent.nodeName.toUpperCase() === "PICTURE" ) || ( element.srcset && !pf.srcsetSupported ) || ( !pf.sizesSupported && ( element.srcset && element.srcset.indexOf("w") > -1 ) ) ) { pf.dodgeSrcset( element ); diff --git a/src/picturefill.js b/src/picturefill.js index 2a6053ce..36601d3c 100644 --- a/src/picturefill.js +++ b/src/picturefill.js @@ -552,7 +552,7 @@ } // Cache and remove `srcset` if present and we’re going to be doing `picture`/`srcset`/`sizes` polyfilling to it. - if ( (parent && parent.nodeName.toUpperCase() === "PICTURE") || + if ( ( parent && parent.nodeName.toUpperCase() === "PICTURE" ) || ( element.srcset && !pf.srcsetSupported ) || ( !pf.sizesSupported && ( element.srcset && element.srcset.indexOf("w") > -1 ) ) ) { pf.dodgeSrcset( element ); diff --git a/tests/tests.js b/tests/tests.js index 3bbe02f7..2aa6a7b5 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -582,4 +582,14 @@ }); + test( "`img` can be added outside the DOM without errors", function() { + var img = document.createElement( "img" ); + + img.setAttribute( "srcset", "data:img 500w" ); + + picturefill( { elements: [ img ] } ); + + assert.equal( img.currentSrc || img.src, "data:img" ); + }); + })( window, jQuery );