aboutsummaryrefslogtreecommitdiffstats
path: root/src/css/support.js
diff options
context:
space:
mode:
authorTimmy Willison <4timmywil@gmail.com>2021-01-11 11:56:08 -0500
committerGitHub <noreply@github.com>2021-01-11 11:56:08 -0500
commit3bbbc11111840d6fd5160db13f2c1a9acb05c4c4 (patch)
treebd7c6a2436fba968e00617478eea9c87dcad472e /src/css/support.js
parent8969732518470a7f8e654d5bc5be0b0076cb0b87 (diff)
downloadjquery-3bbbc11111840d6fd5160db13f2c1a9acb05c4c4.tar.gz
jquery-3bbbc11111840d6fd5160db13f2c1a9acb05c4c4.zip
Dimensions: Add offset prop fallback to FF for unreliable TR dimensions
Firefox incorrectly (or perhaps correctly) includes table borders in computed dimensions, but they are the only one. Workaround this by testing for it and falling back to offset properties Fixes gh-4529 Closes gh-4808
Diffstat (limited to 'src/css/support.js')
-rw-r--r--src/css/support.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/css/support.js b/src/css/support.js
new file mode 100644
index 000000000..9e6a915d2
--- /dev/null
+++ b/src/css/support.js
@@ -0,0 +1,52 @@
+import document from "../var/document.js";
+import documentElement from "../var/documentElement.js";
+import support from "../var/support.js";
+
+( function() {
+
+var reliableTrDimensionsVal,
+ div = document.createElement( "div" );
+
+// Finish early in limited (non-browser) environments
+if ( !div.style ) {
+ return;
+}
+
+// Support: IE 10 - 11+
+// IE misreports `getComputedStyle` of table rows with width/height
+// set in CSS while `offset*` properties report correct values.
+// Support: Firefox 70+
+// Only Firefox includes border widths
+// in computed dimensions. (gh-4529)
+support.reliableTrDimensions = function() {
+ var table, tr, trStyle;
+ if ( reliableTrDimensionsVal == null ) {
+ table = document.createElement( "table" );
+ tr = document.createElement( "tr" );
+
+ table.style.cssText = "position:absolute;left:-11111px;border-collapse:separate";
+ tr.style.cssText = "border:1px solid";
+
+ // Support: Chrome 86+
+ // Height set through cssText does not get applied.
+ // Computed height then comes back as 0.
+ tr.style.height = "1px";
+ div.style.height = "9px";
+
+ documentElement
+ .appendChild( table )
+ .appendChild( tr )
+ .appendChild( div );
+
+ trStyle = window.getComputedStyle( tr );
+ reliableTrDimensionsVal = ( parseInt( trStyle.height, 10 ) +
+ parseInt( trStyle.borderTopWidth, 10 ) +
+ parseInt( trStyle.borderBottomWidth, 10 ) ) === tr.offsetHeight;
+
+ documentElement.removeChild( table );
+ }
+ return reliableTrDimensionsVal;
+};
+} )();
+
+export default support;