MediaWiki:Common.js

From Mor Afgin Website
Revision as of 16:49, 21 October 2024 by Mor Afgin (talk | contribs)

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
        $image.wrap('<a data-fancybox="gallery" href="' + src + '"></a>'); // Wrap each image in a Fancybox-enabled link
    });
});

// Disable MediaViewer for all users
mw.config.set('wgMediaViewerEnabled', false);

// Prevent MediaViewer from handling click events on images
$(function() {
    mw.hook('wikipage.content').add(function() {
        $('.image').off('click');
    });
});