]> source.dussan.org Git - jquery.git/commitdiff
CSS: Add a support test for the hack for .css('marginRight') etc. 2061/head
authorMichał Gołębiowski <m.goleb@gmail.com>
Wed, 4 Feb 2015 13:36:18 +0000 (14:36 +0100)
committerMichał Gołębiowski <m.goleb@gmail.com>
Thu, 5 Feb 2015 01:46:10 +0000 (02:46 +0100)
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 3747cc642a48d2a5a8ac83069f66bddd33bea301

Refs gh-1815
Refs gh-1820
Refs gh-1842
Closes gh-2061

src/css/curCSS.js
src/css/support.js
test/unit/support.js

index c3210f18650f4e183e650e33be1b0fbc96a06467..c1a0d2de15b132f35e8ed90adcadf219f2551564 100644 (file)
@@ -3,8 +3,9 @@ define([
        "../core",
        "./var/rnumnonpx",
        "./var/rmargin",
+       "./support",
        "../selector" // contains
-], function( exports, jQuery, rnumnonpx, rmargin ) {
+], function( exports, jQuery, rnumnonpx, rmargin, support ) {
 
 var getStyles, curCSS,
        rposition = /^(top|right|bottom|left)$/;
@@ -36,13 +37,12 @@ if ( window.getComputedStyle ) {
                                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 ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
+                       if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) {
 
                                // Remember the original values
                                width = style.width;
index e8f8dd4b7c0cc87180e9f554831187c1c3dbfb07..2898f0cb59f2454d303beb7151040403706781fc 100644 (file)
@@ -4,8 +4,7 @@ define([
 ], function( jQuery, support ) {
 
 (function() {
-       // Minified: var b,c,d,e,f,g, h,i
-       var div, style, a, pixelPositionVal, boxSizingReliableVal,
+       var div, container, style, a, pixelPositionVal, boxSizingReliableVal, pixelMarginRightVal,
                reliableHiddenOffsetsVal, reliableMarginRightVal;
 
        // Setup
@@ -33,21 +32,37 @@ define([
        div.cloneNode( true ).style.backgroundClip = "";
        support.clearCloneStyle = div.style.backgroundClip === "content-box";
 
+       container = document.createElement( "div" );
+       container.style.cssText = "border:0;width:8px;height:0;top:0;left:-9999px;" +
+               "padding:0;margin-top:1px;position:absolute";
+       div.innerHTML = "";
+       container.appendChild( div );
+
        jQuery.extend(support, {
                reliableHiddenOffsets: function() {
-                       if ( reliableHiddenOffsetsVal == null ) {
+                       if ( pixelPositionVal == null ) {
                                computeStyleTests();
                        }
                        return reliableHiddenOffsetsVal;
                },
 
                boxSizingReliable: function() {
-                       if ( boxSizingReliableVal == null ) {
+                       // We're checking for pixelPositionVal here instead of boxSizingReliableVal
+                       // since that compresses better and they're computed together anyway.
+                       if ( pixelPositionVal == null ) {
                                computeStyleTests();
                        }
                        return boxSizingReliableVal;
                },
 
+               pixelMarginRight: function() {
+                       // Support: Android 4.0-4.3
+                       if ( pixelPositionVal == null ) {
+                               computeStyleTests();
+                       }
+                       return pixelMarginRightVal;
+               },
+
                pixelPosition: function() {
                        if ( pixelPositionVal == null ) {
                                computeStyleTests();
@@ -55,9 +70,9 @@ define([
                        return pixelPositionVal;
                },
 
-               // Support: Android 2.3
                reliableMarginRight: function() {
-                       if ( reliableMarginRightVal == null ) {
+                       // Support: Android 2.3
+                       if ( pixelPositionVal == null ) {
                                computeStyleTests();
                        }
                        return reliableMarginRightVal;
@@ -65,8 +80,7 @@ define([
        });
 
        function computeStyleTests() {
-               // Minified: var b,c,d,j
-               var div, container, contents,
+               var contents, divStyle,
                        body = document.body;
 
                if ( !body || !body.style ) {
@@ -75,17 +89,16 @@ define([
                }
 
                // Setup
-               div = document.createElement( "div" );
-               container = document.createElement( "div" );
-               container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px";
-               body.appendChild( container ).appendChild( div );
+               body.appendChild( container );
 
                div.style.cssText =
                        // Support: Android 2.3
                        // Vendor-prefix box-sizing
                        "-webkit-box-sizing:border-box;box-sizing:border-box;" +
-                       "display:block;margin-top:1%;top:1%;" +
-                       "border:1px;padding:1px;width:4px;position:absolute";
+                       "position:absolute;display:block;" +
+                       "margin:0;margin-top:1%;margin-right:50%;" +
+                       "border:1px;padding:1px;" +
+                       "top:1%;height:4px;width:50%";
 
                // Support: IE<9
                // Assume reasonable values in the absence of getComputedStyle
@@ -94,9 +107,10 @@ define([
 
                // Check for getComputedStyle so that this code is not run in IE<9.
                if ( window.getComputedStyle ) {
-                       pixelPositionVal = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";
-                       boxSizingReliableVal =
-                               ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px";
+                       divStyle = window.getComputedStyle( div, null );
+                       pixelPositionVal = ( divStyle || {} ).top !== "1%";
+                       boxSizingReliableVal = ( divStyle || { height: "4px" } ).height === "4px";
+                       pixelMarginRightVal = ( divStyle || { marginRight: "4px" } ).marginRight === "4px";
 
                        // Support: Android 2.3
                        // Div with explicit width and no margin-right incorrectly
@@ -136,6 +150,7 @@ define([
                        reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0;
                }
 
+               // Teardown
                body.removeChild( container );
        }
 
index 86745c758af41a70d89488658a047b0135abbc40..74692c06a0111cac42ecbad6a6dc607f2ffc2629 100644 (file)
@@ -94,6 +94,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": true,
                        "optSelected": true,
                        "ownLast": false,
+                       "pixelMarginRight": true,
                        "pixelPosition": true,
                        "radioValue": true,
                        "reliableHiddenOffsets": true,
@@ -125,6 +126,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": true,
                        "optSelected": false,
                        "ownLast": false,
+                       "pixelMarginRight": true,
                        "pixelPosition": true,
                        "radioValue": false,
                        "reliableHiddenOffsets": true,
@@ -156,6 +158,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": true,
                        "optSelected": false,
                        "ownLast": false,
+                       "pixelMarginRight": true,
                        "pixelPosition": true,
                        "radioValue": false,
                        "reliableHiddenOffsets": true,
@@ -187,6 +190,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": true,
                        "optSelected": false,
                        "ownLast": true,
+                       "pixelMarginRight": true,
                        "pixelPosition": false,
                        "radioValue": false,
                        "reliableHiddenOffsets": false,
@@ -218,6 +222,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": true,
                        "optSelected": true,
                        "ownLast": false,
+                       "pixelMarginRight": true,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableHiddenOffsets": true,
@@ -249,6 +254,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": true,
                        "optSelected": true,
                        "ownLast": false,
+                       "pixelMarginRight": true,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableHiddenOffsets": true,
@@ -280,6 +286,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": true,
                        "optSelected": true,
                        "ownLast": false,
+                       "pixelMarginRight": true,
                        "pixelPosition": true,
                        "radioValue": true,
                        "reliableHiddenOffsets": true,
@@ -311,6 +318,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": true,
                        "optSelected": true,
                        "ownLast": false,
+                       "pixelMarginRight": true,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableHiddenOffsets": true,
@@ -342,6 +350,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": true,
                        "optSelected": true,
                        "ownLast": false,
+                       "pixelMarginRight": true,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableHiddenOffsets": true,
@@ -373,6 +382,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": true,
                        "optSelected": true,
                        "ownLast": false,
+                       "pixelMarginRight": false,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableHiddenOffsets": true,
@@ -404,6 +414,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "optDisabled": false,
                        "optSelected": true,
                        "ownLast": false,
+                       "pixelMarginRight": true,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableHiddenOffsets": true,