MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) м Отмена версии 82176, сделанной Pok (обсуждение) Метка: отмена |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 6: | Строка 6: | ||
THEME: 'theme' | THEME: 'theme' | ||
}, | }, | ||
$ | isDark = $.cookie(COOKIES.THEME) === 'dark' || | ||
currentMode; | ($.cookie(COOKIES.THEME) == null && $.cookie(COOKIES.DARK) === 'true'), | ||
currentMode = isDark ? 'dark' : 'light'; | |||
$.cookie(COOKIES.THEME, currentMode, { expires: 365, path: '/' }); | |||
$.cookie(COOKIES.DARK, isDark, { expires: 365, path: '/' }); | |||
function applyMode(mode) { | function applyMode(mode) { | ||
$('body') | if (mode === 'dark') { | ||
mw.loader.using(['wgl.theme.dark']).then(function() { | |||
. | $('body').addClass('wgl-theme-dark').removeClass('wgl-theme-light'); | ||
mw.hook('wgl.themeChanged').fire('dark'); | |||
}); | |||
} else { | |||
$('body').addClass('wgl-theme-light').removeClass('wgl-theme-dark'); | |||
mw.hook('wgl.themeChanged').fire('light'); | |||
} | |||
} | } | ||
applyMode(currentMode); | applyMode(currentMode); | ||
var $toggle = $( | $(function() { | ||
var $tools = $('#user-tools'), | |||
$toggle = $( | |||
'<div id="pt-dm-toggle">' + | |||
'<a href="#" title="Переключить тёмную тему"><span></span></a>' + | |||
'</div>' | |||
); | |||
$tools.prepend($toggle); | |||
$toggle.on('click', 'a', function(e) { | |||
e.preventDefault(); | |||
currentMode = currentMode === 'dark' ? 'light' : 'dark'; | |||
$.cookie(COOKIES.THEME, currentMode, { expires: 365, path: '/' }); | |||
$.cookie(COOKIES.DARK, currentMode === 'dark', { expires: 365, path: '/' }); | |||
applyMode(currentMode); | |||
}); | |||
}); | }); | ||
}(jQuery, mediaWiki)); | }(jQuery, mediaWiki)); | ||