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

м Отмена версии 82389, сделанной Pok (обсуждение)
Метка: отмена
мНет описания правки
Строка 1: Строка 1:
;(function($, mw, rs){
;(function($, mw){
if (mw.config.get('wgPageName') !== 'Обсуждение_участника:Pok') return;
    // Only run on specific page
    if (mw.config.get('wgPageName') !== 'Обсуждение_участника:Pok') return;
var DARK_COOKIE = 'darkmode',
STICKY_HEADER_COOKIE = 'stickyheader',
THEME_COOKIE = 'theme',
fixedWidthEnabled = $.cookie('readermode') === 'true',
theme = $.cookie(THEME_COOKIE) || ($.cookie(DARK_COOKIE) === 'true' ? 'dark' : 'light'),
stickySwitch,
closeButton,
settingsPortletLink,
themePopup;


var self = {
    var COOKIE_THEME = 'theme',
init: function () {
        COOKIE_DARK = 'darkmode',
self.createThemeButton();
        COOKIE_STICKY = 'stickyheader',
self.createSettingsButton();
        COOKIE_FIXED = 'readermode',
self.createFixedWidthToggle();
        theme = $.cookie(COOKIE_THEME) || ($.cookie(COOKIE_DARK) === 'true' ? 'dark' : 'light'),
if ( $.cookie(THEME_COOKIE) == null ) {
        fixedMode = $.cookie(COOKIE_FIXED) === 'true',
$.cookie(THEME_COOKIE, theme, {expires: 365, path: '/'});
        popup;
}
},


createThemeButton: function() {
    function applyTheme(name) {
// Add the theme toggle button inside #user-tools
        // Remove old theme classes
themePortletLink = mw.util.addPortletLink(
        $('body').removeClass(function(i, cls) {
'user-tools',
            return (cls.match(/mw-theme-\S+/g) || []).join(' ');
'',
        });
'pt-theme-toggle',
        if (name !== 'light') {
'Change theme',
            $('body').addClass('mw-theme-' + name);
null,
        }
'#user-tools'
    }
);
$(themePortletLink).find('a')
.addClass('oo-ui-icon-advanced')
.on('click', function(e) {
e.preventDefault();
if (!themePopup) {
mw.loader.using(['oojs-ui-core','oojs-ui-windows','oojs-ui-widgets']).then(self.buildThemePopup);
} else {
themePopup.toggle();
}
});
},


buildThemePopup: function() {
    function initThemeToggle() {
var themeSwitch = new OO.ui.ButtonSelectWidget({
        var link = mw.util.addPortletLink(
items: [
            'user-tools',      // Portlet
new OO.ui.ButtonOptionWidget({data: 'light', label: 'Light'}),
            '#',               // href
new OO.ui.ButtonOptionWidget({data: 'dark', label: 'Dark'})
            'Theme',           // link text
]
            'pt-theme-toggle', // id
});
            'Toggle theme',    // tooltip
themeSwitch.selectItemByData(theme);
            null,              // before
themeSwitch.on('choose', function() {
            '#user-tools'      // after selector ensures inside #user-tools
theme = themeSwitch.findSelectedItem().getData();
        );
$.cookie(THEME_COOKIE, theme, {expires: 365, path: '/'});
        $(link).find('a').on('click', function(e) {
self.applyTheme(theme);
            e.preventDefault();
});
            if (!popup) {
                mw.loader.using(['oojs-ui-core', 'oojs-ui-windows', 'oojs-ui-widgets'], createPopup);
            } else {
                popup.toggle();
            }
        });
    }


themePopup = new OO.ui.PopupWidget({
    function createPopup() {
$content: themeSwitch.$element,
        var toggle = new OO.ui.ButtonSelectWidget({
$floatableContainer: $(themePortletLink),
            items: [
autoClose: true
                new OO.ui.ButtonOptionWidget({data: 'light', label: 'Light'}),
});
                new OO.ui.ButtonOptionWidget({data: 'dark', label: 'Dark'})
$(document.body).append(themePopup.$element);
            ]
themePopup.toggle(true);
        });
},
        toggle.selectItemByData(theme);
        toggle.on('choose', function() {
            theme = toggle.findSelectedItem().getData();
            $.cookie(COOKIE_THEME, theme, {expires: 365, path: '/'});
            applyTheme(theme);
        });


applyTheme: function(name) {
        popup = new OO.ui.PopupWidget({
$('body').removeClass(function(i, cls) {
            $content: toggle.$element,
return (cls.match(/wgl-theme-\S+/g) || []).join(' ');
            $floatableContainer: $( '#pt-theme-toggle' ),
});
            autoClose: true
if (name !== 'light') {
        });
mw.loader.using(['wgl.theme.' + name]).then(function() {
        $(document.body).append(popup.$element);
$('body').addClass('wgl-theme-' + name);
        popup.toggle(true);
});
    }
}
},


toggleFixedWidth: function () {
    function toggleFixedWidth() {
fixedWidthEnabled = !fixedWidthEnabled;
        fixedMode = !fixedMode;
if (fixedWidthEnabled) {
        if (fixedMode) {
$('body').addClass('wgl-fixedWidth');
            mw.loader.load('wg.fixedwidth');
mw.loader.load('wg.fixedwidth');
            $('body').addClass('mw-fixed-width');
} else {
        } else {
$('body').removeClass('wgl-fixedWidth');
            $('body').removeClass('mw-fixed-width');
}
        }
$.cookie('readermode', fixedWidthEnabled, {expires: 365, path: '/'});
        $.cookie(COOKIE_FIXED, fixedMode, {expires: 365, path: '/'});
},
    }


createFixedWidthToggle: function() {
    function initFixedToggle() {
var link = mw.util.addPortletLink('p-personal', '', '', 'pt-fixed-width', 'Toggle fixed-width mode');
        var link = mw.util.addPortletLink(
$(link).find('a').on('click', function(e) {
            'p-personal',
e.preventDefault();
            '#',
self.toggleFixedWidth();
            'Fixed width',
});
            'pt-fixed-toggle',
},
            'Toggle fixed width'
        );
        $(link).find('a').on('click', function(e) {
            e.preventDefault();
            toggleFixedWidth();
        });
    }


createSettingsButton: function() {
    function initStickyToggle() {
settingsPortletLink = mw.util.addPortletLink('p-personal', '', '', 'pt-settings', 'Appearance settings');
        var initial = $.cookie(COOKIE_STICKY) === 'true',
$(settingsPortletLink).find('a').on('click', function(e) {
            link = mw.util.addPortletLink(
e.preventDefault();
                'p-personal',
mw.loader.using(['oojs-ui-core','oojs-ui-windows','oojs-ui-widgets']).then(self.openSettingsModal);
                '#',
});
                'Sticky header',
},
                'pt-sticky-toggle',
                'Toggle sticky header'
            );
        $(link).find('a').on('click', function(e) {
            e.preventDefault();
            initial = !initial;
            $.cookie(COOKIE_STICKY, initial, {expires: 365, path: '/'});
            if (initial) {
                $('body').addClass('mw-sticky-header');
            } else {
                $('body').removeClass('mw-sticky-header');
            }
        });
        // apply on load
        if (initial) $('body').addClass('mw-sticky-header');
    }


openSettingsModal: function() {
    // Initialization after core modules
var stickySwitch = new OO.ui.ToggleSwitchWidget({value: $.cookie(STICKY_HEADER_COOKIE)==='true'});
    mw.loader.using(['jquery.cookie', 'oojs-ui-core'], function() {
stickySwitch.on('change', function() {
        applyTheme(theme);
$.cookie(STICKY_HEADER_COOKIE, stickySwitch.getValue(), {expires:365, path:'/'});
        initThemeToggle();
});
        initFixedToggle();
        initStickyToggle();
    });


var closeBtn = new OO.ui.ButtonInputWidget({label: 'Close', flags: 'destructive'});
})(jQuery, mediaWiki);
var $content = $('<div>').append(
$('<h3>').text('Sticky header'),
stickySwitch.$element,
closeBtn.$element
);
 
rs.createOOUIWindow('settings', 'Appearance settings', {size:'medium'}, function(modal){
modal.$body.append($content);
closeBtn.on('click', function(){ window.OOUIWindowManager.closeWindow(modal); });
}, true);
}
};
 
mw.loader.using(['ext.gadget.rsw-util'], function(){
$(self.init);
});
 
}(jQuery, mediaWiki, rswiki));


const IFRAME_CONFIG = {
const IFRAME_CONFIG = {