MediaWiki:Common.js

From MDrivenWiki
Revision as of 20:25, 26 October 2023 by Edgar (talk | contribs)

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
This page was edited 34 days ago on 10/07/2024. What links here
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function () {
    $.get(mw.util.wikiScript('api'), {
        action: 'query',
        meta: 'userinfo',
        format: 'json'
    }).done(function (data) {
        if (data.query.userinfo.id !== 0) { 
            var username = data.query.userinfo.name;
            var userLink = mw.util.getUrl('User:' + username);
            $('#user-info').html('<a href="' + userLink + '" class="text-white">' + username + '</a>');
        }
    });
});


document.getElementById('offcanvas-toggler').addEventListener('click', function() {
    var sidebar = document.getElementById('offcanvas-menu');
    if (sidebar.classList.contains('show')) {
        sidebar.classList.remove('show');
    } else {
        sidebar.classList.add('show');
    }
});


(function() {
    function toggleSection(header) {
        var submenu = header.nextElementSibling;
        if (submenu.style.display === "none" || submenu.style.display === "") {
            submenu.style.display = "block";
            localStorage.setItem('expandedSection', header.innerText.trim());
        } else {
            submenu.style.display = "none";
            localStorage.setItem('expandedSection', '');
        }
    }

    window.toggleSection = toggleSection; 

    window.onload = function() {
        var expandedSection = localStorage.getItem('expandedSection');
        if(expandedSection) {
            var headers = document.querySelectorAll('.menu-header');
            for(var i = 0; i < headers.length; i++) {
                if(headers[i].innerText.trim() === expandedSection) {
                    toggleSection(headers[i]);
                    break;
                }
            }
        }
    };
})();


$(document).ready(function() {
    $('#offcanvas-close').on('click', function() {
        $('#offcanvas-menu').removeClass('show');
    });
});
This page was edited 34 days ago on 10/07/2024. What links here