Skip to content

Commit

Permalink
Cache detection image
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Oct 7, 2014
1 parent 80573aa commit b010a66
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
22 changes: 10 additions & 12 deletions dist/picturefill.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Picturefill - v2.1.0 - 2014-09-23
/*! Picturefill - v2.1.0 - 2014-10-06
* http://scottjehl.github.io/picturefill
* Copyright (c) 2014 https://github.com/scottjehl/picturefill/blob/master/Authors.txt; Licensed MIT */
/*! 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 */
Expand Down Expand Up @@ -52,7 +52,7 @@ window.matchMedia || (window.matchMedia = function() {
* License: MIT/GPLv2
* Spec: http://picture.responsiveimages.org/
*/
(function( w, doc ) {
(function( w, doc, image ) {
// Enable strict mode
"use strict";

Expand All @@ -73,9 +73,8 @@ window.matchMedia || (window.matchMedia = function() {

// srcset support test
(function() {
var img = doc.createElement( "img" );
pf.srcsetSupported = "srcset" in img;
pf.sizesSupported = "sizes" in img;
pf.srcsetSupported = "srcset" in image;
pf.sizesSupported = "sizes" in image;
})();

// just a string trim workaround
Expand Down Expand Up @@ -158,18 +157,17 @@ window.matchMedia || (window.matchMedia = function() {
pf.types[ "image/webp" ] = function() {
// based on Modernizr's lossless img-webp test
// note: asynchronous
var img = new w.Image(),
type = "image/webp";
var type = "image/webp";

img.onerror = function() {
image.onerror = function() {
pf.types[ type ] = false;
picturefill();
};
img.onload = function() {
pf.types[ type ] = img.width === 1;
image.onload = function() {
pf.types[ type ] = image.width === 1;
picturefill();
};
img.src = "data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=";
image.src = "data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=";
};

/**
Expand Down Expand Up @@ -641,4 +639,4 @@ window.matchMedia || (window.matchMedia = function() {
w.picturefill = picturefill;
}

} )( this, this.document );
} )( this, this.document, new this.Image() );
4 changes: 2 additions & 2 deletions dist/picturefill.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions src/picturefill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* License: MIT/GPLv2
* Spec: http://picture.responsiveimages.org/
*/
(function( w, doc ) {
(function( w, doc, image ) {
// Enable strict mode
"use strict";

Expand All @@ -24,9 +24,8 @@

// srcset support test
(function() {
var img = doc.createElement( "img" );
pf.srcsetSupported = "srcset" in img;
pf.sizesSupported = "sizes" in img;
pf.srcsetSupported = "srcset" in image;
pf.sizesSupported = "sizes" in image;
})();

// just a string trim workaround
Expand Down Expand Up @@ -109,18 +108,17 @@
pf.types[ "image/webp" ] = function() {
// based on Modernizr's lossless img-webp test
// note: asynchronous
var img = new w.Image(),
type = "image/webp";
var type = "image/webp";

img.onerror = function() {
image.onerror = function() {
pf.types[ type ] = false;
picturefill();
};
img.onload = function() {
pf.types[ type ] = img.width === 1;
image.onload = function() {
pf.types[ type ] = image.width === 1;
picturefill();
};
img.src = "data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=";
image.src = "data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=";
};

/**
Expand Down Expand Up @@ -592,4 +590,4 @@
w.picturefill = picturefill;
}

} )( this, this.document );
} )( this, this.document, new this.Image() );

0 comments on commit b010a66

Please sign in to comment.