MediaWiki:Common.js

From Another Chance Wiki
Revision as of 11:53, 20 August 2026 by Awsome2464 (talk | contribs)
Jump to navigation Jump to search

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. */

/* Allows images within galleries to be spoiled if "spoiler:" is put at the start of its caption*/
mw.hook('wikipage.content').add(function ($content) {
    $content.find('ul.gallery li.gallerybox').each(function () {
        var $box = $(this);
        var $caption = $box.find('.gallerytext');
        var captionText = $caption.text().trim().toLowerCase();

        if (captionText.startsWith('spoiler:')) {
            $box.addClass('spoiler-image');
            $caption.html($caption.html().replace('spoiler: ', ''));
        }
    });
});

mw.hook('wikipage.content').add(function ($gallery) {
    var $currentThumb = $gallery.find('.gallerybox.slideshow-current' || 'gallerybox.spoiler-image.slideshow-current');
    if (!$currentThumb.length) {
        $currentThumb = $gallery.find('.gallerybox').first();
    }

    var $imgContainer = $gallery.find('.mw-gallery-slideshow-img-container, .mw-gallery-slideshow, .carousel, .mw-gallery-slideshow-img');
    if ($currentThumb.hasClass('spoiler-image') && !$currentThumb.hasClass('revealed')) {
        $imgContainer.addClass('spoiler-image');
    } else {
        $imgContainer.removeClass('spoiler-image.revealed');
    }
});

/* Toggles spoilered images between blurred and not blurred upon clicking */
$(function() {
    $('.spoiler-image').on('click', function() {
        $(this).toggleClass('revealed');
    });
});