Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
| Line 16: | Line 16: | ||
mw.hook('wikipage.content').add(function($content) { | mw.hook('wikipage.content').add(function($content) { | ||
$content.find('.gallerybox a.image').each(function() { | $content.find('.gallerybox a.image').each(function() { | ||
| − | $(this).attr('data-lightbox', 'gallery'); | + | var $link = $(this); |
| + | var fileUrl = $link.find('img').attr('src').replace(/thumb\//, '').replace(/\/[^\/]+$/, ''); | ||
| + | $link.attr('href', fileUrl); | ||
| + | $link.attr('data-lightbox', 'gallery'); | ||
| − | var caption = $ | + | var caption = $link.closest('.gallerybox').find('.gallerytext').text().trim(); |
if (caption) { | if (caption) { | ||
| − | $ | + | $link.attr('data-title', caption); |
} | } | ||
}); | }); | ||
}); | }); | ||
Revision as of 17:18, 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) {
$link.attr('data-title', caption);
}
});
});