Commit 25bc6809 authored by Michał Gołębiowski's avatar Michał Gołębiowski

CSS: Add a support test for the hack for .css('marginRight') 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 3747cc642a48d2a5a8ac83069f66bddd33bea301

Refs gh-1815
Refs gh-1820
Refs gh-1842
Closes gh-2061
parent 5e5489ce
...@@ -3,8 +3,9 @@ define([ ...@@ -3,8 +3,9 @@ define([
"../core", "../core",
"./var/rnumnonpx", "./var/rnumnonpx",
"./var/rmargin", "./var/rmargin",
"./support",
"../selector" // contains "../selector" // contains
], function( exports, jQuery, rnumnonpx, rmargin ) { ], function( exports, jQuery, rnumnonpx, rmargin, support ) {
var getStyles, curCSS, var getStyles, curCSS,
rposition = /^(top|right|bottom|left)$/; rposition = /^(top|right|bottom|left)$/;
...@@ -36,13 +37,12 @@ if ( window.getComputedStyle ) { ...@@ -36,13 +37,12 @@ if ( window.getComputedStyle ) {
ret = jQuery.style( elem, name ); ret = jQuery.style( elem, name );
} }
// Support: Android 4.0-4.3
// A tribute to the "awesome hack by Dean Edwards" // A tribute to the "awesome hack by Dean Edwards"
// Android Browser returns percentage for some values, // Android Browser returns percentage for some values,
// but width seems to be reliably pixels. // but width seems to be reliably pixels.
// This is against the CSSOM draft spec: // This is against the CSSOM draft spec:
// http://dev.w3.org/csswg/cssom/#resolved-values // 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 // Remember the original values
width = style.width; width = style.width;
......
...@@ -4,8 +4,7 @@ define([ ...@@ -4,8 +4,7 @@ define([
], function( jQuery, support ) { ], function( jQuery, support ) {
(function() { (function() {
// Minified: var b,c,d,e,f,g, h,i var div, container, style, a, pixelPositionVal, boxSizingReliableVal, pixelMarginRightVal,
var div, style, a, pixelPositionVal, boxSizingReliableVal,
reliableHiddenOffsetsVal, reliableMarginRightVal; reliableHiddenOffsetsVal, reliableMarginRightVal;
// Setup // Setup
...@@ -33,21 +32,37 @@ define([ ...@@ -33,21 +32,37 @@ define([
div.cloneNode( true ).style.backgroundClip = ""; div.cloneNode( true ).style.backgroundClip = "";
support.clearCloneStyle = div.style.backgroundClip === "content-box"; 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, { jQuery.extend(support, {
reliableHiddenOffsets: function() { reliableHiddenOffsets: function() {
if ( reliableHiddenOffsetsVal == null ) { if ( pixelPositionVal == null ) {
computeStyleTests(); computeStyleTests();
} }
return reliableHiddenOffsetsVal; return reliableHiddenOffsetsVal;
}, },
boxSizingReliable: function() { 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(); computeStyleTests();
} }
return boxSizingReliableVal; return boxSizingReliableVal;
}, },
pixelMarginRight: function() {
// Support: Android 4.0-4.3
if ( pixelPositionVal == null ) {
computeStyleTests();
}
return pixelMarginRightVal;
},
pixelPosition: function() { pixelPosition: function() {
if ( pixelPositionVal == null ) { if ( pixelPositionVal == null ) {
computeStyleTests(); computeStyleTests();
...@@ -55,9 +70,9 @@ define([ ...@@ -55,9 +70,9 @@ define([
return pixelPositionVal; return pixelPositionVal;
}, },
// Support: Android 2.3
reliableMarginRight: function() { reliableMarginRight: function() {
if ( reliableMarginRightVal == null ) { // Support: Android 2.3
if ( pixelPositionVal == null ) {
computeStyleTests(); computeStyleTests();
} }
return reliableMarginRightVal; return reliableMarginRightVal;
...@@ -65,8 +80,7 @@ define([ ...@@ -65,8 +80,7 @@ define([
}); });
function computeStyleTests() { function computeStyleTests() {
// Minified: var b,c,d,j var contents, divStyle,
var div, container, contents,
body = document.body; body = document.body;
if ( !body || !body.style ) { if ( !body || !body.style ) {
...@@ -75,17 +89,16 @@ define([ ...@@ -75,17 +89,16 @@ define([
} }
// Setup // Setup
div = document.createElement( "div" ); body.appendChild( container );
container = document.createElement( "div" );
container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px";
body.appendChild( container ).appendChild( div );
div.style.cssText = div.style.cssText =
// Support: Android 2.3 // Support: Android 2.3
// Vendor-prefix box-sizing // Vendor-prefix box-sizing
"-webkit-box-sizing:border-box;box-sizing:border-box;" + "-webkit-box-sizing:border-box;box-sizing:border-box;" +
"display:block;margin-top:1%;top:1%;" + "position:absolute;display:block;" +
"border:1px;padding:1px;width:4px;position:absolute"; "margin:0;margin-top:1%;margin-right:50%;" +
"border:1px;padding:1px;" +
"top:1%;height:4px;width:50%";
// Support: IE<9 // Support: IE<9
// Assume reasonable values in the absence of getComputedStyle // Assume reasonable values in the absence of getComputedStyle
...@@ -94,9 +107,10 @@ define([ ...@@ -94,9 +107,10 @@ define([
// Check for getComputedStyle so that this code is not run in IE<9. // Check for getComputedStyle so that this code is not run in IE<9.
if ( window.getComputedStyle ) { if ( window.getComputedStyle ) {
pixelPositionVal = ( window.getComputedStyle( div, null ) || {} ).top !== "1%"; divStyle = window.getComputedStyle( div, null );
boxSizingReliableVal = pixelPositionVal = ( divStyle || {} ).top !== "1%";
( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px"; boxSizingReliableVal = ( divStyle || { height: "4px" } ).height === "4px";
pixelMarginRightVal = ( divStyle || { marginRight: "4px" } ).marginRight === "4px";
// Support: Android 2.3 // Support: Android 2.3
// Div with explicit width and no margin-right incorrectly // Div with explicit width and no margin-right incorrectly
...@@ -136,6 +150,7 @@ define([ ...@@ -136,6 +150,7 @@ define([
reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0; reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0;
} }
// Teardown
body.removeChild( container ); body.removeChild( container );
} }
......
...@@ -94,6 +94,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -94,6 +94,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": true, "optDisabled": true,
"optSelected": true, "optSelected": true,
"ownLast": false, "ownLast": false,
"pixelMarginRight": true,
"pixelPosition": true, "pixelPosition": true,
"radioValue": true, "radioValue": true,
"reliableHiddenOffsets": true, "reliableHiddenOffsets": true,
...@@ -125,6 +126,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -125,6 +126,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": true, "optDisabled": true,
"optSelected": false, "optSelected": false,
"ownLast": false, "ownLast": false,
"pixelMarginRight": true,
"pixelPosition": true, "pixelPosition": true,
"radioValue": false, "radioValue": false,
"reliableHiddenOffsets": true, "reliableHiddenOffsets": true,
...@@ -156,6 +158,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -156,6 +158,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": true, "optDisabled": true,
"optSelected": false, "optSelected": false,
"ownLast": false, "ownLast": false,
"pixelMarginRight": true,
"pixelPosition": true, "pixelPosition": true,
"radioValue": false, "radioValue": false,
"reliableHiddenOffsets": true, "reliableHiddenOffsets": true,
...@@ -187,6 +190,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -187,6 +190,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": true, "optDisabled": true,
"optSelected": false, "optSelected": false,
"ownLast": true, "ownLast": true,
"pixelMarginRight": true,
"pixelPosition": false, "pixelPosition": false,
"radioValue": false, "radioValue": false,
"reliableHiddenOffsets": false, "reliableHiddenOffsets": false,
...@@ -218,6 +222,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -218,6 +222,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": true, "optDisabled": true,
"optSelected": true, "optSelected": true,
"ownLast": false, "ownLast": false,
"pixelMarginRight": true,
"pixelPosition": false, "pixelPosition": false,
"radioValue": true, "radioValue": true,
"reliableHiddenOffsets": true, "reliableHiddenOffsets": true,
...@@ -249,6 +254,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -249,6 +254,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": true, "optDisabled": true,
"optSelected": true, "optSelected": true,
"ownLast": false, "ownLast": false,
"pixelMarginRight": true,
"pixelPosition": false, "pixelPosition": false,
"radioValue": true, "radioValue": true,
"reliableHiddenOffsets": true, "reliableHiddenOffsets": true,
...@@ -280,6 +286,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -280,6 +286,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": true, "optDisabled": true,
"optSelected": true, "optSelected": true,
"ownLast": false, "ownLast": false,
"pixelMarginRight": true,
"pixelPosition": true, "pixelPosition": true,
"radioValue": true, "radioValue": true,
"reliableHiddenOffsets": true, "reliableHiddenOffsets": true,
...@@ -311,6 +318,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -311,6 +318,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": true, "optDisabled": true,
"optSelected": true, "optSelected": true,
"ownLast": false, "ownLast": false,
"pixelMarginRight": true,
"pixelPosition": false, "pixelPosition": false,
"radioValue": true, "radioValue": true,
"reliableHiddenOffsets": true, "reliableHiddenOffsets": true,
...@@ -342,6 +350,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -342,6 +350,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": true, "optDisabled": true,
"optSelected": true, "optSelected": true,
"ownLast": false, "ownLast": false,
"pixelMarginRight": true,
"pixelPosition": false, "pixelPosition": false,
"radioValue": true, "radioValue": true,
"reliableHiddenOffsets": true, "reliableHiddenOffsets": true,
...@@ -373,6 +382,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -373,6 +382,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": true, "optDisabled": true,
"optSelected": true, "optSelected": true,
"ownLast": false, "ownLast": false,
"pixelMarginRight": false,
"pixelPosition": false, "pixelPosition": false,
"radioValue": true, "radioValue": true,
"reliableHiddenOffsets": true, "reliableHiddenOffsets": true,
...@@ -404,6 +414,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec ...@@ -404,6 +414,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
"optDisabled": false, "optDisabled": false,
"optSelected": true, "optSelected": true,
"ownLast": false, "ownLast": false,
"pixelMarginRight": true,
"pixelPosition": false, "pixelPosition": false,
"radioValue": true, "radioValue": true,
"reliableHiddenOffsets": true, "reliableHiddenOffsets": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment