MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
;(function($, mw){ | ;(function($, mw){ | ||
var DARK_COOKIE = 'darkmode', | |||
THEME_COOKIE = 'theme', | |||
isUsingDarkmode = $.cookie(THEME_COOKIE) === 'dark' || ($.cookie(THEME_COOKIE) == null && $.cookie(DARK_COOKIE) === 'true'), | |||
isMobile = mw.config.get('wgMFMode') !== null, | |||
portletLink; | |||
var self = { | |||
init: function () { | |||
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'}); | |||
portletLink = mw.util.addPortletLink( | |||
( isMobile ? 'p-navigation' : 'p-personal' ), | |||
'', | |||
( isMobile ? 'Переключить тёмную тему' : '' ), | |||
'pt-dm-toggle', | |||
'Переключить тёмную тему', | |||
null, | |||
$('#pt-userpage, #pt-anonuserpage, #pt-createaccount')[0] | |||
); | |||
$(portletLink).find('a').click(function(e) { | |||
e.preventDefault(); | |||
isUsingDarkmode = !isUsingDarkmode; | |||
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'}); | |||
$.cookie(DARK_COOKIE, isUsingDarkmode, {expires: 365, path: '/'}); | |||
if (isUsingDarkmode === true) { | |||
mw.loader.using(['wgl.theme.dark']).then(function() { | |||
$('body').addClass('wgl-theme-dark') | |||
$('body').removeClass('wgl-theme-light') | |||
mw.hook('wgl.themeChanged').fire('dark') | |||
}); | |||
} else { | |||
$('body').addClass('wgl-theme-light') | |||
$('body').removeClass('wgl-theme-dark') | |||
mw.hook('wgl.themeChanged').fire('light') | |||
} | |||
}); | |||
} | |||
} | |||
$(self.init); | |||
}(jQuery, mediaWiki)); | }(jQuery, mediaWiki)); | ||