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

м Отмена версии 83111, сделанной Pok (обсуждение)
Метка: отмена
мНет описания правки
Строка 1275: Строка 1275:
// wiki import end
// wiki import end


;(function($, mw){
;(function($, mw) {
     const COOKIE = 'ss14_wikiTheme';
     const COOKIE = 'ss14_wikiTheme';


Строка 1311: Строка 1311:


         const $form = $('<form>');
         const $form = $('<form>');
         [
         const options = [
             { key: 'light',  label: 'Светлая (beta)' },
             { key: 'light',  label: 'Светлая (beta)' },
             { key: 'normal', label: 'Стандартная' },
             { key: 'normal', label: 'Стандартная' },
             { key: 'dark',  label: 'Тёмная' },
             { key: 'dark',  label: 'Тёмная' },
             { key: 'ss14',  label: 'Space Station 14' }
             { key: 'ss14',  label: 'Space Station 14' }
         ].forEach(opt => {
         ];
        options.forEach(opt => {
             const $wr = $('<div>', { class: 'theme-client-prefs-radio' });
             const $wr = $('<div>', { class: 'theme-client-prefs-radio' });
             const $inp = $('<input>', {
             const $inp = $('<input>', {
                 type:     'radio',
                 type: 'radio',
                 name:     'theme-selection',
                 name: 'theme-selection',
                 id:       `theme-value-${opt.key}`,
                 id: `theme-value-${opt.key}`,
                 value:   opt.key,
                 value: opt.key,
                 checked: opt.key === currentTheme
                 checked: opt.key === currentTheme
             });
             });
             const $lbl = $('<label>', {
             const $lbl = $('<label>', {
                 for:     `theme-value-${opt.key}`,
                 for: `theme-value-${opt.key}`,
                 text:     opt.label
                 text: opt.label
             });
             });
             $wr.append($inp, $lbl);
             $wr.append($inp, $lbl);
Строка 1349: Строка 1350:
     }
     }


     mw.themeUtils = { loadTheme, applyTheme, initThemeMenu };
     mw.themeUtils = { loadTheme, saveTheme, applyTheme, initThemeMenu };
}(jQuery, mediaWiki));


;(function($, mw) {
    $(function() {
    mw.loader.using('ext.gadget.theme').then(function() {
        const theme = loadTheme();
         const { loadTheme, initThemeMenu } = mw.themeUtils;
         applyTheme(theme);


         function createSettingsDropdown(currentTheme) {
         const $dropdown = $('<div>', { class: 'theme-dropdown' });
            const $dropdown = $('<div>', { class: 'theme-dropdown' });
        const $details = $('<details>', { id: 'theme-preferences-details', class: 'theme-dropdown-details' });
            const $details = $('<details>', { id: 'theme-preferences-details', class: 'theme-dropdown-details' });
        const $summary = $('<summary>', { class: 'theme-dropdown-summary', 'data-tooltip-initialized': 'true' })
            const $summary = $('<summary>', { class: 'theme-dropdown-summary', 'data-tooltip-initialized': 'true' })
            .append($('<span>', { class: 'theme-icon theme-icon-settings' }));
                .append($('<span>', { class: 'theme-icon theme-icon-settings' }));
        $details.append($summary);
            $details.append($summary);


            const $window = $('<div>', { id: 'theme-preferences', class: 'theme-window' }).hide();
        const $window = $('<div>', { id: 'theme-preferences', class: 'theme-window' }).hide();
            const $header = $('<div>', {
        const $header = $('<div>', { id: 'theme-preferences__header', class: 'theme-window__header', text: 'Параметры' });
                id: 'theme-preferences__header',
        const $content = $('<div>', { id: 'theme-preferences__content', class: 'theme-window__content' });
                class: 'theme-window__header',
        $window.append($header, $content);
                text: 'Параметры'
            });
            $window.append($header);


            const $content = $('<div>', {
        initThemeMenu($content, theme);
                id: 'theme-preferences__content',
                class: 'theme-window__content'
            });
            $window.append($content);


            initThemeMenu($content, currentTheme);
        $dropdown.append($details, $window);
 
        $('#user-tools').append($dropdown);
            $dropdown.append($details, $window);
            $('#user-tools').append($dropdown);
 
            const $cover = $('#menus-cover');
 
            $details.on('toggle', function() {
                const isOpen = $(this).prop('open');
                $window.toggle(isOpen);


        const $cover = $('#menus-cover');
        $details.on('toggle', function() {
            const isOpen = $(this).prop('open');
            $window.toggle(isOpen);
            if ($cover.length) {
                $cover.css('display', isOpen ? 'block' : 'none');
            }
        });
        $(document).on('click', function(e) {
            const isClickInside = $(e.target).closest('.theme-window, .theme-dropdown-summary').length > 0;
            if (!isClickInside && $details.prop('open')) {
                $details.removeAttr('open');
                 if ($cover.length) {
                 if ($cover.length) {
                     $cover.css('display', isOpen ? 'block' : 'none');
                     $cover.css('display', 'none');
                 }
                 }
             });
             }
        });
    });


            $(document).on('click', function(e) {
})(jQuery, mediaWiki);
                const isClickInside = $(e.target).closest('.theme-window, .theme-dropdown-summary').length > 0;
                if (!isClickInside && $details.prop('open')) {
                    $details.removeAttr('open');
                    if ($cover.length) {
                        $cover.css('display', 'none');
                    }
                }
            });
        }
 
        function init() {
            const theme = loadTheme();
            createSettingsDropdown(theme);
        }
 
        $(init);
    });
}(jQuery, mediaWiki));