MediaWiki:Common.js: Difference between revisions

From Mor Afgin Website
No edit summary
No edit summary
Line 17: Line 17:
         var $image = $link.find('img');  // Find the image element inside the link
         var $image = $link.find('img');  // Find the image element inside the link


         // Get the thumbnail URL (which contains the full image URL in its structure)
         // Get the thumbnail URL
         var thumbnailUrl = $image.attr('src');
         var thumbnailUrl = $image.attr('src');
        var fileDescriptionUrl = $link.attr('href'); // Get the current href which is leading to the file description page


         // Log both the thumbnail and full image URLs for debugging
         // Log the thumbnail URL for debugging
         console.log('Thumbnail URL:', thumbnailUrl);
         console.log('Thumbnail URL:', thumbnailUrl);
        console.log('File Description URL:', fileDescriptionUrl);


         // Replace the /index.php/File: part with /images/ to construct the direct image URL
         // Convert the thumbnail URL to the full image URL by removing "/thumb/" and the size part
        var fileName = fileDescriptionUrl.match(/File:(.+)$/)[1];  // Extract the file name
         var fullImageUrl = thumbnailUrl.replace('/thumb', '').replace(/\/\d+px-.+$/, '');
         var fullImageUrl = 'https://www.morafgin.com/images/' + fileName.charAt(0) + '/' + fileName.charAt(1) + '/' + fileName;


         // Log the constructed full image URL for debugging
         // Log the constructed full image URL for debugging
Line 35: Line 32:
         $link.attr('href', fullImageUrl);
         $link.attr('href', fullImageUrl);


         // Open in a new tab for debugging
         // Temporarily open in a new tab for debugging
         $link.attr('target', '_blank');  // Temporarily open in a new tab to check the URL
         $link.attr('target', '_blank');  // Open in a new tab


         // Later, re-enable Fancybox after verifying URLs are correct
         // Re-enable Fancybox later:
         // $link.attr('data-fancybox', 'gallery');  // Enable Fancybox for this link
         // $link.attr('data-fancybox', 'gallery');  // Enable Fancybox for this link
     });
     });


     // Re-enable this after URL verification
     // Re-enable Fancybox after URL verification
     /*
     /*
     $('[data-fancybox="gallery"]').fancybox({
     $('[data-fancybox="gallery"]').fancybox({

Revision as of 18:31, 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');

        // Log the thumbnail URL for debugging
        console.log('Thumbnail URL:', thumbnailUrl);

        // Convert the thumbnail URL to the full image URL by removing "/thumb/" and the size part
        var fullImageUrl = thumbnailUrl.replace('/thumb', '').replace(/\/\d+px-.+$/, '');

        // Log the constructed full image URL for debugging
        console.log('Constructed Full Image URL:', fullImageUrl);

        // Update the link to point to the full image URL
        $link.attr('href', fullImageUrl);

        // Temporarily open in a new tab for debugging
        $link.attr('target', '_blank');  // Open in a new tab

        // Re-enable Fancybox later:
        // $link.attr('data-fancybox', 'gallery');  // Enable Fancybox for this link
    });

    // Re-enable Fancybox after URL verification
    /*
    $('[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'
        }
    });
    */
});