diff options
author | Michał Gołębiowski <m.goleb@gmail.com> | 2014-11-05 18:27:01 +0100 |
---|---|---|
committer | Michał Gołębiowski <m.goleb@gmail.com> | 2015-02-04 13:51:56 +0100 |
commit | 3747cc642a48d2a5a8ac83069f66bddd33bea301 (patch) | |
tree | 3ee4b914c4078094162f181e0e25a0511ebf66bf /src/css/curCSS.js | |
parent | 1ba45fcc15c894cad591d93cbb88010df5f235fe (diff) | |
download | jquery-3747cc642a48d2a5a8ac83069f66bddd33bea301.tar.gz jquery-3747cc642a48d2a5a8ac83069f66bddd33bea301.zip |
CSS: Restore the hack to get pixels for .css('width') etc.
This hack turns out to be needed by Android 4.0-4.3.
Add a support test so that the hack is invoked only where needed.
Refs gh-1815
Refs gh-1820
Closes gh-1842
Diffstat (limited to 'src/css/curCSS.js')
-rw-r--r-- | src/css/curCSS.js | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/css/curCSS.js b/src/css/curCSS.js index 260184b47..f5c85ecc0 100644 --- a/src/css/curCSS.js +++ b/src/css/curCSS.js @@ -3,11 +3,13 @@ define([ "./var/rnumnonpx", "./var/rmargin", "./var/getStyles", + "./support", "../selector" // contains -], function( jQuery, rnumnonpx, rmargin, getStyles ) { +], function( jQuery, rnumnonpx, rmargin, getStyles, support ) { function curCSS( elem, name, computed ) { - var ret; + var width, minWidth, maxWidth, ret, + style = elem.style; computed = computed || getStyles( elem ); @@ -22,6 +24,29 @@ function curCSS( elem, name, computed ) { if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) { ret = jQuery.style( elem, name ); } + + // Support: Android 4.0-4.3 + // A tribute to the "awesome hack by Dean Edwards" + // Android Browser returns percentage for some values, + // but width seems to be reliably pixels. + // This is against the CSSOM draft spec: + // http://dev.w3.org/csswg/cssom/#resolved-values + if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) { + + // Remember the original values + width = style.width; + minWidth = style.minWidth; + maxWidth = style.maxWidth; + + // Put in the new values to get a computed value out + style.minWidth = style.maxWidth = style.width = ret; + ret = computed.width; + + // Revert the changed values + style.width = width; + style.minWidth = minWidth; + style.maxWidth = maxWidth; + } } return ret !== undefined ? |