1
- /*! Picturefill - v2.3.0-beta - 2015-03-05
1
+ /*! Picturefill - v2.3.0 - 2015-03-23
2
2
* http://scottjehl.github.io/picturefill
3
3
* Copyright (c) 2015 https://github.com/scottjehl/picturefill/blob/master/Authors.txt; Licensed MIT */
4
4
/*! 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() {
137
137
*/
138
138
pf . getWidthFromLength = function ( length ) {
139
139
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
+ }
142
144
143
145
/**
144
146
* If length is specified in `vw` units, use `%` instead since the div we’re measuring
@@ -161,7 +163,9 @@ window.matchMedia || (window.matchMedia = function() {
161
163
162
164
pf . lengthEl . style . width = "0px" ;
163
165
164
- pf . lengthEl . style . width = length ;
166
+ try {
167
+ pf . lengthEl . style . width = length ;
168
+ } catch ( e ) { }
165
169
166
170
doc . body . appendChild ( pf . lengthEl ) ;
167
171
@@ -195,12 +199,14 @@ window.matchMedia || (window.matchMedia = function() {
195
199
// container of supported mime types that one might need to qualify before using
196
200
pf . types = pf . types || { } ;
197
201
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
+ } ;
204
210
205
211
pf . verifyTypeSupport = function ( source ) {
206
212
var type = source . getAttribute ( "type" ) ;
@@ -259,7 +265,7 @@ window.matchMedia || (window.matchMedia = function() {
259
265
}
260
266
261
267
//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 ) ;
263
269
} ;
264
270
265
271
pf . parseSrcset = function ( srcset ) {
@@ -425,24 +431,36 @@ window.matchMedia || (window.matchMedia = function() {
425
431
pf . setIntrinsicSize = ( function ( ) {
426
432
var urlCache = { } ;
427
433
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
+ }
429
437
} ;
430
438
return function ( picImg , bestCandidate ) {
431
439
var img ;
432
- if ( ! picImg [ pf . ns ] ) {
440
+ if ( ! picImg [ pf . ns ] || w . pfStopIntrinsicSize ) {
433
441
return ;
434
442
}
435
443
if ( picImg [ pf . ns ] . dims === undefined ) {
436
444
picImg [ pf . ns ] . dims = picImg . getAttribute ( "width" ) || picImg . getAttribute ( "height" ) ;
437
445
}
438
446
if ( picImg [ pf . ns ] . dims ) { return ; }
439
447
440
- if ( urlCache [ bestCandidate . url ] ) {
448
+ if ( bestCandidate . url in urlCache ) {
441
449
setSize ( picImg , urlCache [ bestCandidate . url ] , bestCandidate . resolution ) ;
442
450
} else {
443
451
img = doc . createElement ( "img" ) ;
444
452
img . onload = function ( ) {
445
453
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
+
446
464
if ( picImg . src === bestCandidate . url ) {
447
465
setSize ( picImg , urlCache [ bestCandidate . url ] , bestCandidate . resolution ) ;
448
466
}
@@ -676,6 +694,7 @@ window.matchMedia || (window.matchMedia = function() {
676
694
* Also attaches picturefill on resize
677
695
*/
678
696
function runPicturefill ( ) {
697
+ pf . initTypeDetects ( ) ;
679
698
picturefill ( ) ;
680
699
var intervalId = setInterval ( function ( ) {
681
700
// When the document has finished loading, stop checking for new images
0 commit comments