12,787
edits
No edit summary |
(Amend dark mode code) |
||
(17 intermediate revisions by 2 users not shown) | |||
Line 544: | Line 544: | ||
} | } | ||
} | } | ||
function toggleDarkMode() { | |||
document.body.classList.toggle('darkMode'); | |||
localStorage.setItem('darkMode', localStorage.getItem('darkMode') !== 'true'); | |||
} | |||
$(document).ready(function () { | $(document).ready(function () { | ||
if (document.getElementsByClassName('stickyHeader').length > 0) { | |||
setStickyHeaderTop(); | |||
$(window).resize(setStickyHeaderTop); | |||
} | |||
const darkMode = localStorage.getItem('darkMode'); | |||
if (darkMode === 'true') { | |||
document.body.classList.add('darkMode'); | |||
} else { | |||
document.body.classList.remove('darkMode'); | |||
} | |||
}); | |||
function | // Add dark mode links to "Wiki tools" and personal tools menus | ||
$.when(mw.loader.using(['mediawiki.util']), $.ready).then( function() { | |||
var dmLinkTools = mw.util.addPortletLink('p-tb', '#', 'Dark mode', 't-darkmode', 'Toggle between a dark and light theme', null, '#t-specialpages'); | |||
var dmLinkPersonal = mw.util.addPortletLink('p-personal', '#', 'Dark mode', 'pt-darkmode', 'Toggle between a dark and light theme', null, null); | |||
dmLinkPersonal.style.marginTop = '0.5rem'; | |||
function | $(dmLinkTools).on('click', function(e) { | ||
e.preventDefault(); | |||
toggleDarkMode(); | |||
}); | |||
$(dmLinkPersonal).on('click', function(e) { | |||
e.preventDefault(); | |||
toggleDarkMode(); | |||
}); | |||
} ); | |||
} |