MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
Line 19: | Line 19: | ||
// Get the thumbnail URL | // Get the thumbnail URL | ||
var thumbnailUrl = $image.attr('src'); | var thumbnailUrl = $image.attr('src'); | ||
// Convert the thumbnail URL to the full image URL by removing "/thumb/" and the size part | // Convert the thumbnail URL to the full image URL by removing "/thumb/" and the size part | ||
var fullImageUrl = thumbnailUrl.replace('/thumb', '').replace(/\/\d+px-.+$/, ''); | var fullImageUrl = thumbnailUrl.replace('/thumb', '').replace(/\/\d+px-.+$/, ''); | ||
// Update the link to point to the full image URL | // Update the link to point to the full image URL | ||
$link.attr('href', fullImageUrl); | $link.attr('href', fullImageUrl); | ||
// | // Enable Fancybox for this link | ||
$link.attr('data-fancybox', 'gallery'); | |||
}); | }); | ||
// | // Initialize Fancybox | ||
$('[data-fancybox="gallery"]').fancybox({ | $('[data-fancybox="gallery"]').fancybox({ | ||
buttons: [ | buttons: [ | ||
Line 58: | Line 48: | ||
transitionEffect: 'fade', | transitionEffect: 'fade', | ||
mobile: { | mobile: { | ||
clickSlide: 'close', | clickSlide: 'close', // Customize for mobile if needed | ||
clickOutside: 'close' | clickOutside: 'close' | ||
} | } | ||
}); | }); | ||
}); | }); |
Revision as of 18:35, 21 October 2024
/* 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 a').each(function() {
var $link = $(this);
var $image = $link.find('img'); // Find the image element inside the link
// Get the thumbnail URL
var thumbnailUrl = $image.attr('src');
// Convert the thumbnail URL to the full image URL by removing "/thumb/" and the size part
var fullImageUrl = thumbnailUrl.replace('/thumb', '').replace(/\/\d+px-.+$/, '');
// Update the link to point to the full image URL
$link.attr('href', fullImageUrl);
// Enable Fancybox for this link
$link.attr('data-fancybox', 'gallery');
});
// Initialize Fancybox
$('[data-fancybox="gallery"]').fancybox({
buttons: [
'zoom',
'slideShow',
'fullScreen',
'thumbs',
'close'
],
protect: true,
loop: true,
maxWidth: '90%',
maxHeight: '90%',
width: 'auto',
height: 'auto',
responsive: true,
transitionEffect: 'fade',
mobile: {
clickSlide: 'close', // Customize for mobile if needed
clickOutside: 'close'
}
});
});