mediawiki-skins-Citizen/resources/skins.citizen.scripts/tables.js

34 lines
668 B
JavaScript
Raw Normal View History

/**
* Wrap table in div container to make it scrollable without breaking layout
*
* @param {HTMLTableElement} table
* @return {void}
*/
function wrapTable( table ) {
const wrapper = document.createElement( 'div' );
wrapper.classList.add( 'citizen-table-wrapper' );
table.parentNode.insertBefore( wrapper, table );
wrapper.appendChild( table );
}
/**
* @param {HTMLElement} bodyContent
* @return {void}
*/
function init( bodyContent ) {
if ( !bodyContent.querySelector( 'table' ) ) {
return;
}
const
tables = bodyContent.querySelectorAll( 'table' );
tables.forEach( ( table ) => {
wrapTable( table );
} );
}
module.exports = {
init: init
};