MediaWiki:Common.js: Difference between revisions

    From UNITApedia
    No edit summary
    No edit summary
     
    (4 intermediate revisions by the same user not shown)
    Line 1: Line 1:
    mw.loader.using('mediawiki.util', function () {
    mw.loader.using('mediawiki.util', function () {
       $(function(){
       $(function () {
         // Get the list of categories assigned to this page
         // 📄 PDF Export Button (for InternationalisationForms pages)
         var cats = mw.config.get('wgCategories') || [];
         var cats = mw.config.get('wgCategories') || [];
        // Specify the category you want to target
         var targetCat = 'InternationalisationForms';
         var targetCat = 'InternationalisationForms';


        // Only proceed if the page is in that category
         if (cats.indexOf(targetCat) !== -1) {
         if ( cats.indexOf(targetCat) !== -1 ) {
           var $pdfLink = $('<a>')
           // Create and style the button-like link
        var $pdfLink = $('<a>')
             .text('📄 Export this page to PDF')
             .text('📄 Export this page to PDF')
             .attr('href','#')
             .attr('href', '#')
             .css({
             .css({
              display: 'inline-block',
              display: 'inline-block',
            padding: '0.39em 0.77em',
              padding: '0.39em 0.77em',
            'font-size': '0.82em',
              'font-size': '0.82em',
            'background-color': '#19529E',
              'background-color': '#19529E',
            color: '#fff',
              color: '#fff',
            'text-decoration': 'none',
              'text-decoration': 'none',
            'border-radius': '3px',
              'border-radius': '3px',
            margin: '0.39em'
              margin: '0.39em'
             })
             })
             .click(function(e){
             .click(function (e) {
               e.preventDefault();
               e.preventDefault();
               window.print();
               window.print();
             })
             });
            $('#content').before(
     
          $('#content').before(
             $('<div>')
             $('<div>')
            .attr('id', 'export-to-pdf-container')
              .attr('id', 'export-to-pdf-container')
            .css({ 'text-align': 'right', padding: '0.5em' })
              .css({ 'text-align': 'right', padding: '0.5em' })
            .append($pdfLink)
              .append($pdfLink)
        );
          );
         }
         }
            // HIDE TOOLBOX for anonymous users
     
        // 🧰 Hide toolbox for anonymous users
         if (mw.config.get('wgUserName') === null) {
         if (mw.config.get('wgUserName') === null) {
          // For classic skins
           $('#p-tb').hide();
           $('#p-tb').hide();
          $('#p-toolbox, #vector-page-tools, #vector-page-tools-dropdown').hide();
        }


          // For Vector 2022: also try hiding dropdown
        // 🧼 Hide “Switch to old look” link
           $('#p-toolbox, #vector-page-tools, #vector-page-tools-dropdown').hide();
        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 (expand/collapse rows based on parent)
        $(".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();
        });
       });
       });
    });
    });

    Latest revision as of 11:37, 24 July 2025

    mw.loader.using('mediawiki.util', function () {
      $(function () {
        // 📄 PDF Export Button (for InternationalisationForms pages)
        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” link
        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 (expand/collapse rows based on parent)
        $(".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();
        });
      });
    });