|
| 1 | +import { jQuery } from "../core.js"; |
1 | 2 | import { document } from "../var/document.js"; |
2 | 3 | import { documentElement } from "../var/documentElement.js"; |
3 | 4 | import { support } from "../var/support.js"; |
| 5 | +import { isIE } from "../var/isIE.js"; |
4 | 6 |
|
5 | | -( function() { |
| 7 | +var reliableTrDimensionsVal, reliableColDimensionsVal, |
| 8 | + table = document.createElement( "table" ); |
6 | 9 |
|
7 | | -var reliableTrDimensionsVal, |
8 | | - div = document.createElement( "div" ); |
| 10 | +// Executing table tests requires only one layout, so they're executed |
| 11 | +// at the same time to save the second computation. |
| 12 | +function computeTableStyleTests() { |
| 13 | + if ( |
9 | 14 |
|
10 | | -// Finish early in limited (non-browser) environments |
11 | | -if ( !div.style ) { |
12 | | - return; |
13 | | -} |
| 15 | + // This is a singleton, we need to execute it only once |
| 16 | + !table || |
| 17 | + |
| 18 | + // Finish early in limited (non-browser) environments |
| 19 | + !table.style |
| 20 | + ) { |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + var trStyle, |
| 25 | + col = document.createElement( "col" ), |
| 26 | + tr = document.createElement( "tr" ), |
| 27 | + td = document.createElement( "td" ); |
14 | 28 |
|
15 | | -// Support: IE 10 - 11+ |
16 | | -// IE misreports `getComputedStyle` of table rows with width/height |
17 | | -// set in CSS while `offset*` properties report correct values. |
18 | | -// Support: Firefox 70+ |
19 | | -// Only Firefox includes border widths |
20 | | -// in computed dimensions. (gh-4529) |
21 | | -support.reliableTrDimensions = function() { |
22 | | - var table, tr, trStyle; |
23 | | - if ( reliableTrDimensionsVal == null ) { |
24 | | - table = document.createElement( "table" ); |
25 | | - tr = document.createElement( "tr" ); |
26 | | - |
27 | | - table.style.cssText = "position:absolute;left:-11111px;border-collapse:separate"; |
28 | | - tr.style.cssText = "box-sizing:content-box;border:1px solid;height:1px"; |
29 | | - div.style.height = "9px"; |
30 | | - |
31 | | - // Support: Android Chrome 86+ |
32 | | - // In our bodyBackground.html iframe, |
33 | | - // display for all div elements is set to "inline", |
34 | | - // which causes a problem only in Android Chrome, but |
35 | | - // not consistently across all devices. |
36 | | - // Ensuring the div is `display: block` |
37 | | - // gets around this issue. |
38 | | - div.style.display = "block"; |
39 | | - |
40 | | - documentElement |
41 | | - .appendChild( table ) |
42 | | - .appendChild( tr ) |
43 | | - .appendChild( div ); |
44 | | - |
45 | | - // Don't run until window is visible |
46 | | - if ( table.offsetWidth === 0 ) { |
47 | | - documentElement.removeChild( table ); |
48 | | - return; |
49 | | - } |
50 | | - |
51 | | - trStyle = window.getComputedStyle( tr ); |
52 | | - reliableTrDimensionsVal = ( Math.round( parseFloat( trStyle.height ) ) + |
53 | | - Math.round( parseFloat( trStyle.borderTopWidth ) ) + |
54 | | - Math.round( parseFloat( trStyle.borderBottomWidth ) ) ) === tr.offsetHeight; |
| 29 | + table.style.cssText = "position:absolute;left:-11111px;" + |
| 30 | + "border-collapse:separate;border-spacing:0"; |
| 31 | + tr.style.cssText = "box-sizing:content-box;border:1px solid;height:1px"; |
| 32 | + td.style.cssText = "height:9px;width:9px;padding:0"; |
55 | 33 |
|
| 34 | + col.span = 2; |
| 35 | + |
| 36 | + documentElement |
| 37 | + .appendChild( table ) |
| 38 | + .appendChild( col ) |
| 39 | + .parentNode |
| 40 | + .appendChild( tr ) |
| 41 | + .appendChild( td ) |
| 42 | + .parentNode |
| 43 | + .appendChild( td.cloneNode( true ) ); |
| 44 | + |
| 45 | + // Don't run until window is visible |
| 46 | + if ( table.offsetWidth === 0 ) { |
56 | 47 | documentElement.removeChild( table ); |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + trStyle = window.getComputedStyle( tr ); |
| 52 | + |
| 53 | + // Support: Firefox 135+ |
| 54 | + // Firefox always reports computed width as if `span` was 1. |
| 55 | + // Support: Safari 18.3+ |
| 56 | + // In Safari, computed width for columns is always 0. |
| 57 | + // In both these browsers, using `offsetWidth` solves the issue. |
| 58 | + // Support: IE 11+ |
| 59 | + // In IE, `<col>` computed width is `"auto"` unless `width` is set |
| 60 | + // explicitly via CSS so measurements there remain incorrect. Because of |
| 61 | + // the lack of a proper workaround, we accept this limitation, treating |
| 62 | + // IE as passing the test. |
| 63 | + reliableColDimensionsVal = isIE || Math.round( parseFloat( |
| 64 | + window.getComputedStyle( col ).width ) |
| 65 | + ) === 18; |
| 66 | + |
| 67 | + // Support: IE 10 - 11+ |
| 68 | + // IE misreports `getComputedStyle` of table rows with width/height |
| 69 | + // set in CSS while `offset*` properties report correct values. |
| 70 | + // Support: Firefox 70 - 135+ |
| 71 | + // Only Firefox includes border widths |
| 72 | + // in computed dimensions for table rows. (gh-4529) |
| 73 | + reliableTrDimensionsVal = Math.round( parseFloat( trStyle.height ) + |
| 74 | + parseFloat( trStyle.borderTopWidth ) + |
| 75 | + parseFloat( trStyle.borderBottomWidth ) ) === tr.offsetHeight; |
| 76 | + |
| 77 | + documentElement.removeChild( table ); |
| 78 | + |
| 79 | + // Nullify the table so it wouldn't be stored in the memory; |
| 80 | + // it will also be a sign that checks were already performed. |
| 81 | + table = null; |
| 82 | +} |
| 83 | + |
| 84 | +jQuery.extend( support, { |
| 85 | + reliableTrDimensions: function() { |
| 86 | + computeTableStyleTests(); |
| 87 | + return reliableTrDimensionsVal; |
| 88 | + }, |
| 89 | + |
| 90 | + reliableColDimensions: function() { |
| 91 | + computeTableStyleTests(); |
| 92 | + return reliableColDimensionsVal; |
57 | 93 | } |
58 | | - return reliableTrDimensionsVal; |
59 | | -}; |
60 | | -} )(); |
| 94 | +} ); |
61 | 95 |
|
62 | 96 | export { support }; |
0 commit comments