Skip to content

Commit

Permalink
perf(core): ⚡️ check for nowrap classes before constructing class
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair3149 committed May 29, 2024
1 parent 06d10b9 commit 2bbb1d9
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions resources/skins.citizen.scripts/overflowElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -247,13 +236,25 @@ 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 ) {
overflowElements.forEach( ( el ) => {
const overflowElement = new OverflowElement( el );
overflowElement.init();
} );
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 = {
Expand Down

0 comments on commit 2bbb1d9

Please sign in to comment.