Jump to content

MediaWiki:Common.js: Difference between revisions

From International Treaty Law Wiki
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
/* Dezente PDF- und Share-Links im Wikipedia-Stil */
/* Add PDF + Share links to the Vector-2022 page tools bar */
$(function () {
$(function () {


     // Nur auf Artikelseiten (Namespace 0)
     // Only on article pages (namespace 0)
     if (mw.config.get('wgNamespaceNumber') !== 0) return;
     if (mw.config.get('wgNamespaceNumber') !== 0) return;


     // Container für die Action-Links (rechts oben)
     // Find the Vector-2022 action bar (the row with Read / Edit / View history)
     var $actions = $('#p-views ul');
     var $actions = $('.vector-page-toolbar .vector-page-tools .vector-menu-content-list');


     if ($actions.length) {
     if ($actions.length) {


         // PDF-Link (klein, unauffällig)
         // PDF link
         $actions.append(
         $actions.prepend(
             '<li><a href="javascript:window.print()" title="Als PDF drucken">PDF</a></li>'
             '<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download as PDF">PDF</a></li>'
         );
         );


         // Share-Link (klein, unauffällig)
         // Share link
         $actions.append(
         $actions.prepend(
             '<li><a href="javascript:navigator.share ? navigator.share({title: document.title, url: location.href}) : prompt(\'Link kopieren:\', location.href)" title="Seite teilen">Teilen</a></li>'
             '<li class="vector-menu-content-list-item"><a href="javascript:navigator.share ? navigator.share({title: document.title, url: location.href}) : prompt(\'Copy link:\', location.href)" title="Share this page">Share</a></li>'
         );
         );
     }
     }
});
});

Revision as of 22:18, 17 January 2026

/* Any JavaScript here will be loaded for all users on every page load. */
/* Add PDF + Share links to the Vector-2022 page tools bar */
$(function () {

    // Only on article pages (namespace 0)
    if (mw.config.get('wgNamespaceNumber') !== 0) return;

    // Find the Vector-2022 action bar (the row with Read / Edit / View history)
    var $actions = $('.vector-page-toolbar .vector-page-tools .vector-menu-content-list');

    if ($actions.length) {

        // PDF link
        $actions.prepend(
            '<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download as PDF">PDF</a></li>'
        );

        // Share link
        $actions.prepend(
            '<li class="vector-menu-content-list-item"><a href="javascript:navigator.share ? navigator.share({title: document.title, url: location.href}) : prompt(\'Copy link:\', location.href)" title="Share this page">Share</a></li>'
        );
    }
});