MediaWiki:Common.js: Difference between revisions
imported>Dawning m open anchored collapsible |
imported>Dawning mNo edit summary |
||
| Line 85: | Line 85: | ||
var anchor = $(location.hash); | var anchor = $(location.hash); | ||
if (anchor.length) { | if (anchor.length) { | ||
anchor. | var collapsible = anchor.closest('.mw-collapsible'); | ||
if (collapsible.hasClass('mw-collapsed')) { | |||
// Simulate a click on its toggle | |||
$('.mw-customtoggle-' + collapsible.attr('id').replace('mw-customcollapsible-', '')).click(); | |||
} | |||
} | } | ||
} | } | ||
}); | }); | ||
Revision as of 16:05, 28 September 2025
/* Any JavaScript here will be loaded for all users on every page load. */
/* DRUID */
$(function () {
$(".druid-main-images-label").off("click");
$(".druid-main-images-label").click(function () {
var $parent = $(this).closest(".druid-container");
$parent.find(".druid-toggleable").removeClass("focused");
var i = $(this).attr("data-druid");
$parent.find(".druid-toggleable[data-druid=" + i + "]").addClass("focused");
});
$(".druid-collapsible").off("click");
$(".druid-collapsible").click(function () {
var kind = $(this).attr("data-druid-section");
$(this).toggleClass("druid-collapsible-collapsed");
$(this)
.closest(".druid-container")
.find("[data-druid-section-row=" + kind + "]")
.toggleClass("druid-collapsed");
});
});
/* End DRUID */
/* [[Template:Spoiler]] */
$(function () {
$('.spoiler-content')
.off('click') // in case this code is loaded twice
.on('click', function(e){
$(this).toggleClass('show');
}).find('a').on('click', function(e){
e.stopPropagation();
});
});
/* End Template:Spoiler */
/* Link to imported modules from Lua code */
$(function() {
var config = mw.config.get([
'wgCanonicalNamespace',
'wgFormattedNamespaces'
]);
if (config.wgCanonicalNamespace !== 'Module') {
return;
}
var localizedNamespace = config.wgFormattedNamespaces[828];
$('.s1, .s2, .s').each(function() {
var $this = $(this);
var html = $this.html();
var quote = html[0];
var isLongStringQuote = quote === '[';
var quoteRE = new RegExp('^\\' + quote + '|\\' + quote + '$', 'g');
if (isLongStringQuote) {
quoteRE = /^\[\[|\]\]$/g;
}
var name = html.replace(quoteRE, '');
var isEnglishPrefix = name.startsWith('Module:');
var isLocalizedPrefix = name.startsWith(localizedNamespace + ':');
var isDevPrefix = name.startsWith('Dev:');
if (isEnglishPrefix || isLocalizedPrefix || isDevPrefix) {
var attrs = {
href: mw.util.getUrl(name)
};
if (isDevPrefix) {
attrs.href = 'https://commons.wiki.gg/wiki/Module:' + mw.util.wikiUrlencode(name.replace('Dev:', ''));
attrs.target = '_blank';
attrs.rel = 'noopener';
}
var link = mw.html.element('a', attrs, name);
var str = quote + link + quote;
if (isLongStringQuote) {
str = '[[' + link + ']]';
}
$this.html(str);
}
});
});
/* Open anchored collapsibles */
$(function() {
if (location.hash) {
var anchor = $(location.hash);
if (anchor.length) {
var collapsible = anchor.closest('.mw-collapsible');
if (collapsible.hasClass('mw-collapsed')) {
// Simulate a click on its toggle
$('.mw-customtoggle-' + collapsible.attr('id').replace('mw-customcollapsible-', '')).click();
}
}
}
});