Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
| Line 5: | Line 5: | ||
var link = document.createElement('link'); | var link = document.createElement('link'); | ||
link.rel = 'stylesheet'; | link.rel = 'stylesheet'; | ||
| − | link.href = '/resources/lightbox2/lightbox.css'; // or .min.css | + | link.href = '/w/resources/lightbox2/lightbox.css'; // or .min.css |
document.head.appendChild(link); | document.head.appendChild(link); | ||
// Load Lightbox2 JS | // Load Lightbox2 JS | ||
var script = document.createElement('script'); | var script = document.createElement('script'); | ||
| − | script.src = '/resources/lightbox2/lightbox.min.js'; | + | script.src = '/w/resources/lightbox2/lightbox.min.js'; |
document.body.appendChild(script); | document.body.appendChild(script); | ||
}); | }); | ||
Revision as of 17:17, 23 May 2025
/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using('jquery').then(function() {
// Load Lightbox2 CSS
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = '/w/resources/lightbox2/lightbox.css'; // or .min.css
document.head.appendChild(link);
// Load Lightbox2 JS
var script = document.createElement('script');
script.src = '/w/resources/lightbox2/lightbox.min.js';
document.body.appendChild(script);
});
mw.hook('wikipage.content').add(function($content) {
$content.find('.gallerybox a.image').each(function() {
$(this).attr('data-lightbox', 'gallery');
var caption = $(this).closest('.gallerybox').find('.gallerytext').text().trim();
if (caption) {
$(this).attr('data-title', caption);
}
});
});