Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Move picturefill length insert scottjehl#340
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Oct 7, 2014
1 parent ee13442 commit 694b9c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
24 changes: 15 additions & 9 deletions dist/picturefill.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ window.matchMedia || (window.matchMedia = function() {
// Create a cached element for getting length value widths
if ( !pf.lengthEl ) {
pf.lengthEl = doc.createElement( "div" );
doc.documentElement.insertBefore( pf.lengthEl, doc.documentElement.firstChild );

// Positioning styles help prevent padding/margin/width on `html` or `body` from throwing calculations off.
pf.lengthEl.style.cssText = "border:0;display:block;font-size:1em;left:0;margin:0;padding:0;position:absolute;visibility:hidden";
}

// Positioning styles help prevent padding/margin/width on `html` from throwing calculations off.
pf.lengthEl.style.cssText = "position: absolute; left: 0; width: " + length + ";";
pf.lengthEl.style.width = length;

doc.body.appendChild(pf.lengthEl);

// Add a class, so that everyone knows where this element comes from
pf.lengthEl.className = "helper-from-picturefill-js";
Expand All @@ -139,7 +142,11 @@ window.matchMedia || (window.matchMedia = function() {
pf.lengthEl.style.cssText = "width: 100%;";
}

return pf.lengthEl.offsetWidth;
var offsetWidth = pf.lengthEl.offsetWidth;

doc.body.removeChild( pf.lengthEl );

return offsetWidth;
};

// container of supported mime types that one might need to qualify before using
Expand Down Expand Up @@ -413,12 +420,11 @@ window.matchMedia || (window.matchMedia = function() {
// http://picture.responsiveimages.org/#the-img-element
picImg.currentSrc = picImg.src;

var
style = picImg.style || {},
hasWebkitBackfaceVisibility = "webkitBackfaceVisibility" in style,
currentZoom = style.zoom;
var style = picImg.style || {},
hasWebkitBackfaceVisibility = "webkitBackfaceVisibility" in style,
currentZoom = style.zoom;

if (hasWebkitBackfaceVisibility) {
if (hasWebkitBackfaceVisibility) { // See: https://github.com/scottjehl/picturefill/issues/332
style.zoom = ".999";

hasWebkitBackfaceVisibility = picImg.offsetWidth;
Expand Down
2 changes: 1 addition & 1 deletion dist/picturefill.min.js

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

15 changes: 11 additions & 4 deletions src/picturefill.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@
// Create a cached element for getting length value widths
if ( !pf.lengthEl ) {
pf.lengthEl = doc.createElement( "div" );
doc.documentElement.insertBefore( pf.lengthEl, doc.documentElement.firstChild );

// Positioning styles help prevent padding/margin/width on `html` or `body` from throwing calculations off.
pf.lengthEl.style.cssText = "border:0;display:block;font-size:1em;left:0;margin:0;padding:0;position:absolute;visibility:hidden";
}

// Positioning styles help prevent padding/margin/width on `html` from throwing calculations off.
pf.lengthEl.style.cssText = "position: absolute; left: 0; width: " + length + ";";
pf.lengthEl.style.width = length;

doc.body.appendChild(pf.lengthEl);

// Add a class, so that everyone knows where this element comes from
pf.lengthEl.className = "helper-from-picturefill-js";
Expand All @@ -90,7 +93,11 @@
pf.lengthEl.style.cssText = "width: 100%;";
}

return pf.lengthEl.offsetWidth;
var offsetWidth = pf.lengthEl.offsetWidth;

doc.body.removeChild( pf.lengthEl );

return offsetWidth;
};

// container of supported mime types that one might need to qualify before using
Expand Down

0 comments on commit 694b9c4

Please sign in to comment.