Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js

MediaWiki interface page
Revision as of 00:57, 25 February 2026 by Redheadkelly (talk | contribs) (Created page with "Any JavaScript here will be loaded for all users on every page load.: ============================================================ Ross Tabs — tab switching logic Add this block to MediaWiki:Common.js ============================================================: ( function () { 'use strict'; function initRossTabs( container ) { var buttons = container.querySelectorAll( '.ross-tab-btn' ); var panels = container.querySelectorA...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/* ============================================================
   Ross Tabs — tab switching logic
   Add this block to MediaWiki:Common.js
   ============================================================ */
( function () {
    'use strict';

    function initRossTabs( container ) {
        var buttons = container.querySelectorAll( '.ross-tab-btn' );
        var panels  = container.querySelectorAll( '.ross-tab-panel' );

        buttons.forEach( function ( btn ) {
            btn.addEventListener( 'click', function () {
                var targetId = btn.getAttribute( 'data-tab' );

                // Deactivate all buttons and panels in this container
                buttons.forEach( function ( b ) { b.classList.remove( 'active' ); } );
                panels.forEach(  function ( p ) { p.classList.remove( 'active' ); } );

                // Activate the clicked button and its panel
                btn.classList.add( 'active' );
                var target = container.querySelector( '#' + targetId );
                if ( target ) { target.classList.add( 'active' ); }
            } );
        } );
    }

    function initAllRossTabs() {
        document.querySelectorAll( '.ross-tabs-container' ).forEach( initRossTabs );
    }

    // Initialise on DOM ready (works whether the script runs early or late)
    if ( document.readyState === 'loading' ) {
        document.addEventListener( 'DOMContentLoaded', initAllRossTabs );
    } else {
        initAllRossTabs();
    }

    // Re-initialise after any MediaWiki dynamic content load (e.g. VisualEditor)
    mw.hook( 'wikipage.content' ).add( function ( $content ) {
        $content[ 0 ].querySelectorAll( '.ross-tabs-container' ).forEach( initRossTabs );
    } );

}() );