12,787
edits
No edit summary |
(Amend dark mode code) |
||
(One intermediate revision by the same user 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( | if (document.getElementsByClassName('stickyHeader').length > 0) { | ||
setStickyHeaderTop(); | setStickyHeaderTop(); | ||
$(window).resize(setStickyHeaderTop); | $(window).resize(setStickyHeaderTop); | ||
} | } | ||
const darkMode = localStorage.getItem( | const darkMode = localStorage.getItem('darkMode'); | ||
if (darkMode === | if (darkMode === 'true') { | ||
document.body.classList.add( | document.body.classList.add('darkMode'); | ||
} else { | } else { | ||
document.body.classList.remove( | document.body.classList.remove('darkMode'); | ||
} | } | ||
}); | }); | ||
// Add dark mode links to "Wiki tools" and personal tools menus | |||
function | $.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'; | |||
$(dmLinkTools).on('click', function(e) { | |||
} | e.preventDefault(); | ||
toggleDarkMode(); | |||
}); | |||
} | $(dmLinkPersonal).on('click', function(e) { | ||
} | e.preventDefault(); | ||
toggleDarkMode(); | |||
}); | |||
} ); |