MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
Line 23: | Line 23: | ||
var fullImageUrl = thumbnailUrl.replace('/thumb', '').replace(/\/\d+px-.+$/, ''); | var fullImageUrl = thumbnailUrl.replace('/thumb', '').replace(/\/\d+px-.+$/, ''); | ||
// | // Ensure the href is set to the full image URL | ||
$link.attr('href', fullImageUrl); | $link.attr('href', fullImageUrl); | ||
// Double-check the final href on the link for debugging | |||
console.log('Final href set on link:', $link.attr('href')); | |||
// Enable Fancybox for this link | // Enable Fancybox for this link | ||
$link.attr('data-fancybox', 'gallery'); | $link.attr('data-fancybox', 'gallery'); | ||
}); | }); | ||
// Initialize Fancybox with explicit dimensions and | // Initialize Fancybox with explicit dimensions and logging | ||
$('[data-fancybox="gallery"]').fancybox({ | $('[data-fancybox="gallery"]').fancybox({ | ||
buttons: [ | buttons: [ | ||
Line 55: | Line 54: | ||
clickOutside: 'close' | clickOutside: 'close' | ||
}, | }, | ||
afterLoad: function(instance, current) { | afterLoad: function(instance, current) { | ||
console.log('Fancybox loaded with URL:', current.src); | console.log('Fancybox loaded with URL:', current.src); | ||
}, | }, | ||
afterShow: function(instance, current) { | afterShow: function(instance, current) { | ||
console.log('Fancybox showing image:', current.src); | console.log('Fancybox showing image:', current.src); | ||
}, | }, | ||
onInit: function(instance) { | onInit: function(instance) { | ||
Line 70: | Line 66: | ||
}); | }); | ||
// | // Custom CSS to enforce Fancybox scaling to 90% | ||
$('<style>') | $('<style>') | ||
.prop('type', 'text/css') | .prop('type', 'text/css') |
Revision as of 13:22, 28 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-.+$/, '');
// Ensure the href is set to the full image URL
$link.attr('href', fullImageUrl);
// Double-check the final href on the link for debugging
console.log('Final href set on link:', $link.attr('href'));
// Enable Fancybox for this link
$link.attr('data-fancybox', 'gallery');
});
// Initialize Fancybox with explicit dimensions and logging
$('[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',
clickOutside: 'close'
},
afterLoad: function(instance, current) {
console.log('Fancybox loaded with URL:', current.src);
},
afterShow: function(instance, current) {
console.log('Fancybox showing image:', current.src);
},
onInit: function(instance) {
console.log('Fancybox initialized');
}
});
});
// Custom CSS to enforce Fancybox scaling to 90%
$('<style>')
.prop('type', 'text/css')
.html(`
.fancybox-content {
max-width: 90vw !important;
max-height: 90vh !important;
}
.fancybox-image {
width: 100% !important;
height: auto !important;
}
`)
.appendTo('head');