MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
(screw the JS, I'll do it manually through CSS) |
mNo edit summary |
||
(19 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
/* Check for cookie and apply darkmode if exists */ | |||
$(function (){ | |||
var darkmode = /\bdarkmode=1\b/.test(document.cookie); | |||
if (!darkmode) { | |||
document.documentElement.classList.remove('client-darkmode') | |||
} else { | |||
document.documentElement.classList.add('client-darkmode') | |||
}; | |||
}); | |||
;(function () { | |||
$('#pt-darkmode a').on('click', function (e) { | |||
e.preventDefault() | |||
var darkmode = /\bdarkmode=1\b/.test(document.cookie); | |||
if (darkmode) { | |||
document.cookie = 'darkmode=; Path=/; Max-Age=0;' | |||
} else { | |||
document.cookie = 'darkmode=1; Path=/;' | |||
} | |||
}) | |||
})(); | |||
/* Implements section-collapse and stop-section-collapse */ | /* Implements section-collapse and stop-section-collapse */ | ||
Line 26: | Line 49: | ||
t.classList.toggle('collapsed-icon'); | t.classList.toggle('collapsed-icon'); | ||
} | } | ||
Revision as of 21:38, 3 April 2024
/* Any JavaScript here will be loaded for all users on every page load. */ /* Check for cookie and apply darkmode if exists */ $(function (){ var darkmode = /\bdarkmode=1\b/.test(document.cookie); if (!darkmode) { document.documentElement.classList.remove('client-darkmode') } else { document.documentElement.classList.add('client-darkmode') }; }); ;(function () { $('#pt-darkmode a').on('click', function (e) { e.preventDefault() var darkmode = /\bdarkmode=1\b/.test(document.cookie); if (darkmode) { document.cookie = 'darkmode=; Path=/; Max-Age=0;' } else { document.cookie = 'darkmode=1; Path=/;' } }) })(); /* Implements section-collapse and stop-section-collapse */ var collapsing = document.querySelectorAll(".section-collapse"); if (collapsing.length>0) { for (var i = 0; i < collapsing.length ; i++) { collapsing.item(i).addEventListener('click',collapseHandler,false); if (collapsing.item(i).classList.contains("collapsed")) collapseHandlerThis(collapsing.item(i)); } } function collapseHandler() { collapseHandlerThis(this); } function collapseHandlerThis(t) { var c = t.parentNode.parentNode.nextSibling; while (c) { if (c.classList) { if (c.classList.contains("section-collapse") || c.classList.contains("stop-section-collapse")) break; c.classList.toggle('section-collapsed'); } c = c.nextSibling; } t.classList.toggle('collapsed-icon'); }