perf(core): ️ check for nowrap classes before constructing class

This commit is contained in:
alistair3149 2024-05-29 14:02:57 -04:00
parent 06d10b99ce
commit 2bbb1d9408
No known key found for this signature in database

View file

@ -134,18 +134,7 @@ class OverflowElement {
return;
}
try {
const nowrapClasses = config.wgCitizenOverflowNowrapClasses;
if ( !nowrapClasses || !Array.isArray( nowrapClasses ) ) {
mw.log.error( '[Citizen] Invalid or missing $wgCitizenOverflowNowrapClasses. Cannot proceed with wrapping element.' );
return;
}
const parentNode = this.element.parentNode;
if ( nowrapClasses.some( ( cls ) => this.element.classList.contains( cls ) ) ) {
return;
}
const wrapper = document.createElement( 'div' );
wrapper.className = 'citizen-overflow-wrapper';
@ -247,14 +236,26 @@ class OverflowElement {
* @return {void}
*/
function init( bodyContent ) {
const nowrapClasses = config.wgCitizenOverflowNowrapClasses;
if ( !nowrapClasses || !Array.isArray( nowrapClasses ) ) {
mw.log.error( '[Citizen] Invalid or missing $wgCitizenOverflowNowrapClasses. Cannot proceed with wrapping element.' );
return;
}
const overflowElements = bodyContent.querySelectorAll( '.citizen-overflow, table:not( table table )' );
if ( overflowElements.length > 0 ) {
if ( !overflowElements.length ) {
return;
}
overflowElements.forEach( ( el ) => {
if ( nowrapClasses.some( ( cls ) => el.classList.contains( cls ) ) ) {
return;
}
const overflowElement = new OverflowElement( el );
overflowElement.init();
} );
}
}
module.exports = {
init: init