Skip to content

Commit

Permalink
WIP Core: Drop support for iOS 10 & Firefox 60
Browse files Browse the repository at this point in the history
  • Loading branch information
mgol committed Apr 10, 2019
1 parent 2fc644c commit 724f955
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 216 deletions.
16 changes: 1 addition & 15 deletions src/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ define( [
"./css/var/swap",
"./css/curCSS",
"./css/adjustCSS",
"./css/addGetHookIf",
"./css/support",
"./css/finalPropName",

"./core/init",
"./core/ready",
"./selector" // contains
], function( jQuery, access, camelCase, rcssNum, rnumnonpx, cssExpand, isAutoPx,
getStyles, swap, curCSS, adjustCSS, addGetHookIf, support, finalPropName ) {
getStyles, swap, curCSS, adjustCSS, support, finalPropName ) {

"use strict";

Expand Down Expand Up @@ -367,19 +366,6 @@ jQuery.each( [ "height", "width" ], function( i, dimension ) {
};
} );

jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
function( elem, computed ) {
if ( computed ) {
return ( parseFloat( curCSS( elem, "marginLeft" ) ) ||
elem.getBoundingClientRect().left -
swap( elem, { marginLeft: 0 }, function() {
return elem.getBoundingClientRect().left;
} )
) + "px";
}
}
);

// These hooks are used by animate to expand properties
jQuery.each( {
margin: "",
Expand Down
26 changes: 0 additions & 26 deletions src/css/addGetHookIf.js

This file was deleted.

38 changes: 3 additions & 35 deletions src/css/curCSS.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
define( [
"../core",
"../core/isAttached",
"./var/rboxStyle",
"./var/rnumnonpx",
"./var/getStyles",
"./support"
], function( jQuery, isAttached, rboxStyle, rnumnonpx, getStyles, support ) {
"./var/getStyles"
], function( jQuery, isAttached, rboxStyle, getStyles ) {

"use strict";

function curCSS( elem, name, computed ) {
var width, minWidth, maxWidth, ret,

// Support: Firefox 51+
// Retrieving style before computed somehow
// fixes an issue with getting wrong values
// on detached elements
style = elem.style;
var ret;

computed = computed || getStyles( elem );

Expand All @@ -27,29 +18,6 @@ function curCSS( elem, name, computed ) {
if ( ret === "" && !isAttached( elem ) ) {
ret = jQuery.style( elem, name );
}

// Support: iOS <=10 only
// A tribute to the "awesome hack by Dean Edwards"
// Old WebKit returns percentage for some values,
// but width seems to be reliably pixels.
// This is against the CSSOM draft spec:
// https://drafts.csswg.org/cssom/#resolved-values
if ( !support.pixelBoxStyles() && rnumnonpx.test( ret ) && rboxStyle.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 ?
Expand Down
83 changes: 25 additions & 58 deletions src/css/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,7 @@ define( [

( function() {

// Executing both pixelPosition & boxSizingReliable tests require only one layout
// so they're executed at the same time to save the second computation.
function computeStyleTests() {

// This is a singleton, we need to execute it only once
if ( !div ) {
return;
}

container.style.cssText = "position:absolute;left:-11111px;width:60px;" +
"margin-top:1px;padding:0;border:0";
div.style.cssText =
"position:relative;display:block;box-sizing:border-box;overflow:scroll;" +
"margin:auto;border:1px;padding:1px;" +
"width:60%;top:1%";
documentElement.appendChild( container ).appendChild( div );

var divStyle = window.getComputedStyle( div );
pixelPositionVal = divStyle.top !== "1%";

// Support: Android 4.0 - 4.3 only, Firefox <=3 - 60 only
reliableMarginLeftVal = roundPixelMeasures( divStyle.marginLeft ) === 12;

// Support: iOS <=7.0 - 10.3 only
// Some styles come back with percentage values, even though they shouldn't
div.style.right = "60%";
pixelBoxStylesVal = roundPixelMeasures( divStyle.right ) === 36;

// Support: IE 9 - 11 only
// Detect misreporting of content dimensions for box-sizing:border-box elements
boxSizingReliableVal = roundPixelMeasures( divStyle.width ) === 36;

documentElement.removeChild( container );

// Nullify the div so it wouldn't be stored in the memory and
// it will also be a sign that checks already performed
div = null;
}

function roundPixelMeasures( measure ) {
return Math.round( parseFloat( measure ) );
}

var pixelPositionVal, boxSizingReliableVal, pixelBoxStylesVal,
reliableMarginLeftVal,
var boxSizingReliableVal,
container = document.createElement( "div" ),
div = document.createElement( "div" );

Expand All @@ -70,20 +26,31 @@ define( [

jQuery.extend( support, {
boxSizingReliable: function() {
computeStyleTests();

// This is a singleton, we need to execute it only once
if ( div ) {
container.style.cssText = "position:absolute;left:-11111px;width:60px;" +
"margin-top:1px;padding:0;border:0";
div.style.cssText =
"position:relative;display:block;box-sizing:border-box;overflow:scroll;" +
"margin:auto;border:1px;padding:1px;" +
"width:60%;top:1%";
documentElement.appendChild( container ).appendChild( div );

var divStyle = window.getComputedStyle( div );

// Support: IE 9 - 11 only
// Detect misreporting of content dimensions for box-sizing:border-box elements
boxSizingReliableVal = Math.round( parseFloat( divStyle.width ) ) === 36;

documentElement.removeChild( container );

// Nullify the div so it wouldn't be stored in the memory and
// it will also be a sign that checks already performed
div = null;
}

return boxSizingReliableVal;
},
pixelBoxStyles: function() {
computeStyleTests();
return pixelBoxStylesVal;
},
pixelPosition: function() {
computeStyleTests();
return pixelPositionVal;
},
reliableMarginLeft: function() {
computeStyleTests();
return reliableMarginLeftVal;
}
} );
} )();
Expand Down
23 changes: 1 addition & 22 deletions src/offset.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ define( [
"./var/documentElement",
"./css/var/rnumnonpx",
"./css/curCSS",
"./css/addGetHookIf",
"./css/support",
"./var/isWindow",
"./core/init",
"./css",
"./selector" // contains
], function( jQuery, access, document, documentElement, rnumnonpx,
curCSS, addGetHookIf, support, isWindow ) {
curCSS, support, isWindow ) {

"use strict";

Expand Down Expand Up @@ -207,25 +206,5 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function(
};
} );

// Support: iOS <=7.0 - 10.3 only
// Add the top/left cssHooks using jQuery.fn.position
// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
// getComputedStyle returns percent when specified for top/left/bottom/right;
// rather than make the css module depend on the offset module, just check for it here
jQuery.each( [ "top", "left" ], function( i, prop ) {
jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
function( elem, computed ) {
if ( computed ) {
computed = curCSS( elem, prop );

// If curCSS returns percentage, fallback to offset
return rnumnonpx.test( computed ) ?
jQuery( elem ).position()[ prop ] + "px" :
computed;
}
}
);
} );

return jQuery;
} );
66 changes: 6 additions & 60 deletions test/unit/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,112 +58,58 @@ testIframe(
var expected,
userAgent = window.navigator.userAgent,
expectedMap = {
edge: {
boxSizingReliable: true,
clearCloneStyle: true,
focusin: false,
noCloneChecked: true,
optSelected: true,
pixelBoxStyles: true,
pixelPosition: true,
radioValue: true,
reliableMarginLeft: true
},
ie_11: {
boxSizingReliable: false,
clearCloneStyle: false,
focusin: true,
noCloneChecked: false,
optSelected: false,
pixelBoxStyles: true,
pixelPosition: true,
radioValue: false,
reliableMarginLeft: true
radioValue: false
},
chrome: {
boxSizingReliable: true,
clearCloneStyle: true,
focusin: false,
noCloneChecked: true,
optSelected: true,
pixelBoxStyles: true,
pixelPosition: true,
radioValue: true,
reliableMarginLeft: true
radioValue: true
},
safari: {
boxSizingReliable: true,
clearCloneStyle: true,
focusin: false,
noCloneChecked: true,
optSelected: true,
pixelBoxStyles: true,
pixelPosition: true,
radioValue: true,
reliableMarginLeft: true
radioValue: true
},
firefox: {
boxSizingReliable: true,
clearCloneStyle: true,
focusin: false,
noCloneChecked: true,
optSelected: true,
pixelBoxStyles: true,
pixelPosition: true,
radioValue: true,
reliableMarginLeft: true
},
firefox_60: {
boxSizingReliable: true,
clearCloneStyle: true,
focusin: false,
noCloneChecked: true,
optSelected: true,
pixelBoxStyles: true,
pixelPosition: true,
radioValue: true,
reliableMarginLeft: false
radioValue: true
},
ios: {
boxSizingReliable: true,
clearCloneStyle: true,
focusin: false,
noCloneChecked: true,
optSelected: true,
pixelBoxStyles: true,
pixelPosition: true,
radioValue: true,
reliableMarginLeft: true
},
ios_10: {
boxSizingReliable: true,
clearCloneStyle: true,
focusin: false,
noCloneChecked: true,
optSelected: true,
pixelBoxStyles: false,
pixelPosition: false,
radioValue: true,
reliableMarginLeft: true
radioValue: true
}
};

if ( /edge\//i.test( userAgent ) ) {
expected = expectedMap.edge;
} else if ( document.documentMode ) {
if ( document.documentMode ) {
expected = expectedMap.ie_11;
} else if ( /chrome/i.test( userAgent ) ) {

// Catches Chrome on Android & Opera as well.
expected = expectedMap.chrome;
} else if ( /\b\d+(\.\d+)+ safari/i.test( userAgent ) ) {
expected = expectedMap.safari;
} else if ( /firefox\/60/i.test( userAgent ) ) {
expected = expectedMap.firefox_60;
} else if ( /firefox/i.test( userAgent ) ) {
expected = expectedMap.firefox;
} else if ( /iphone os 10_/i.test( userAgent ) ) {
expected = expectedMap.ios_10;
} else if ( /(?:iphone|ipad);.*(?:iphone)? os \d+_/i.test( userAgent ) ) {
expected = expectedMap.ios;
}
Expand Down

0 comments on commit 724f955

Please sign in to comment.