diff options
author | Mike Sherov <mike.sherov@gmail.com> | 2011-12-06 20:32:26 -0500 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2011-12-06 20:32:26 -0500 |
commit | 7f6a991313380b74d5fb18782fb6b99fd6c4a22d (patch) | |
tree | b59b466d91c929592645ef2d6a03aeb2584cba0b /src/css.js | |
parent | 2c75a993be712ceb5da4eee9810f562b90fd7e23 (diff) | |
download | jquery-7f6a991313380b74d5fb18782fb6b99fd6c4a22d.tar.gz jquery-7f6a991313380b74d5fb18782fb6b99fd6c4a22d.zip |
Fix #10639. Make percent-specified margins return px values in WebKit.
Diffstat (limited to 'src/css.js')
-rw-r--r-- | src/css.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/css.js b/src/css.js index 810d18178..7d5abe975 100644 --- a/src/css.js +++ b/src/css.js @@ -7,6 +7,7 @@ var ralpha = /alpha\([^)]*\)/i, rnumpx = /^-?\d+(?:px)?$/i, rnumnopx = /^-?\d+(?!px)[^\d\s]+$/i, rrelNum = /^([\-+])=([\-+.\de]+)/, + rmargin = /^margin/, cssShow = { position: "absolute", visibility: "hidden", display: "block" }, cssWidth = [ "Left", "Right" ], @@ -256,7 +257,7 @@ jQuery(function() { if ( document.defaultView && document.defaultView.getComputedStyle ) { getComputedStyle = function( elem, name ) { - var ret, defaultView, computedStyle; + var ret, defaultView, computedStyle, width, style = elem.style; name = name.replace( rupper, "-$1" ).toLowerCase(); @@ -268,6 +269,16 @@ if ( document.defaultView && document.defaultView.getComputedStyle ) { } } + // A tribute to the "awesome hack by Dean Edwards" + // WebKit uses "computed value (percentage if specified)" instead of "used value" for margins + // which is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values + if ( !jQuery.support.pixelMargin && computedStyle && rmargin.test( name ) && rnumnopx.test( ret ) ) { + width = style.width; + style.width = ret; + ret = computedStyle.width; + style.width = width; + } + return ret; }; } @@ -299,7 +310,7 @@ if ( document.documentElement.currentStyle ) { if ( rsLeft ) { elem.runtimeStyle.left = elem.currentStyle.left; } - style.left = name === "fontSize" ? "1em" : ( ret || 0 ); + style.left = name === "fontSize" ? "1em" : ret; ret = style.pixelLeft + "px"; // Revert the changed values |