MediaWiki:Gadget-skinTogglesMobile.js: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(Created page with "→* * Toggles for skin cookies on mobile * * @author JaydenKieran *: const DARK_COOKIE = 'darkmode'; var currentDark = $.cookie('theme') === 'dark' || ($.cookie('theme') == null && $.cookie(DARK_COOKIE) === 'true'), darkPortletLink; var self = { init: function () { darkPortletLink = mw.util.addPortletLink( 'p-personal', '#', (currentDark ? 'Light' : 'Dark') + ' mode', 'wgl-darkmode-toggle', 'Toggle ' + (currentDark ? 'light' : 'dark') + ' mo...") |
No edit summary Tag: Reverted |
||
Line 12: | Line 12: | ||
var self = { |
var self = { |
||
init: function () { |
init: function () { |
||
darkPortletLink = mw.util.addPortletLink( |
darkPortletLink = mw.mw.util.addPortletLink( |
||
'p-personal', |
'p-personal', |
||
'#', |
'#', |
Revision as of 00:10, 17 October 2024
/**
* Toggles for skin cookies on mobile
*
* @author JaydenKieran
*
*/
const DARK_COOKIE = 'darkmode';
var currentDark = $.cookie('theme') === 'dark' || ($.cookie('theme') == null && $.cookie(DARK_COOKIE) === 'true'),
darkPortletLink;
var self = {
init: function () {
darkPortletLink = mw.mw.util.addPortletLink(
'p-personal',
'#',
(currentDark ? 'Light' : 'Dark') + ' mode',
'wgl-darkmode-toggle',
'Toggle ' + (currentDark ? 'light' : 'dark') + ' mode',
null,
$('a.menu__item--logout').closest('li')
);
$('meta[name="theme-color"]').attr('content', currentDark ? '#071022' : '#c0a886');
$.cookie('theme', currentDark ? 'dark' : 'light', {expires: 365, path: '/'});
$(darkPortletLink).click(function (e) {
e.preventDefault();
currentDark = !currentDark;
$('#wgl-darkmode-toggle .toggle-list-item__label').text((currentDark ? 'Light' : 'Dark') + ' mode');
$.cookie('theme', currentDark ? 'dark' : 'light', {expires: 365, path: '/'});
$.cookie(DARK_COOKIE, currentDark, {expires: 365, path: '/'});
$('meta[name="theme-color"]').attr('content', currentDark ? '#071022' : '#c0a886');
if (currentDark) {
mw.loader.using(['wgl.theme.dark']).then(function() {
$('body').addClass('wgl-theme-dark').removeClass('wgl-theme-light')
});
} else {
$('body').addClass('wgl-theme-light').removeClass('wgl-theme-dark')
}
mw.notify( 'Switched to ' + (currentDark ? 'dark' : 'light') + ' mode!', { tag: 'wg-darkmode-notification' } );
});
},
}
$(self.init);