MediaWiki:Common.js: Difference between revisions
Appearance
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. */ | ||
/* | /* Add PDF + Share links to the Vector-2022 page tools bar */ | ||
$(function () { | $(function () { | ||
// | // Only on article pages (namespace 0) | ||
if (mw.config.get('wgNamespaceNumber') !== 0) return; | if (mw.config.get('wgNamespaceNumber') !== 0) return; | ||
// | // Find the Vector-2022 action bar (the row with Read / Edit / View history) | ||
var $actions = $(' | var $actions = $('.vector-page-toolbar .vector-page-tools .vector-menu-content-list'); | ||
if ($actions.length) { | if ($actions.length) { | ||
// PDF | // PDF link | ||
$actions. | $actions.prepend( | ||
'<li><a href="javascript:window.print()" title=" | '<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download as PDF">PDF</a></li>' | ||
); | ); | ||
// Share | // Share link | ||
$actions. | $actions.prepend( | ||
'<li><a href="javascript:navigator.share ? navigator.share({title: document.title, url: location.href}) : prompt(\' | '<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>'
);
}
});