MediaWiki:Common.js

    From UNITApedia

    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.
    mw.loader.using('mediawiki.util', function () {
      $(function () {
        // PDF Export Button (for InternationalisationForms)
        var cats = mw.config.get('wgCategories') || [];
        var targetCat = 'InternationalisationForms';
    
        if (cats.indexOf(targetCat) !== -1) {
          var $pdfLink = $('<a>')
            .text('📄 Export this page to PDF')
            .attr('href', '#')
            .css({
              display: 'inline-block',
              padding: '0.39em 0.77em',
              'font-size': '0.82em',
              'background-color': '#19529E',
              color: '#fff',
              'text-decoration': 'none',
              'border-radius': '3px',
              margin: '0.39em'
            })
            .click(function (e) {
              e.preventDefault();
              window.print();
            });
    
          $('#content').before(
            $('<div>')
              .attr('id', 'export-to-pdf-container')
              .css({ 'text-align': 'right', padding: '0.5em' })
              .append($pdfLink)
          );
        }
    
        // Hide toolbox for anonymous users
        if (mw.config.get('wgUserName') === null) {
          $('#p-tb').hide();
          $('#p-toolbox, #vector-page-tools, #vector-page-tools-dropdown').hide();
        }
    
        // Hide “Switch to old look”
        function hideSkinSwitcher() {
          $('a').filter(function () {
            return $(this).text().trim() === 'Switch to old look';
          }).closest('li, span, div').hide();
        }
    
        hideSkinSwitcher();
        const observer = new MutationObserver(hideSkinSwitcher);
        observer.observe(document.body, { childList: true, subtree: true });
    
        // 🔽 COLLAPSIBLE TREE TABLE
        $(".treetable .tree-row").each(function () {
          const id = $(this).data("id");
          const parent = $(this).data("parent");
    
          if (parent) {
            $(this).addClass("child-of-" + parent.replace(/\s/g, "-")).hide();
          } else {
            $(this).addClass("root-row").css("cursor", "pointer");
          }
        });
    
        $(".treetable .root-row").on("click", function () {
          const id = $(this).data("id").replace(/\s/g, "-");
          $(".child-of-" + id).toggle();
        });
      });
    });