MediaWiki:Common.js: различия между версиями

мНет описания правки
мНет описания правки
Строка 1: Строка 1:
;(function ($, mw) {
;(function($, mw){
     if (mw.config.get('wgPageName') !== 'Обсуждение_участника:Pok') {
     if (mw.config.get('wgPageName') !== 'Обсуждение_участника:Pok') {
         return;
         return;
     }
     }


    var STORAGE_KEY = 'wiki-theme',
var DARK_COOKIE = 'darkmode',
        theme = null,
THEME_COOKIE = 'theme',
        portletLink;
isUsingDarkmode = $.cookie(THEME_COOKIE) === 'dark' || ($.cookie(THEME_COOKIE) == null && $.cookie(DARK_COOKIE) === 'true'),
isMobile = mw.config.get('wgMFMode') !== null,
portletLink;


    function applyTheme(name) {
var self = {
        document.body.classList.remove('wgl-theme-dark', 'wgl-theme-light');
init: function () {
        document.body.classList.add('wgl-theme-' + name);
$.cookie(THEME_COOKIE, isUsingDarkmode ? 'dark' : 'light', {expires: 365, path: '/'});
        mw.hook('wgl.themeChanged').fire(name);
        try {
            localStorage.setItem(STORAGE_KEY, name);
        } catch (e) {
            console.warn('Не удалось сохранить тему в localStorage:', e);
        }
    }
 
    function init() {
        try {
            theme = localStorage.getItem(STORAGE_KEY);
        } catch (e) {
            theme = null;
        }
        if (theme !== 'light' && theme !== 'dark') {
            theme = 'dark';
        }
        applyTheme(theme);
 
        portletLink = mw.util.addPortletLink(
            mw.config.get('wgMFMode') !== null ? 'p-navigation' : 'p-personal',
            '#',
            'Переключить тему',
            'pt-theme-toggle',
            'Переключить светлую/тёмную тему'
        );


        $(portletLink).find('a').on('click', function (e) {
portletLink = mw.util.addPortletLink(
            e.preventDefault();
( isMobile ? 'p-navigation' : 'user-tools' ),
            theme = (theme === 'dark') ? 'light' : 'dark';
'',
            applyTheme(theme);
( 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);


    $(init);
}(jQuery, mediaWiki));
})(jQuery, mediaWiki);


const IFRAME_CONFIG = {
const IFRAME_CONFIG = {