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' );
var commentBtn = closest( target, 'verse-action-commentary' );
    if ( commentBtn ) {
if ( commentBtn ) {
      e.preventDefault();
  e.preventDefault();
      var verseId = commentBtn.getAttribute( 'data-verse' );
  var verseId = commentBtn.getAttribute( 'data-verse' );
      if ( !verseId ) return;
  if ( !verseId ) return;


      var allBodies = document.querySelectorAll( '.commentary-body[data-verse="' + verseId + '"]' );
  // Match all commentary bodies for this verse by id prefix
      var allBtns   = document.querySelectorAll( '.verse-action-commentary[data-verse="' + verseId + '"]' );
  var allBodies = document.querySelectorAll( '[id^="commentary-body-' + verseId + '"]' );
      var isOpen    = allBodies.length && allBodies[0].classList.contains( 'open' );
  var allBtns   = document.querySelectorAll( '.verse-action-commentary[data-verse="' + verseId + '"]' );


      // Close every open commentary first
  var isOpen = allBodies.length && allBodies[0].classList.contains( 'open' );
      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
  // Close all open commentaries on the page first
      if ( !isOpen ) {
  document.querySelectorAll( '.commentary-body.open' ).forEach( function ( el ) {
        allBodies.forEach( function ( el ) { el.classList.add( 'open' ); } );
    el.classList.remove( 'open' );
        allBtns.forEach(  function ( el ) { el.classList.add( 'active' ); } );
  } );
      }
  document.querySelectorAll( '.verse-action-commentary.active' ).forEach( function ( el ) {
      return;
    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 ── */