MediaWiki:Common.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
// Load Fancybox CSS
$('<link>')
.appendTo('head')
.attr({
type: 'text/css',
rel: 'stylesheet',
href: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css'
});
// Load Fancybox JS
$.getScript('https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js', function() {
// Apply Fancybox to all images in the gallery
$('.fancybox-gallery a').each(function() {
var $link = $(this);
var fileDescriptionUrl = $link.attr('href'); // Get the URL to the file description page
// Modify the file description URL to get the direct image link
// Wikimedia stores the full-size image at a similar URL but without "/thumb/" and the size suffix
var fullImageUrl = fileDescriptionUrl.replace('/wiki/File:', '/w/images/'); // Adjust URL for the full image path
// Set the link to the full image for Fancybox
$link.attr('href', fullImageUrl);
$link.attr('data-fancybox', 'gallery'); // Enable Fancybox for this link
});
// Initialize Fancybox with custom settings
$('[data-fancybox="gallery"]').fancybox({
buttons: [
'zoom',
'slideShow',
'fullScreen',
'thumbs',
'close'
],
protect: true,
loop: true,
// Set max width and height to 90% of the screen
maxWidth: '90%',
maxHeight: '90%',
width: 'auto',
height: 'auto',
responsive: true,
transitionEffect: 'fade',
mobile: {
clickSlide: 'close',
clickOutside: 'close'
}
});
});