mediawiki-skins-Vector/resources/skins.vector.js/tables.js
bwang 711f67ce00 Avoid wrapping floated tables using computed styles
Bug: T366314
Change-Id: I71657b7f1f26bcf52f5ade5b7668955a1f4df24b
2024-06-07 16:49:30 +00:00

30 lines
808 B
JavaScript

const config = require( './config.json' );
const init = () => {
if ( !config.VectorWrapTablesTemporary ) {
return;
}
const tables = document.querySelectorAll( '.mw-parser-output table.wikitable' );
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 wrapper = document.createElement( 'div' );
wrapper.classList.add( 'noresize' );
parent.insertBefore( wrapper, table );
wrapper.appendChild( table );
}
} );
};
module.exports = {
init
};