@@ -9,6 +9,21 @@ define( [
9
9
10
10
( function ( ) {
11
11
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
+
12
27
// Executing both pixelPosition & boxSizingReliable tests require only one layout
13
28
// so they're executed at the same time to save the second computation.
14
29
function computeStyleTests ( ) {
@@ -59,23 +74,83 @@ define( [
59
74
60
75
documentElement . removeChild ( container ) ;
61
76
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.
64
79
div = null ;
65
80
}
66
81
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 ( ) {
70
85
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
+ }
75
90
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 ;
79
154
}
80
155
81
156
// Support: IE <=9 - 11 only
@@ -106,58 +181,13 @@ define( [
106
181
return scrollboxSizeVal ;
107
182
} ,
108
183
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)
118
184
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 ( ) ;
160
186
return reliableTrDimensionsVal ;
187
+ } ,
188
+ reliableColDimensions : function ( ) {
189
+ computeTableStyleTests ( ) ;
190
+ return reliableColDimensionsVal ;
161
191
}
162
192
} ) ;
163
193
} ) ( ) ;
0 commit comments