MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 19: | Line 19: | ||
/* ── Commentary toggle ── */ | /* ── Commentary toggle ── */ | ||
var commentBtn = closest( target, 'verse-action-commentary' ); | |||
if ( commentBtn ) { | |||
e.preventDefault(); | |||
var verseId = commentBtn.getAttribute( 'data-verse' ); | |||
if ( !verseId ) return; | |||
// Match all commentary bodies for this verse by id prefix | |||
var allBodies = document.querySelectorAll( '[id^="commentary-body-' + verseId + '"]' ); | |||
var allBtns = document.querySelectorAll( '.verse-action-commentary[data-verse="' + verseId + '"]' ); | |||
var isOpen = allBodies.length && allBodies[0].classList.contains( 'open' ); | |||
// Close all open commentaries on the page first | |||
document.querySelectorAll( '.commentary-body.open' ).forEach( function ( el ) { | |||
el.classList.remove( 'open' ); | |||
} ); | |||
document.querySelectorAll( '.verse-action-commentary.active' ).forEach( function ( el ) { | |||
el.classList.remove( 'active' ); | |||
} ); | |||
// If it was closed, open it | |||
if ( !isOpen ) { | |||
allBodies.forEach( function ( el ) { el.classList.add( 'open' ); } ); | |||
allBtns.forEach( function ( el ) { el.classList.add( 'active' ); } ); | |||
} | |||
return; | |||
} | |||
/* ── Copy verse — copies verse ID for crosslinking ── */ | /* ── Copy verse — copies verse ID for crosslinking ── */ | ||