mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-24 07:43:47 +00:00
1ccb5be4c3
Bug: T374493 Change-Id: I276a58635504cfb30c3bcdec93f6bb29f5df730b
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const config = require( './config.json' );
|
|
const init = () => {
|
|
if ( !config.VectorWrapTablesTemporary ) {
|
|
return;
|
|
}
|
|
const tables = document.querySelectorAll( '.mw-parser-output table.wikitable' );
|
|
let numberBigTables = 0;
|
|
Array.from( tables ).forEach( ( table ) => {
|
|
const styles = window.getComputedStyle( table );
|
|
const isFloat = styles.getPropertyValue( 'float' ) === 'right' || styles.getPropertyValue( 'float' ) === 'left';
|
|
|
|
// Don't wrap tables within tables
|
|
const parent = table.parentElement;
|
|
if (
|
|
parent &&
|
|
!parent.matches( '.noresize' ) &&
|
|
!parent.closest( 'table' ) &&
|
|
!isFloat
|
|
) {
|
|
const tableRect = table.getBoundingClientRect();
|
|
const tableWidth = tableRect && tableRect.width;
|
|
const wrapper = document.createElement( 'div' );
|
|
wrapper.classList.add( 'noresize' );
|
|
parent.insertBefore( wrapper, table );
|
|
wrapper.appendChild( table );
|
|
|
|
if ( tableWidth > 948 ) {
|
|
numberBigTables++;
|
|
}
|
|
}
|
|
} );
|
|
if ( numberBigTables > 0 ) {
|
|
// @ts-ignore
|
|
mw.errorLogger.logError(
|
|
new Error( `T374493: ${ numberBigTables } tables wrapped` ),
|
|
'error.web-team'
|
|
);
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
init
|
|
};
|