MediaWiki:Common.js: Difference between revisions

From Mor Afgin Website
No edit summary
No edit summary
Line 15: Line 15:
     $('.fancybox-gallery a').each(function() {
     $('.fancybox-gallery a').each(function() {
         var $link = $(this);
         var $link = $(this);
         var filePageUrl = $link.attr('href');  // Get the link to the file description page
         var $image = $link.find('img');  // Find the image element inside the link


         // Extract the file name from the Wikimedia URL (e.g., File:Equinox1123.jpg)
         // Get the thumbnail URL (which contains the full image URL in its structure)
         var fileName = filePageUrl.match(/File:(.+)$/)[1];
         var thumbnailUrl = $image.attr('src');
        var fullImageUrl = $link.attr('href'); // Get the current href which Wikimedia may generate


         // Log the file name for debugging
         // Log both the thumbnail and full image URLs for debugging
         console.log('File Name:', fileName);
         console.log('Thumbnail URL:', thumbnailUrl);
        console.log('Full Image URL (from href):', fullImageUrl);


         // This is just a temporary assumption for constructing the correct path
         // Use the full image URL if available, otherwise try to extract from the thumbnail URL
        // You will need to find the hash structure of each file
         if (fullImageUrl) {
         // Let's assume first character is the main directory, second and third combined for subdir
            $link.attr('href', fullImageUrl);  // Use full image URL from href
        var hashFirstChar = '8';  // Replace with actual logic to get the first character of the hash
         } else {
         var hashSubDir = '8d';   // Replace with actual logic to get the second and third chars of the hash
            console.log('No full image URL available in href, using fallback.');
        }


         // Construct the correct full image URL
         // Open in a new tab for debugging
        var fullImageUrl = 'https://www.morafgin.com/images/' + hashFirstChar + '/' + hashSubDir + '/' + fileName;
         $link.attr('target', '_blank');  // Temporarily open in a new tab to check the URL
 
        // 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);
 
        // Disable Fancybox temporarily for debugging: open in a new tab to verify the URL
         $link.attr('target', '_blank');  // Open in a new tab


         // Later, re-enable Fancybox after verifying URLs are correct
         // Later, re-enable Fancybox after verifying URLs are correct

Revision as of 18:26, 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 (which contains the full image URL in its structure)
        var thumbnailUrl = $image.attr('src');
        var fullImageUrl = $link.attr('href'); // Get the current href which Wikimedia may generate

        // Log both the thumbnail and full image URLs for debugging
        console.log('Thumbnail URL:', thumbnailUrl);
        console.log('Full Image URL (from href):', fullImageUrl);

        // Use the full image URL if available, otherwise try to extract from the thumbnail URL
        if (fullImageUrl) {
            $link.attr('href', fullImageUrl);  // Use full image URL from href
        } else {
            console.log('No full image URL available in href, using fallback.');
        }

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

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

    // Re-enable this 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'
        }
    });
    */
});