MediaWiki:Common.js: Difference between revisions

From GladiusRO Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
/*
/*
  * GladiusRO Wiki
  * GladiusRO Wiki
  * Move the article Table of Contents to the bottom
  * Move the article Table of Contents below the Tools section.
* of the existing left sidebar, below Tools.
  */
  */


mw.loader.using(['mediawiki.util']).then(function () {
(function ($, mw) {
    'use strict';


     function moveTOCToBottomOfSidebar() {
     function moveTOCBelowTools() {
         var toc = document.querySelector('#toc');
         var toc = document.getElementById('toc');
        var tools = document.getElementById('p-tb');


         /*
         /*
         * Stop if:
         * Stop when:
         * 1. This page has no table of contents.
         * - The page does not have a TOC.
         * 2. The table of contents was already moved.
         * - The Tools section cannot be found.
        * - The TOC was already moved.
         */
         */
         if (!toc || document.querySelector('#gladius-sidebar-toc')) {
         if (!toc || !tools) {
             return;
             return;
         }
         }


         /*
         if (document.getElementById('gladius-sidebar-toc')) {
        * Find the existing MediaWiki left sidebar.
        */
        var sidebar =
            document.querySelector('#mw-panel') ||
            document.querySelector('#mw-navigation') ||
            document.querySelector('.sidebar');
 
        if (!sidebar) {
             return;
             return;
         }
         }


         /*
         /*
         * Create the sidebar TOC container.
         * Create a new sidebar section for Contents.
         */
         */
         var tocContainer = document.createElement('div');
         var tocContainer = document.createElement('div');


         tocContainer.id = 'gladius-sidebar-toc';
         tocContainer.id = 'gladius-sidebar-toc';
         tocContainer.className = 'mw-portlet portal';
         tocContainer.className = 'portal mw-portlet';
         tocContainer.setAttribute('role', 'navigation');
         tocContainer.setAttribute('role', 'navigation');
         tocContainer.setAttribute('aria-label', 'Page contents');
         tocContainer.setAttribute('aria-label', 'Page contents');


         /*
         /*
         * Move the original article TOC into the new container.
         * Move the existing article TOC into the new container.
         */
         */
         tocContainer.appendChild(toc);
         tocContainer.appendChild(toc);


         /*
         /*
         * Put Contents at the very bottom of the sidebar.
         * Insert Contents immediately below the Tools section.
        * This keeps the logo, navigation and Tools above it.
         */
         */
         sidebar.appendChild(tocContainer);
         if (tools.parentNode) {
 
            tools.parentNode.insertBefore(
        document.body.classList.add('gladius-toc-enabled');
                tocContainer,
                tools.nextSibling
            );
        }
     }
     }


     /*
     /*
     * Wait briefly so the skin can finish loading
     * Wait until the MediaWiki page is ready.
    * the logo, navigation and Tools sections first.
     */
     */
     function initialiseGladiusTOC() {
     $(function () {
         window.setTimeout(moveTOCToBottomOfSidebar, 150);
         moveTOCBelowTools();
     }
     });


     /*
     /*
     * Run when the page loads.
     * Also support dynamically loaded article content.
     */
     */
     initialiseGladiusTOC();
     mw.hook('wikipage.content').*dd(function () {
        window.se*Timeout(moveTOCBelowTools, 50);
  * });


    /*
}(jQuery, mediaWiki));
    * Run again if MediaWiki dynamically refreshes
    * the article content.
    */
    mw.hook('wikipage.content').*dd(function () {
        initialis*GladiusTOC();
    });
});

Revision as of 02:41, 2 August 2026

/*
 * GladiusRO Wiki
 * Move the article Table of Contents below the Tools section.
 */

(function ($, mw) {
    'use strict';

    function moveTOCBelowTools() {
        var toc = document.getElementById('toc');
        var tools = document.getElementById('p-tb');

        /*
         * Stop when:
         * - The page does not have a TOC.
         * - The Tools section cannot be found.
         * - The TOC was already moved.
         */
        if (!toc || !tools) {
            return;
        }

        if (document.getElementById('gladius-sidebar-toc')) {
            return;
        }

        /*
         * Create a new sidebar section for Contents.
         */
        var tocContainer = document.createElement('div');

        tocContainer.id = 'gladius-sidebar-toc';
        tocContainer.className = 'portal mw-portlet';
        tocContainer.setAttribute('role', 'navigation');
        tocContainer.setAttribute('aria-label', 'Page contents');

        /*
         * Move the existing article TOC into the new container.
         */
        tocContainer.appendChild(toc);

        /*
         * Insert Contents immediately below the Tools section.
         */
        if (tools.parentNode) {
            tools.parentNode.insertBefore(
                tocContainer,
                tools.nextSibling
            );
        }
    }

    /*
     * Wait until the MediaWiki page is ready.
     */
    $(function () {
        moveTOCBelowTools();
    });

    /*
     * Also support dynamically loaded article content.
     */
    mw.hook('wikipage.content').*dd(function () {
        window.se*Timeout(moveTOCBelowTools, 50);
  * });

}(jQuery, mediaWiki));