MediaWiki:Common.js

    From UNITApedia
    Revision as of 06:50, 12 May 2025 by Horia Modran (talk | contribs) (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': '...")
    (diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

    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.
    /* 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': '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
        $('#content').before(
          $('<div>')
            .attr('id', 'export-to-pdf-container')
            .css({ 'text-align': 'right', padding: '0.5em' })
            .append($pdfLink)
        );
      });
    });