MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Awsome2464 (talk | contribs) No edit summary |
Awsome2464 (talk | contribs) No edit summary |
||
| Line 13: | Line 13: | ||
} | } | ||
}); | }); | ||
}); | |||
$content.find('ul.mw-gallery-slideshow').each(function () { | |||
var $gallery = $(this); | |||
function updateImage() { | |||
var $current = $gallery.find('.gallerybox.slideshow-current'); | |||
if (!$current.length) { | |||
$current = $gallery.find.('.gallerybox').first(); | |||
} | |||
var $container = $gallery.find('.mw-gallery-slideshow-img-container'); | |||
if ($current.hasClass('spoiler-image') && !current.hasClass('revealed')) { | |||
$container.addClass('spoiler-image'); | |||
} else { | |||
$container.removeClass('spoiler-image revealed'); | |||
} | |||
} | |||
updateImage(); | |||
var observer = new MutationObserver(function () { | |||
updateImage(); | |||
}); | |||
observer.observe($gallery[0], { | |||
attributes: true, | |||
attributeFilter: ['class'], | |||
subtree: true, | |||
childList: true | |||
}); | |||
}); | |||
$content.on('click', '.mw-gallery-slideshow-img-container.spoiler-image', function (x) { | |||
if ($(x.target).closest('.oo-ui-buttonElement, button, a.oo-ui-buttonElement-button').length) { | |||
return; | |||
} | |||
var $container = $(this); | |||
$container.addClass('revealed'); | |||
$ | |||
$container.closest('ul.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 13:31, 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: ', ''));
}
});
$content.find('ul.mw-gallery-slideshow').each(function () {
var $gallery = $(this);
function updateImage() {
var $current = $gallery.find('.gallerybox.slideshow-current');
if (!$current.length) {
$current = $gallery.find.('.gallerybox').first();
}
var $container = $gallery.find('.mw-gallery-slideshow-img-container');
if ($current.hasClass('spoiler-image') && !current.hasClass('revealed')) {
$container.addClass('spoiler-image');
} else {
$container.removeClass('spoiler-image revealed');
}
}
updateImage();
var observer = new MutationObserver(function () {
updateImage();
});
observer.observe($gallery[0], {
attributes: true,
attributeFilter: ['class'],
subtree: true,
childList: true
});
});
$content.on('click', '.mw-gallery-slideshow-img-container.spoiler-image', function (x) {
if ($(x.target).closest('.oo-ui-buttonElement, button, a.oo-ui-buttonElement-button').length) {
return;
}
var $container = $(this);
$container.addClass('revealed');
$container.closest('ul.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');
});
});