Skip to content

Commit 1ab2ff6

Browse files
committed
Merge pull request #3 from mattbagwell/master
allow previously loaded larger images to be used at lower media sizes
2 parents d9a4615 + 54e7382 commit 1ab2ff6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

js/picturefill-dev.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
// See if which sources match
1919
for( var j = 0, jl = sources.length; j < jl; j++ ){
2020
var media = sources[ j ].getAttribute( "data-media" );
21-
// if there's no media specified, OR w.matchMedia is supported
22-
if( !media || ( w.matchMedia && w.matchMedia( media ).matches ) ){
21+
// if there's no media specified, OR w.matchMedia is supported OR media has already been loaded
22+
if( !media || ( w.matchMedia && w.matchMedia( media ).matches ) || ( sources[ j ].getAttribute("data-loaded") !== null) ){
2323
matches.push( sources[ j ] );
2424
}
2525
}
@@ -40,6 +40,7 @@
4040

4141
picImg.src = matchedEl.getAttribute( "data-src" );
4242
matchedEl.appendChild( picImg );
43+
matchedEl.setAttribute("data-loaded", "true");
4344
picImg.removeAttribute("width");
4445
picImg.removeAttribute("height");
4546
}

0 commit comments

Comments
 (0)