MediaWiki:Common.js: Difference between revisions
Horia Modran (talk | contribs) No edit summary |
Horia Modran (talk | contribs) No edit summary |
||
Line 9: | Line 9: | ||
if ( cats.indexOf(targetCat) !== -1 ) { | if ( cats.indexOf(targetCat) !== -1 ) { | ||
// Create and style the button-like link | // 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', | |||
padding: '0.5em 1em', | |||
'font-size': '1em', | |||
'background-color': '#007bff', | |||
color: '#fff', | |||
'text-decoration': 'none', | |||
'border-radius': '4px', | |||
margin: '0.5em' | |||
}) | }) | ||
.click(function(e){ | .click(function(e){ | ||
Line 25: | Line 26: | ||
window.print(); | window.print(); | ||
}) | }) | ||
$('#content').before( | |||
. | $('<div>') | ||
.attr('id', 'export-to-pdf-container') | |||
.css({ 'text-align': 'right', padding: '0.5em' }) | |||
.append($pdfLink) | |||
); | |||
} | } | ||
}); | }); | ||
}); | }); |
Revision as of 07:06, 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
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'
})
.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)
);
}
});
});