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

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


Строка 12: Строка 12:


     function applyTheme(name) {
     function applyTheme(name) {
        // Remove old theme classes
         $('body').removeClass(function(i, cls) {
         $('body').removeClass(function(i, cls) {
             return (cls.match(/mw-theme-\S+/g) || []).join(' ');
             return (cls.match(/mw-theme-\S+/g) || []).join(' ');
Строка 22: Строка 21:


     function initThemeToggle() {
     function initThemeToggle() {
         var link = mw.util.addPortletLink(
         var $tools = $('#user-tools');
            'user-tools',      // Portlet
        if (!$tools.length) return;
            '#',                // href
        var $link = $('<a>', {
            'Theme',           // link text
             id: 'pt-theme-toggle',
             'pt-theme-toggle', // id
             href: '#',
             'Toggle theme',     // tooltip
            title: 'Toggle theme',
             null,              // before
             text: 'Theme'
            '#user-tools'       // after selector ensures inside #user-tools
        }).addClass('oo-ui-icon-advanced mw-ui-button')
        );
          .css({marginLeft: '0.5em'});
         $(link).find('a').on('click', function(e) {
         $tools.append($link);
        $link.on('click', function(e) {
             e.preventDefault();
             e.preventDefault();
             if (!popup) {
             if (!popup) {
Строка 54: Строка 54:
             applyTheme(theme);
             applyTheme(theme);
         });
         });
         popup = new OO.ui.PopupWidget({
         popup = new OO.ui.PopupWidget({
             $content: toggle.$element,
             $content: toggle.$element,
             $floatableContainer: $( '#pt-theme-toggle' ),
             $floatableContainer: $('#pt-theme-toggle'),
             autoClose: true
             autoClose: true
         });
         });
Строка 76: Строка 75:


     function initFixedToggle() {
     function initFixedToggle() {
         var link = mw.util.addPortletLink(
         var $container = $('#pt-personal');
            'p-personal',
        // fallback if personal portlet not found
            '#',
        if (!$container.length) $container = $('#p-personal');
            'Fixed width',
        var $link = $('<a>', {
             'pt-fixed-toggle',
             id: 'pt-fixed-toggle',
             'Toggle fixed width'
             href: '#',
         );
            title: 'Toggle fixed width',
         $(link).find('a').on('click', function(e) {
            text: 'Fixed width'
         }).addClass('mw-ui-button');
         $container.append($('<li>').append($link));
        $link.on('click', function(e) {
             e.preventDefault();
             e.preventDefault();
             toggleFixedWidth();
             toggleFixedWidth();
Строка 90: Строка 92:


     function initStickyToggle() {
     function initStickyToggle() {
         var initial = $.cookie(COOKIE_STICKY) === 'true',
         var sticky = $.cookie(COOKIE_STICKY) === 'true';
            link = mw.util.addPortletLink(
        var $container = $('#pt-personal');
                'p-personal',
        if (!$container.length) $container = $('#p-personal');
                '#',
        var $link = $('<a>', {
                'Sticky header',
            id: 'pt-sticky-toggle',
                'pt-sticky-toggle',
            href: '#',
                'Toggle sticky header'
            title: 'Toggle sticky header',
             );
             text: 'Sticky header'
         $(link).find('a').on('click', function(e) {
        }).addClass('mw-ui-button');
         $container.append($('<li>').append($link));
        $link.on('click', function(e) {
             e.preventDefault();
             e.preventDefault();
             initial = !initial;
             sticky = !sticky;
             $.cookie(COOKIE_STICKY, initial, {expires: 365, path: '/'});
             $.cookie(COOKIE_STICKY, sticky, {expires: 365, path: '/'});
             if (initial) {
             $('body').toggleClass('mw-sticky-header', sticky);
                $('body').addClass('mw-sticky-header');
            } else {
                $('body').removeClass('mw-sticky-header');
            }
         });
         });
        // apply on load
         if (sticky) $('body').addClass('mw-sticky-header');
         if (initial) $('body').addClass('mw-sticky-header');
     }
     }


     // Initialization after core modules
     // After modules loaded
     mw.loader.using(['jquery.cookie', 'oojs-ui-core'], function() {
     mw.loader.using(['jquery.cookie', 'oojs-ui-core'], function() {
         applyTheme(theme);
         applyTheme(theme);