MediaWiki:Gadget-skinTogglesMobile.js: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
No edit summary Tag: Manual revert |
No edit summary |
||
Line 1: | Line 1: | ||
"use strict"; |
|||
/** |
/** |
||
* Toggles for skin cookies on mobile |
* Toggles for skin cookies on mobile |
||
Line 6: | Line 8: | ||
*/ |
*/ |
||
var DARK_COOKIE = 'darkmode'; |
|||
var currentDark = $.cookie('theme') === 'dark' || |
var currentDark = $.cookie('theme') === 'dark' || $.cookie('theme') == null && $.cookie(DARK_COOKIE) === 'true', |
||
darkPortletLink; |
|||
var self = { |
var self = { |
||
init: function init() { |
|||
darkPortletLink = mw.util.addPortletLink('p-personal', '#', (currentDark ? 'Light' : 'Dark') + ' mode', 'wgl-darkmode-toggle', 'Toggle ' + (currentDark ? 'light' : 'dark') + ' mode', null, $('a.menu__item--logout').closest('li')); |
|||
darkPortletLink = mw.util.addPortletLink( |
|||
⚫ | |||
'p-personal', |
|||
⚫ | |||
'#', |
|||
expires: 365, |
|||
⚫ | |||
path: '/' |
|||
'wgl-darkmode-toggle', |
|||
⚫ | |||
'Toggle ' + (currentDark ? 'light' : 'dark') + ' mode', |
|||
⚫ | |||
null, |
|||
⚫ | |||
$('a.menu__item--logout').closest('li') |
|||
⚫ | |||
); |
|||
⚫ | |||
$.cookie('theme', currentDark ? 'dark' : 'light', { |
|||
expires: 365, |
|||
path: '/' |
|||
}); |
|||
$.cookie(DARK_COOKIE, currentDark, { |
|||
⚫ | |||
expires: 365, |
|||
⚫ | |||
path: '/' |
|||
⚫ | |||
}); |
|||
⚫ | |||
$('meta[name="theme-color"]').attr('content', currentDark ? '#071022' : '#c0a886'); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
}); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
$('body').addClass('wgl-theme-light').removeClass('wgl-theme-dark'); |
|||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
tag: 'wg-darkmode-notification' |
|||
⚫ | |||
}); |
|||
} |
|||
⚫ | |||
mw.notify( 'Switched to ' + (currentDark ? 'dark' : 'light') + ' mode!', { tag: 'wg-darkmode-notification' } ); |
|||
} |
|||
⚫ | |||
}; |
|||
} |
|||
$(self.init); |
$(self.init); |
Latest revision as of 12:06, 20 October 2024
"use strict";
/**
* Toggles for skin cookies on mobile
*
* @author JaydenKieran
*
*/
var DARK_COOKIE = 'darkmode';
var currentDark = $.cookie('theme') === 'dark' || $.cookie('theme') == null && $.cookie(DARK_COOKIE) === 'true',
darkPortletLink;
var self = {
init: function init() {
darkPortletLink = 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);