MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
;(function($, mw){ | ;(function($, mw){ | ||
// Only | // 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) { | ||
$('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 | var $tools = $('#user-tools'); | ||
if (!$tools.length) return; | |||
var $link = $('<a>', { | |||
id: 'pt-theme-toggle', | |||
'pt-theme-toggle', | href: '#', | ||
'Toggle theme', | title: 'Toggle theme', | ||
text: 'Theme' | |||
}).addClass('oo-ui-icon-advanced mw-ui-button') | |||
.css({marginLeft: '0.5em'}); | |||
$(link) | $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 | var $container = $('#pt-personal'); | ||
// fallback if personal portlet not found | |||
if (!$container.length) $container = $('#p-personal'); | |||
var $link = $('<a>', { | |||
'pt-fixed-toggle', | id: 'pt-fixed-toggle', | ||
'Toggle fixed width' | href: '#', | ||
); | title: 'Toggle fixed width', | ||
$( | 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 | var sticky = $.cookie(COOKIE_STICKY) === 'true'; | ||
var $container = $('#pt-personal'); | |||
if (!$container.length) $container = $('#p-personal'); | |||
var $link = $('<a>', { | |||
id: 'pt-sticky-toggle', | |||
href: '#', | |||
title: 'Toggle sticky header', | |||
); | text: 'Sticky header' | ||
$( | }).addClass('mw-ui-button'); | ||
$container.append($('<li>').append($link)); | |||
$link.on('click', function(e) { | |||
e.preventDefault(); | e.preventDefault(); | ||
sticky = !sticky; | |||
$.cookie(COOKIE_STICKY, | $.cookie(COOKIE_STICKY, sticky, {expires: 365, path: '/'}); | ||
$('body').toggleClass('mw-sticky-header', sticky); | |||
}); | }); | ||
if (sticky) $('body').addClass('mw-sticky-header'); | |||
if ( | |||
} | } | ||
// | // 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); | ||