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 inside the gallery
$('.fancybox-gallery img').each(function() {
var $image = $(this);
var src = $image.attr('src'); // Get image source
// Wrap each image in a Fancybox-enabled link
$image.wrap('<a data-fancybox="gallery" href="' + src + '"></a>');
});
// 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', // Customize for mobile if needed
clickOutside: 'close'
}
});
});