@@ -9,6 +9,21 @@ define( [
99
1010( function ( ) {
1111
12+ var pixelPositionVal , boxSizingReliableVal , scrollboxSizeVal , pixelBoxStylesVal ,
13+ reliableMarginLeftVal , reliableTrDimensionsVal , reliableColDimensionsVal ,
14+ container = document . createElement ( "div" ) ,
15+ div = document . createElement ( "div" ) ,
16+ table = document . createElement ( "table" ) ;
17+
18+ // Finish early in limited (non-browser) environments
19+ if ( ! div . style ) {
20+ return ;
21+ }
22+
23+ function roundPixelMeasures ( measure ) {
24+ return Math . round ( parseFloat ( measure ) ) ;
25+ }
26+
1227 // Executing both pixelPosition & boxSizingReliable tests require only one layout
1328 // so they're executed at the same time to save the second computation.
1429 function computeStyleTests ( ) {
@@ -59,23 +74,83 @@ define( [
5974
6075 documentElement . removeChild ( container ) ;
6176
62- // Nullify the div so it wouldn't be stored in the memory and
63- // it will also be a sign that checks already performed
77+ // Nullify the table so it wouldn't be stored in the memory;
78+ // it will also be a sign that checks were already performed.
6479 div = null ;
6580 }
6681
67- function roundPixelMeasures ( measure ) {
68- return Math . round ( parseFloat ( measure ) ) ;
69- }
82+ // Executing table tests requires only one layout, so they're executed
83+ // at the same time to save the second computation.
84+ function computeTableStyleTests ( ) {
7085
71- var pixelPositionVal , boxSizingReliableVal , scrollboxSizeVal , pixelBoxStylesVal ,
72- reliableTrDimensionsVal , reliableMarginLeftVal ,
73- container = document . createElement ( "div" ) ,
74- div = document . createElement ( "div" ) ;
86+ // This is a singleton, we need to execute it only once
87+ if ( ! table ) {
88+ return ;
89+ }
7590
76- // Finish early in limited (non-browser) environments
77- if ( ! div . style ) {
78- return ;
91+ var trStyle ,
92+ col = document . createElement ( "col" ) ,
93+ tr = document . createElement ( "tr" ) ,
94+ td = document . createElement ( "td" ) ;
95+
96+ table . style . cssText = "position:absolute;left:-11111px;" +
97+ "border-collapse:separate;border-spacing:0" ;
98+ tr . style . cssText = "box-sizing:content-box;border:1px solid;height:1px" ;
99+ td . style . cssText = "height:9px;width:9px;padding:0" ;
100+
101+ col . span = 2 ;
102+
103+ documentElement
104+ . appendChild ( table )
105+ . appendChild ( col )
106+ . parentNode
107+ . appendChild ( tr )
108+ . appendChild ( td )
109+ . parentNode
110+ . appendChild ( td . cloneNode ( true ) ) ;
111+
112+ // Don't run until window is visible
113+ if ( table . offsetWidth === 0 ) {
114+ documentElement . removeChild ( table ) ;
115+ return ;
116+ }
117+
118+ trStyle = window . getComputedStyle ( tr ) ;
119+
120+ // Support: Firefox 135+
121+ // Firefox always reports computed width as if `span` was 1.
122+ // Support: Safari 18.3+
123+ // In Safari, computed width for columns is always 0.
124+ // In both these browsers, using `offsetWidth` solves the issue.
125+ // Support: IE 11+, Edge 15 - 18+
126+ // In IE/Edge, `<col>` computed width is `"auto"` unless `width` is set
127+ // explicitly via CSS so measurements there remain incorrect. Because of
128+ // the lack of a proper workaround, we accept this limitation, treating
129+ // IE/Edge as passing the test. Detect them by checking for
130+ // `msMatchesSelector`; despite Edge 15+ implementing `matches`, all
131+ // IE 9+ and Edge Legacy versions implement `msMatchesSelector` as well.
132+ reliableColDimensionsVal = ! ! documentElement . msMatchesSelector || Math . round ( parseFloat (
133+ window . getComputedStyle ( col ) . width )
134+ ) === 18 ;
135+
136+ // Support: IE 9 - 11+, Edge 15 - 18+
137+ // IE/Edge misreport `getComputedStyle` of table rows with width/height
138+ // set in CSS while `offset*` properties report correct values.
139+ // Behavior in IE 9 is more subtle than in newer versions & it passes
140+ // some versions of this test; make sure not to make it pass there!
141+ //
142+ // Support: Firefox 70+
143+ // Only Firefox includes border widths
144+ // in computed dimensions for table rows. (gh-4529)
145+ reliableTrDimensionsVal = Math . round ( parseFloat ( trStyle . height ) +
146+ parseFloat ( trStyle . borderTopWidth ) +
147+ parseFloat ( trStyle . borderBottomWidth ) ) === tr . offsetHeight ;
148+
149+ documentElement . removeChild ( table ) ;
150+
151+ // Nullify the table so it wouldn't be stored in the memory;
152+ // it will also be a sign that checks were already performed.
153+ table = null ;
79154 }
80155
81156 // Support: IE <=9 - 11 only
@@ -106,58 +181,13 @@ define( [
106181 return scrollboxSizeVal ;
107182 } ,
108183
109- // Support: IE 9 - 11+, Edge 15 - 18+
110- // IE/Edge misreport `getComputedStyle` of table rows with width/height
111- // set in CSS while `offset*` properties report correct values.
112- // Behavior in IE 9 is more subtle than in newer versions & it passes
113- // some versions of this test; make sure not to make it pass there!
114- //
115- // Support: Firefox 70+
116- // Only Firefox includes border widths
117- // in computed dimensions. (gh-4529)
118184 reliableTrDimensions : function ( ) {
119- var table , tr , trChild , trStyle ;
120- if ( reliableTrDimensionsVal == null ) {
121- table = document . createElement ( "table" ) ;
122- tr = document . createElement ( "tr" ) ;
123- trChild = document . createElement ( "div" ) ;
124-
125- table . style . cssText = "position:absolute;left:-11111px;border-collapse:separate" ;
126- tr . style . cssText = "box-sizing:content-box;border:1px solid" ;
127-
128- // Support: Chrome 86+
129- // Height set through cssText does not get applied.
130- // Computed height then comes back as 0.
131- tr . style . height = "1px" ;
132- trChild . style . height = "9px" ;
133-
134- // Support: Android 8 Chrome 86+
135- // In our bodyBackground.html iframe,
136- // display for all div elements is set to "inline",
137- // which causes a problem only in Android 8 Chrome 86.
138- // Ensuring the div is `display: block`
139- // gets around this issue.
140- trChild . style . display = "block" ;
141-
142- documentElement
143- . appendChild ( table )
144- . appendChild ( tr )
145- . appendChild ( trChild ) ;
146-
147- // Don't run until window is visible
148- if ( table . offsetWidth === 0 ) {
149- documentElement . removeChild ( table ) ;
150- return ;
151- }
152-
153- trStyle = window . getComputedStyle ( tr ) ;
154- reliableTrDimensionsVal = ( Math . round ( parseFloat ( trStyle . height ) ) +
155- Math . round ( parseFloat ( trStyle . borderTopWidth ) ) +
156- Math . round ( parseFloat ( trStyle . borderBottomWidth ) ) ) === tr . offsetHeight ;
157-
158- documentElement . removeChild ( table ) ;
159- }
185+ computeTableStyleTests ( ) ;
160186 return reliableTrDimensionsVal ;
187+ } ,
188+ reliableColDimensions : function ( ) {
189+ computeTableStyleTests ( ) ;
190+ return reliableColDimensionsVal ;
161191 }
162192 } ) ;
163193} ) ( ) ;
0 commit comments