Skip to content

Commit

Permalink
merging commit from @voku with updated build files
Browse files Browse the repository at this point in the history
  • Loading branch information
scottjehl committed Sep 23, 2014
2 parents 5beb1b9 + c22f56d commit 80573aa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
39 changes: 25 additions & 14 deletions dist/picturefill.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Picturefill - v2.1.0 - 2014-08-20
/*! Picturefill - v2.1.0 - 2014-09-23
* 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 @@ -72,8 +72,11 @@ window.matchMedia || (window.matchMedia = function() {
pf.ns = "picturefill";

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

// just a string trim workaround
pf.trim = function( str ) {
Expand Down Expand Up @@ -129,6 +132,9 @@ window.matchMedia || (window.matchMedia = function() {
// Positioning styles help prevent padding/margin/width on `html` from throwing calculations off.
pf.lengthEl.style.cssText = "position: absolute; left: 0; width: " + length + ";";

// Add a class, so that everyone knows where this element comes from
pf.lengthEl.className = "helper-from-picturefill-js";

if ( pf.lengthEl.offsetWidth <= 0 ) {
// Something has gone wrong. `calc()` is in use and unsupported, most likely. Default to `100vw` (`100%`, for broader support.):
pf.lengthEl.style.cssText = "width: 100%;";
Expand Down Expand Up @@ -598,18 +604,23 @@ window.matchMedia || (window.matchMedia = function() {
return;
}
}, 250 );
if ( w.addEventListener ) {

function checkResize() {
var resizeThrottle;
w.addEventListener( "resize", function() {
if (!w._picturefillWorking) {
w._picturefillWorking = true;
w.clearTimeout( resizeThrottle );
resizeThrottle = w.setTimeout( function() {
picturefill({ reevaluate: true });
w._picturefillWorking = false;
}, 60 );
}
}, false );
if (!w._picturefillWorking) {
w._picturefillWorking = true;
w.clearTimeout( resizeThrottle );
resizeThrottle = w.setTimeout( function() {
picturefill({ reevaluate: true });
w._picturefillWorking = false;
}, 60 );
}
}

if ( w.addEventListener ) {
w.addEventListener( "resize", checkResize, false );
} else if ( w.attachEvent ) {
w.attachEvent( "onresize", checkResize );
}
}

Expand Down
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.

3 changes: 3 additions & 0 deletions src/picturefill.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
// Positioning styles help prevent padding/margin/width on `html` from throwing calculations off.
pf.lengthEl.style.cssText = "position: absolute; left: 0; width: " + length + ";";

// Add a class, so that everyone knows where this element comes from
pf.lengthEl.className = "helper-from-picturefill-js";

if ( pf.lengthEl.offsetWidth <= 0 ) {
// Something has gone wrong. `calc()` is in use and unsupported, most likely. Default to `100vw` (`100%`, for broader support.):
pf.lengthEl.style.cssText = "width: 100%;";
Expand Down

0 comments on commit 80573aa

Please sign in to comment.