MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Awsome2464 (talk | contribs) No edit summary |
Awsome2464 (talk | contribs) No edit summary Tag: Reverted |
||
| Line 2: | Line 2: | ||
/* Allows images within galleries to be spoiled if "spoiler:" is put at the start of its caption*/ | /* Allows images within galleries to be spoiled if "spoiler:" is put at the start of its caption*/ | ||
(function () { | |||
function markSpoilerBoxes($content) { | |||
$content.find('ul.gallery li.gallerybox').each(function () { | |||
var $box = $(this); | |||
var caption = $box.find('.gallerytext').text().trim().toLowerCase(); | |||
if (caption.startsWith('spoiler:')) { | |||
$box.addClass('spoiler-image'); | |||
$box.find('.gallerytext').html(function (_, html) { | |||
return html.replace('spoiler: ', ''); | |||
}); | |||
} | |||
}); | |||
} | |||
function handleSlideshowImage($gallery) { | |||
var $currentThumb = $gallery.find('.gallerybox.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 (!$imgContainer.length) { | |||
$imgContainer = $gallery.find('li').has('img').not('.gallerybox').first(); | |||
} | |||
if ($currentThumb.hasClass('spoiler-image') && !$currentThumb.hasClass('revealed')) { | |||
$imgContainer.addClass('spoiler-image'); | |||
} else { | |||
$imgContainer.addClass('spoiler-image.revealed'); | |||
} | |||
} | |||
$(document).on('click', '.mw-gallery-slideshow-img-container.spoiler-main, .mw-gallery-slideshow .spoiler-main', function (e) { | |||
if ($(e.target).closest('a, button, .oo-ui-buttonElement').length) { | |||
return; | |||
} | } | ||
$(this).addClass('revealed'); | |||
var $gallery = $(this).closest('ul.gallery'); | |||
$gallery.find('.gallerybox.slideshow-current').addClass('revealed'); | |||
}); | }); | ||
/* Toggles spoilered images between blurred and not blurred upon clicking */ | /* Toggles spoilered images between blurred and not blurred upon clicking */ | ||
Revision as of 11:17, 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*/
(function () {
function markSpoilerBoxes($content) {
$content.find('ul.gallery li.gallerybox').each(function () {
var $box = $(this);
var caption = $box.find('.gallerytext').text().trim().toLowerCase();
if (caption.startsWith('spoiler:')) {
$box.addClass('spoiler-image');
$box.find('.gallerytext').html(function (_, html) {
return html.replace('spoiler: ', '');
});
}
});
}
function handleSlideshowImage($gallery) {
var $currentThumb = $gallery.find('.gallerybox.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 (!$imgContainer.length) {
$imgContainer = $gallery.find('li').has('img').not('.gallerybox').first();
}
if ($currentThumb.hasClass('spoiler-image') && !$currentThumb.hasClass('revealed')) {
$imgContainer.addClass('spoiler-image');
} else {
$imgContainer.addClass('spoiler-image.revealed');
}
}
$(document).on('click', '.mw-gallery-slideshow-img-container.spoiler-main, .mw-gallery-slideshow .spoiler-main', function (e) {
if ($(e.target).closest('a, button, .oo-ui-buttonElement').length) {
return;
}
$(this).addClass('revealed');
var $gallery = $(this).closest('ul.gallery');
$gallery.find('.gallerybox.slideshow-current').addClass('revealed');
});
/* Toggles spoilered images between blurred and not blurred upon clicking */
$(function() {
$('.spoiler-image').on('click', function() {
$(this).toggleClass('revealed');
});
});