| 1 |
const config = require( './config.json' ); |
| 2 |
const init = () => { |
| 3 |
if ( !config.VectorWrapTablesTemporary ) { |
| 4 |
return; |
| 5 |
} |
| 6 |
const tables = document.querySelectorAll( '.mw-parser-output > table.wikitable' ); |
| 7 |
let numberBigTables = 0; |
| 8 |
Array.from( tables ).forEach( ( table ) => { |
| 9 |
const styles = window.getComputedStyle( table ); |
| 10 |
const isFloat = styles.getPropertyValue( 'float' ) === 'right' || styles.getPropertyValue( 'float' ) === 'left'; |
| 11 |
|
| 12 |
|
| 13 |
const parent = table.parentElement; |
| 14 |
if ( |
| 15 |
parent && |
| 16 |
!parent.matches( '.noresize' ) && |
| 17 |
!parent.closest( 'table' ) && |
| 18 |
!isFloat |
| 19 |
) { |
| 20 |
const tableRect = table.getBoundingClientRect(); |
| 21 |
const tableWidth = tableRect && tableRect.width; |
| 22 |
const wrapper = document.createElement( 'div' ); |
| 23 |
wrapper.classList.add( 'noresize' ); |
| 24 |
parent.insertBefore( wrapper, table ); |
| 25 |
wrapper.appendChild( table ); |
| 26 |
|
| 27 |
if ( tableWidth > 948 ) { |
| 28 |
numberBigTables++; |
| 29 |
} |
| 30 |
} |
| 31 |
} ); |
| 32 |
if ( numberBigTables > 0 ) { |
| 33 |
|
| 34 |
mw.errorLogger.logError( |
| 35 |
new Error( `T374493: ${ numberBigTables } tables wrapped` ), |
| 36 |
'error.web-team' |
| 37 |
); |
| 38 |
} |
| 39 |
}; |
| 40 |
|
| 41 |
module.exports = { |
| 42 |
init |
| 43 |
}; |