User:MetalManeMc/vector.js: Difference between revisions
Jump to navigation
Jump to search
MetalManeMc (talk | contribs) No edit summary |
MetalManeMc (talk | contribs) No edit summary |
||
Line 7: | Line 7: | ||
*/ | */ | ||
;(function($, mw){ | ;(function($, mw){ | ||
var | var LIGHT_COOKIE = 'lightmode', | ||
THEME_COOKIE = 'theme', | THEME_COOKIE = 'theme', | ||
isUsingLightmode = $.cookie(THEME_COOKIE) === 'light' || ($.cookie(THEME_COOKIE) == null && $.cookie(LIGHT_COOKIE) === 'true'), | |||
portletLink; | portletLink; | ||
var self = { | var self = { | ||
init: function () { | init: function () { | ||
$.cookie(THEME_COOKIE, | $.cookie(THEME_COOKIE, isUsingLightmode ? 'light' : 'dark', {expires: 365, path: '/'}); | ||
portletLink = mw.util.addPortletLink( | portletLink = mw.util.addPortletLink( | ||
Line 21: | Line 21: | ||
'', | '', | ||
'pt-dm-toggle', | 'pt-dm-toggle', | ||
'Toggle | 'Toggle light mode', | ||
null, | null, | ||
$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0] | $('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0] | ||
Line 29: | Line 29: | ||
e.preventDefault(); | e.preventDefault(); | ||
isUsingLightmode = !isUsingLightmode; | |||
$.cookie(THEME_COOKIE, | $.cookie(THEME_COOKIE, isUsingLightmode ? 'dark' : 'light', {expires: 365, path: '/'}); | ||
$.cookie(DARK_COOKIE, | $.cookie(DARK_COOKIE, isUsingLightmode, {expires: 365, path: '/'}); | ||
if ( | if (isUsingLightmode === true) { | ||
mw.loader.using(['theme- | mw.loader.using(['theme-light']).then(function() { | ||
$('body').addClass('theme-light') | |||
$('body').removeClass('theme-dark-grey') | |||
}); | }); | ||
} else { | } else { | ||
$('body').addClass('theme- | $('body').addClass('theme-dark-grey') | ||
$('body').removeClass('theme- | $('body').removeClass('theme-light') | ||
} | } | ||
}); | }); |
Revision as of 23:13, 18 December 2023
/**
* Toggle for dark mode testing
*
* @author [[User:Jayden]] for https://minecraft.wiki
* @author [[User:MetalManeMc]] for adaptation on Baldur's Gate 3 Wiki
* @see Based on https://runescape.wiki/w/MediaWiki:Gadget-skinTogglesNew.js
*/
;(function($, mw){
var LIGHT_COOKIE = 'lightmode',
THEME_COOKIE = 'theme',
isUsingLightmode = $.cookie(THEME_COOKIE) === 'light' || ($.cookie(THEME_COOKIE) == null && $.cookie(LIGHT_COOKIE) === 'true'),
portletLink;
var self = {
init: function () {
$.cookie(THEME_COOKIE, isUsingLightmode ? 'light' : 'dark', {expires: 365, path: '/'});
portletLink = mw.util.addPortletLink(
'p-personal',
'',
'',
'pt-dm-toggle',
'Toggle light mode',
null,
$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0]
);
$(portletLink).find('a').click(function(e) {
e.preventDefault();
isUsingLightmode = !isUsingLightmode;
$.cookie(THEME_COOKIE, isUsingLightmode ? 'dark' : 'light', {expires: 365, path: '/'});
$.cookie(DARK_COOKIE, isUsingLightmode, {expires: 365, path: '/'});
if (isUsingLightmode === true) {
mw.loader.using(['theme-light']).then(function() {
$('body').addClass('theme-light')
$('body').removeClass('theme-dark-grey')
});
} else {
$('body').addClass('theme-dark-grey')
$('body').removeClass('theme-light')
}
});
}
}
$(self.init);
}(jQuery, mediaWiki));