2024-05-29 22:35:45 +00:00
|
|
|
const config = require( './config.json' );
|
2024-05-24 16:15:14 +00:00
|
|
|
const init = () => {
|
2024-05-29 22:35:45 +00:00
|
|
|
if ( !config.VectorWrapTablesTemporary ) {
|
|
|
|
return;
|
|
|
|
}
|
2024-06-07 15:52:40 +00:00
|
|
|
const tables = document.querySelectorAll( '.mw-parser-output table.wikitable' );
|
2024-05-24 16:15:14 +00:00
|
|
|
Array.from( tables ).forEach( ( table ) => {
|
2024-06-07 15:52:40 +00:00
|
|
|
const styles = window.getComputedStyle( table );
|
|
|
|
const isFloat = styles.getPropertyValue( 'float' ) === 'right' || styles.getPropertyValue( 'float' ) === 'left';
|
|
|
|
|
2024-05-24 16:15:14 +00:00
|
|
|
// Don't wrap tables within tables
|
|
|
|
const parent = table.parentElement;
|
2024-05-28 21:36:07 +00:00
|
|
|
if (
|
2024-06-07 15:52:40 +00:00
|
|
|
parent &&
|
2024-05-28 21:36:07 +00:00
|
|
|
!parent.matches( '.noresize' ) &&
|
2024-06-07 15:52:40 +00:00
|
|
|
!parent.closest( 'table' ) &&
|
|
|
|
!isFloat
|
2024-05-28 21:36:07 +00:00
|
|
|
) {
|
2024-05-24 16:15:14 +00:00
|
|
|
const wrapper = document.createElement( 'div' );
|
|
|
|
wrapper.classList.add( 'noresize' );
|
|
|
|
parent.insertBefore( wrapper, table );
|
|
|
|
wrapper.appendChild( table );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init
|
|
|
|
};
|