MediaWiki:Common.js

From GladiusRO Wiki
Revision as of 02:37, 2 August 2026 by Ikhwan (talk | contribs)
Jump to navigation Jump to search

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.
/*
 * GladiusRO Wiki
 * Move the article Table of Contents to the bottom
 * of the existing left sidebar, below Tools.
 */

mw.loader.using(['mediawiki.util']).then(function () {

    function moveTOCToBottomOfSidebar() {
        var toc = document.querySelector('#toc');

        /*
         * Stop if:
         * 1. This page has no table of contents.
         * 2. The table of contents was already moved.
         */
        if (!toc || document.querySelector('#gladius-sidebar-toc')) {
            return;
        }

        /*
         * Find the existing MediaWiki left sidebar.
         */
        var sidebar =
            document.querySelector('#mw-panel') ||
            document.querySelector('#mw-navigation') ||
            document.querySelector('.sidebar');

        if (!sidebar) {
            return;
        }

        /*
         * Create the sidebar TOC container.
         */
        var tocContainer = document.createElement('div');

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

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

        /*
         * Put Contents at the very bottom of the sidebar.
         * This keeps the logo, navigation and Tools above it.
         */
        sidebar.appendChild(tocContainer);

        document.body.classList.add('gladius-toc-enabled');
    }

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

    /*
     * Run when the page loads.
     */
    initialiseGladiusTOC();

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