Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
| Line 22: | Line 22: | ||
var caption = $link.closest('.gallerybox').find('.gallerytext').text().trim(); | var caption = $link.closest('.gallerybox').find('.gallerytext').text().trim(); | ||
| − | + | if (caption) { | |
| − | + | caption += "<br><small style='display:block;margin-top:5px;'>Press Esc or click outside the image to exit</small>"; | |
| − | + | $link.attr('data-title', caption); | |
| + | } | ||
| + | |||
}); | }); | ||
}); | }); | ||
Revision as of 17:26, 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() {
var $link = $(this);
var fileUrl = $link.find('img').attr('src').replace(/thumb\//, '').replace(/\/[^\/]+$/, '');
$link.attr('href', fileUrl);
$link.attr('data-lightbox', 'gallery');
var caption = $link.closest('.gallerybox').find('.gallerytext').text().trim();
if (caption) {
caption += "<br><small style='display:block;margin-top:5px;'>Press Esc or click outside the image to exit</small>";
$link.attr('data-title', caption);
}
});
});