Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 18d6ba4

Browse files
author
aFarkas
committed
build
1 parent 80f446b commit 18d6ba4

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

dist/picturefill.js

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! Picturefill - v2.3.0-beta - 2015-03-05
1+
/*! Picturefill - v2.3.0 - 2015-03-23
22
* http://scottjehl.github.io/picturefill
33
* Copyright (c) 2015 https://github.com/scottjehl/picturefill/blob/master/Authors.txt; Licensed MIT */
44
/*! 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 */
@@ -137,8 +137,10 @@ window.matchMedia || (window.matchMedia = function() {
137137
*/
138138
pf.getWidthFromLength = function( length ) {
139139
var cssValue;
140-
// If a length is specified and doesn’t contain a percentage, and it is greater than 0 or using `calc`, use it. Else, use the `100vw` default.
141-
length = length && length.indexOf( "%" ) > -1 === false && ( parseFloat( length ) > 0 || length.indexOf( "calc(" ) > -1 ) ? length : "100vw";
140+
// If a length is specified and doesn’t contain a percentage, and it is greater than 0 or using `calc`, use it. Else, abort.
141+
if ( !(length && length.indexOf( "%" ) > -1 === false && ( parseFloat( length ) > 0 || length.indexOf( "calc(" ) > -1 )) ) {
142+
return false;
143+
}
142144

143145
/**
144146
* If length is specified in `vw` units, use `%` instead since the div we’re measuring
@@ -161,7 +163,9 @@ window.matchMedia || (window.matchMedia = function() {
161163

162164
pf.lengthEl.style.width = "0px";
163165

164-
pf.lengthEl.style.width = length;
166+
try {
167+
pf.lengthEl.style.width = length;
168+
} catch ( e ) {}
165169

166170
doc.body.appendChild(pf.lengthEl);
167171

@@ -195,12 +199,14 @@ window.matchMedia || (window.matchMedia = function() {
195199
// container of supported mime types that one might need to qualify before using
196200
pf.types = pf.types || {};
197201

198-
// Add support for standard mime types
199-
pf.types[ "image/jpeg" ] = true;
200-
pf.types[ "image/gif" ] = true;
201-
pf.types[ "image/png" ] = true;
202-
pf.types[ "image/svg+xml" ] = doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1");
203-
pf.types[ "image/webp" ] = pf.detectTypeSupport("image/webp", "data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=");
202+
pf.initTypeDetects = function() {
203+
// Add support for standard mime types
204+
pf.types[ "image/jpeg" ] = true;
205+
pf.types[ "image/gif" ] = true;
206+
pf.types[ "image/png" ] = true;
207+
pf.types[ "image/svg+xml" ] = doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1");
208+
pf.types[ "image/webp" ] = pf.detectTypeSupport("image/webp", "data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=");
209+
};
204210

205211
pf.verifyTypeSupport = function( source ) {
206212
var type = source.getAttribute( "type" );
@@ -259,7 +265,7 @@ window.matchMedia || (window.matchMedia = function() {
259265
}
260266

261267
//if we have no winningLength fallback to 100vw
262-
return winningLength || Math.max(w.innerWidth || 0, doc.document.clientWidth);
268+
return winningLength || Math.max(w.innerWidth || 0, doc.documentElement.clientWidth);
263269
};
264270

265271
pf.parseSrcset = function( srcset ) {
@@ -425,24 +431,36 @@ window.matchMedia || (window.matchMedia = function() {
425431
pf.setIntrinsicSize = (function() {
426432
var urlCache = {};
427433
var setSize = function( picImg, width, res ) {
428-
picImg.setAttribute( "width", parseInt(width / res, 10) );
434+
if ( width ) {
435+
picImg.setAttribute( "width", parseInt(width / res, 10) );
436+
}
429437
};
430438
return function( picImg, bestCandidate ) {
431439
var img;
432-
if ( !picImg[ pf.ns ] ) {
440+
if ( !picImg[ pf.ns ] || w.pfStopIntrinsicSize ) {
433441
return;
434442
}
435443
if ( picImg[ pf.ns ].dims === undefined ) {
436444
picImg[ pf.ns].dims = picImg.getAttribute("width") || picImg.getAttribute("height");
437445
}
438446
if ( picImg[ pf.ns].dims ) { return; }
439447

440-
if ( urlCache[bestCandidate.url] ) {
448+
if ( bestCandidate.url in urlCache ) {
441449
setSize( picImg, urlCache[bestCandidate.url], bestCandidate.resolution );
442450
} else {
443451
img = doc.createElement( "img" );
444452
img.onload = function() {
445453
urlCache[bestCandidate.url] = img.width;
454+
455+
//IE 10/11 don't calculate width for svg outside document
456+
if ( !urlCache[bestCandidate.url] ) {
457+
try {
458+
doc.body.appendChild( img );
459+
urlCache[bestCandidate.url] = img.width || img.offsetWidth;
460+
doc.body.removeChild( img );
461+
} catch(e){}
462+
}
463+
446464
if ( picImg.src === bestCandidate.url ) {
447465
setSize( picImg, urlCache[bestCandidate.url], bestCandidate.resolution );
448466
}
@@ -676,6 +694,7 @@ window.matchMedia || (window.matchMedia = function() {
676694
* Also attaches picturefill on resize
677695
*/
678696
function runPicturefill() {
697+
pf.initTypeDetects();
679698
picturefill();
680699
var intervalId = setInterval( function() {
681700
// When the document has finished loading, stop checking for new images

dist/picturefill.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)