MediaWiki:Common.js: Difference between revisions

    From UNITApedia
    (Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: mw.loader.using(['mediawiki.util'], function () { $(function () { // Build the link styled as a button var $pdfLink = $('<a>') .text('📄 Export this page to PDF') .attr('href', '#') .css({ display: 'inline-block', padding: '0.5em 1em', 'font-size': '1em', 'background-color': '#007bff', color: '#fff', 'text-decoration': '...")
     
    No edit summary
    Line 1: Line 1:
    /* Any JavaScript here will be loaded for all users on every page load. */
    mw.loader.using('mediawiki.util', function () {
    mw.loader.using(['mediawiki.util'], function () {
       $(function(){
       $(function () {
         // Get the list of categories assigned to this page
         // Build the link styled as a button
         var cats = mw.config.get('wgCategories') || [];
         var $pdfLink = $('<a>')
        // Specify the category you want to target
          .text('📄 Export this page to PDF')
        var targetCat = 'InternationalizationForms';
          .attr('href', '#')
          .css({
            display: 'inline-block',
            padding: '0.5em 1em',
            'font-size': '1em',
            'background-color': '#007bff',
            color: '#fff',
            'text-decoration': 'none',
            'border-radius': '4px',
            margin: '0.5em'
          })
          .on('click', function (e) {
            e.preventDefault();
            window.print();  // triggers browser print dialog (Save as PDF)
          });


         // Insert into the page: choose where you like, e.g. top of content
         // Only proceed if the page is in that category
         $('#content').before(
         if ( cats.indexOf(targetCat) !== -1 ) {
           $('<div>')
          // Create and style the button-like link
             .attr('id', 'export-to-pdf-container')
           $('<a>')
             .css({ 'text-align': 'right', padding: '0.5em' })
            .text('📄 Export this page to PDF')
             .append($pdfLink)
             .attr('href','#')
        );
             .css({
              display:'inline-block',
              padding:'0.5em 1em',
              background:'#007bff',
              color:'#fff',
              'border-radius':'4px',
              margin:'0.5em',
              'text-decoration':'none'
            })
             .click(function(e){
              e.preventDefault();
              window.print();
            })
            // Insert it above the content area
            .prependTo('#content');
        }
       });
       });
    });
    });

    Revision as of 07:03, 12 May 2025

    mw.loader.using('mediawiki.util', function () {
      $(function(){
        // Get the list of categories assigned to this page
        var cats = mw.config.get('wgCategories') || [];
        // Specify the category you want to target
        var targetCat = 'InternationalizationForms';
    
        // Only proceed if the page is in that category
        if ( cats.indexOf(targetCat) !== -1 ) {
          // Create and style the button-like link
          $('<a>')
            .text('📄 Export this page to PDF')
            .attr('href','#')
            .css({
              display:'inline-block',
              padding:'0.5em 1em',
              background:'#007bff',
              color:'#fff',
              'border-radius':'4px',
              margin:'0.5em',
              'text-decoration':'none'
            })
            .click(function(e){
              e.preventDefault();
              window.print();
            })
            // Insert it above the content area
            .prependTo('#content');
        }
      });
    });