]> source.dussan.org Git - jquery.git/commitdiff
CSS: Detect more WebKit styles erroneously reported as percentages
authorRichard Gibson <richard.gibson@gmail.com>
Mon, 18 Sep 2017 15:59:50 +0000 (11:59 -0400)
committerGitHub <noreply@github.com>
Mon, 18 Sep 2017 15:59:50 +0000 (11:59 -0400)
Ref 692f9d4db30c9c6c4f6bc76005cf153586202fa6
Fixes gh-3777
Closes gh-3778

src/css.js
src/css/curCSS.js
src/css/support.js
src/css/var/rboxStyle.js [new file with mode: 0644]
src/css/var/rmargin.js [deleted file]
test/unit/support.js

index 107d85a93286d7fe80651a62e1e436706fd5addf..1058ad4a2750a0452a49e4df9d919ddad4677c09 100644 (file)
@@ -2,7 +2,6 @@ define( [
        "./core",
        "./var/pnum",
        "./core/access",
-       "./css/var/rmargin",
        "./var/document",
        "./var/rcssNum",
        "./css/var/rnumnonpx",
@@ -17,7 +16,7 @@ define( [
        "./core/init",
        "./core/ready",
        "./selector" // contains
-], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand,
+], function( jQuery, pnum, access, document, rcssNum, rnumnonpx, cssExpand,
        getStyles, swap, curCSS, adjustCSS, addGetHookIf, support ) {
 
 "use strict";
@@ -447,7 +446,7 @@ jQuery.each( {
                }
        };
 
-       if ( !rmargin.test( prefix ) ) {
+       if ( prefix !== "margin" ) {
                jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
        }
 } );
index 01ccad3aec52301258ea6717802e2c53c2adb6d4..aa1414d26156765950150333a45d59bc57342169 100644 (file)
@@ -1,11 +1,11 @@
 define( [
        "../core",
+       "./var/rboxStyle",
        "./var/rnumnonpx",
-       "./var/rmargin",
        "./var/getStyles",
        "./support",
        "../selector" // Get jQuery.contains
-], function( jQuery, rnumnonpx, rmargin, getStyles, support ) {
+], function( jQuery, rboxStyle, rnumnonpx, getStyles, support ) {
 
 "use strict";
 
@@ -35,7 +35,7 @@ function curCSS( elem, name, computed ) {
                // but width seems to be reliably pixels.
                // This is against the CSSOM draft spec:
                // https://drafts.csswg.org/cssom/#resolved-values
-               if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) {
+               if ( !support.pixelBoxStyles() && rnumnonpx.test( ret ) && rboxStyle.test( name ) ) {
 
                        // Remember the original values
                        width = style.width;
index 97f5aad7015c790d00cc230939cd556b0774fc4f..5404f8cd8819d5d3e1952693d39efbf445085f8f 100644 (file)
@@ -32,10 +32,10 @@ define( [
                // Support: Android 4.0 - 4.3 only, Firefox <=3 - 44
                reliableMarginLeftVal = divStyle.marginLeft === "12px";
 
-               // Support: Android 4.0 - 4.3 only
+               // Support: Android 4.0 - 4.3 only, Safari <=9.1 - 10.1, iOS <=7.0 - 9.3
                // Some styles come back with percentage values, even though they shouldn't
-               div.style.marginRight = "60%";
-               pixelMarginRightVal = divStyle.marginRight === "36px";
+               div.style.right = "60%";
+               pixelBoxStylesVal = divStyle.right === "36px";
 
                // Support: IE 9 - 11 only
                // Detect misreporting of content dimensions for box-sizing:border-box elements
@@ -53,7 +53,7 @@ define( [
                div = null;
        }
 
-       var pixelPositionVal, boxSizingReliableVal, scrollboxSizeVal, pixelMarginRightVal,
+       var pixelPositionVal, boxSizingReliableVal, scrollboxSizeVal, pixelBoxStylesVal,
                reliableMarginLeftVal,
                container = document.createElement( "div" ),
                div = document.createElement( "div" );
@@ -74,13 +74,13 @@ define( [
                        computeStyleTests();
                        return boxSizingReliableVal;
                },
-               pixelPosition: function() {
+               pixelBoxStyles: function() {
                        computeStyleTests();
-                       return pixelPositionVal;
+                       return pixelBoxStylesVal;
                },
-               pixelMarginRight: function() {
+               pixelPosition: function() {
                        computeStyleTests();
-                       return pixelMarginRightVal;
+                       return pixelPositionVal;
                },
                reliableMarginLeft: function() {
                        computeStyleTests();
diff --git a/src/css/var/rboxStyle.js b/src/css/var/rboxStyle.js
new file mode 100644 (file)
index 0000000..902c010
--- /dev/null
@@ -0,0 +1,7 @@
+define( [
+       "./cssExpand"
+], function( cssExpand ) {
+       "use strict";
+
+       return new RegExp( cssExpand.join( "|" ), "i" );
+} );
diff --git a/src/css/var/rmargin.js b/src/css/var/rmargin.js
deleted file mode 100644 (file)
index 0fbfbd8..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-define( function() {
-       "use strict";
-
-       return ( /^margin/ );
-} );
index f893886da15de895f8035aaf59e1771c954b0218..98a24e7821d420791880dde63677abb9c5239884 100644 (file)
@@ -70,7 +70,7 @@ testIframe(
                        "focusin": false,
                        "noCloneChecked": true,
                        "optSelected": true,
-                       "pixelMarginRight": true,
+                       "pixelBoxStyles": true,
                        "pixelPosition": true,
                        "radioValue": true,
                        "reliableMarginLeft": true,
@@ -88,7 +88,7 @@ testIframe(
                        "focusin": true,
                        "noCloneChecked": false,
                        "optSelected": false,
-                       "pixelMarginRight": true,
+                       "pixelBoxStyles": true,
                        "pixelPosition": true,
                        "radioValue": false,
                        "reliableMarginLeft": true,
@@ -106,7 +106,7 @@ testIframe(
                        "focusin": true,
                        "noCloneChecked": false,
                        "optSelected": false,
-                       "pixelMarginRight": true,
+                       "pixelBoxStyles": true,
                        "pixelPosition": true,
                        "radioValue": false,
                        "reliableMarginLeft": true,
@@ -127,7 +127,7 @@ testIframe(
                        "focusin": false,
                        "noCloneChecked": true,
                        "optSelected": true,
-                       "pixelMarginRight": true,
+                       "pixelBoxStyles": true,
                        "pixelPosition": true,
                        "radioValue": true,
                        "reliableMarginLeft": true,
@@ -145,7 +145,7 @@ testIframe(
                        "focusin": false,
                        "noCloneChecked": true,
                        "optSelected": true,
-                       "pixelMarginRight": true,
+                       "pixelBoxStyles": false,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableMarginLeft": true,
@@ -163,7 +163,7 @@ testIframe(
                        "focusin": false,
                        "noCloneChecked": true,
                        "optSelected": true,
-                       "pixelMarginRight": true,
+                       "pixelBoxStyles": true,
                        "pixelPosition": true,
                        "radioValue": true,
                        "reliableMarginLeft": false,
@@ -181,7 +181,7 @@ testIframe(
                        "focusin": false,
                        "noCloneChecked": true,
                        "optSelected": true,
-                       "pixelMarginRight": true,
+                       "pixelBoxStyles": false,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableMarginLeft": true,
@@ -199,7 +199,7 @@ testIframe(
                        "focusin": false,
                        "noCloneChecked": true,
                        "optSelected": true,
-                       "pixelMarginRight": true,
+                       "pixelBoxStyles": false,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableMarginLeft": true,
@@ -217,7 +217,7 @@ testIframe(
                        "focusin": false,
                        "noCloneChecked": true,
                        "optSelected": true,
-                       "pixelMarginRight": true,
+                       "pixelBoxStyles": false,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableMarginLeft": true,
@@ -235,7 +235,7 @@ testIframe(
                        "focusin": false,
                        "noCloneChecked": true,
                        "optSelected": true,
-                       "pixelMarginRight": false,
+                       "pixelBoxStyles": false,
                        "pixelPosition": false,
                        "radioValue": true,
                        "reliableMarginLeft": false,