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

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


    function initThemeMenu($container) {
function initThemeMenu($container, currentTheme) {
        const currentTheme = loadTheme();
    currentTheme = currentTheme || loadTheme();
 
        const $portlet = $('<div>', {
    const $portlet = $('<div>', {
            class: 'mw-portlet mw-portlet-skin-client-prefs-skin-theme mw-portlet-js theme-menu',
        class: 'mw-portlet mw-portlet-skin-client-prefs-skin-theme mw-portlet-js theme-menu',
            id: 'skin-client-prefs-skin-theme'
        id: 'skin-client-prefs-skin-theme'
        });
    });
        $portlet.append(
    $portlet.append(
            $('<div>', { class: 'theme-menu__heading', text: 'Тема' }),
        $('<div>', { class: 'theme-menu__heading', text: 'Тема' }),
            $('<div>', { class: 'theme-menu__content' })
        $('<div>', { class: 'theme-menu__content' })
        );
    );
 
        const $form = $('<form>');
    const $form = $('<form>');
        [
    [
            { key: 'light',  label: 'Светлая (beta)' },
        { key: 'light',  label: 'Светлая (beta)' },
            { key: 'normal', label: 'Стандартная' },
        { key: 'normal', label: 'Стандартная' },
            { key: 'dark',  label: 'Тёмная' }
        { key: 'dark',  label: 'Тёмная' }
        ].forEach(opt => {
    ].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);
            $form.append($wr);
        $form.append($wr);
        });
    });
 
        $portlet.find('.theme-menu__content').append(
    $portlet.find('.theme-menu__content').append(
            $('<ul>', { class: 'theme-menu__content-list' })
        $('<ul>', { class: 'theme-menu__content-list' })
                .append( $('<li>', { class: 'mw-list-item mw-list-item-js' }).append($form) )
            .append( $('<li>', { class: 'mw-list-item mw-list-item-js' }).append($form) )
        );
    );
        $container.append($portlet);
    $container.append($portlet);
 
        $form.on('change', 'input[name="theme-selection"]', function() {
    $form.on('change', 'input[name="theme-selection"]', function() {
            const newTheme = $(this).val();
        const newTheme = $(this).val();
            saveTheme(newTheme);
        saveTheme(newTheme);
            applyTheme(newTheme);
        applyTheme(newTheme);
        });
    });
    }
}


     $(function() {
     $(function() {