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

мНет описания правки
мНет описания правки
Строка 5: Строка 5:


     var STORAGE_KEY = 'wiki-theme',
     var STORAGE_KEY = 'wiki-theme',
        $tools = $('#user-tools'),
         theme = null,
         theme = null,
         $btn;
         portletLink;


     function applyTheme(name) {
     function applyTheme(name) {
Строка 18: Строка 17:
             console.warn('Не удалось сохранить тему в localStorage:', e);
             console.warn('Не удалось сохранить тему в localStorage:', e);
         }
         }
        updateButton(name);
    }
    function updateButton(current) {
        var label = current === 'dark'
            ? '☀️ Перейти на светлую'
            : '🌙 Перейти на тёмную';
        $btn.text(label);
     }
     }


Строка 39: Строка 30:
         applyTheme(theme);
         applyTheme(theme);


         if ($tools.length) {
         portletLink = mw.util.addPortletLink(
             $btn = $('<button>', {
             mw.config.get('wgMFMode') !== null ? 'p-navigation' : 'p-personal',
                id: 'theme-toggle-btn',
            '#',
                css: {
            'Переключить тему',
                    marginLeft: '0.5em',
            'pt-theme-toggle',
                    padding: '0.2em 0.6em',
            'Переключить светлую/тёмную тему'
                    cursor: 'pointer',
        );
                    'background-color': 'transparent',
 
                    border: '1px solid #888',
        $(portletLink).find('a').on('click', function (e) {
                    'border-radius': '0.2em',
            e.preventDefault();
                    'font-size': '0.9em'
            theme = (theme === 'dark') ? 'light' : 'dark';
                }
            applyTheme(theme);
            }).on('click', function (e) {
        });
                e.preventDefault();
                var next = (theme === 'dark') ? 'light' : 'dark';
                theme = next;
                applyTheme(next);
            });
            $tools.append($btn);
        }
     }
     }