MediaWiki:Common.js: Difference between revisions

From Another Chance Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 22: Line 22:


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

Revision as of 12:01, 20 August 2026

/* 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('.slideshow-current');
    if (!$currentThumb.length) {
        $currentThumb = $gallery.find('.gallerybox').first();
    }

    var $imgContainer = $gallery.find('.mw-gallery-slideshow-img-container');
    if ($currentThumb.classList.contains('spoiler-image') && !$currentThumb.classList.contains('revealed')) {
        $imgContainer.classList.add('spoiler-image');
    } else {
        $imgContainer.classList.remove('spoiler-image.revealed');
    }
});

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