MediaWiki:Gadget-theme.js: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
;(function($, mw){ | ;(function($, mw){ | ||
const COOKIE = 'ss14_wikiTheme'; | const COOKIE = 'ss14_wikiTheme'; | ||
const COOKIE_SPACE = 'ss14_spaceAnimation'; | |||
function loadTheme() { | function loadTheme() { | ||
| Строка 20: | Строка 21: | ||
$body.addClass(`wgl-theme-${theme}`); | $body.addClass(`wgl-theme-${theme}`); | ||
mw.hook('wgl.themeChanged').fire(theme); | mw.hook('wgl.themeChanged').fire(theme); | ||
} | |||
function loadSpaceAnimation() { | |||
return $.cookie(COOKIE_SPACE) || 'on'; | |||
} | |||
function saveSpaceAnimation(val) { | |||
$.cookie(COOKIE_SPACE, val, { expires: 365, path: '/' }); | |||
} | |||
function applySpaceAnimation(val) { | |||
const $body = $('body'); | |||
$body.attr('data-ss14-space-animation', val); | |||
mw.hook('ss14.spaceAnimationChanged').fire(val); | |||
} | } | ||
| Строка 36: | Строка 51: | ||
const $form = $('<form>'); | const $form = $('<form>'); | ||
[ | [ | ||
{ key: 'light', label: 'Светлая | { key: 'light', label: 'Светлая' }, | ||
{ key: 'normal', label: 'Стандартная' }, | { key: 'normal', label: 'Стандартная' }, | ||
{ key: 'dark', label: 'Тёмная' }, | { key: 'dark', label: 'Тёмная' }, | ||
| Строка 64: | Строка 79: | ||
) | ) | ||
); | ); | ||
$container.append($portlet); | $container.append($portlet); | ||
initSpaceMenu($portlet); | |||
$form.on('change', 'input[name="theme-selection"]', function() { | $form.on('change', 'input[name="theme-selection"]', function() { | ||
| Строка 73: | Строка 90: | ||
} | } | ||
mw.themeUtils = { loadTheme, applyTheme, initThemeMenu }; | function initSpaceMenu($afterPortlet, currentVal) { | ||
currentVal = currentVal || loadSpaceAnimation(); | |||
const $spacePortlet = $('<div>', { | |||
class: 'mw-portlet mw-portlet-skin-client-prefs-skin-space mw-portlet-js space-menu', | |||
id: 'skin-client-prefs-skin-space' | |||
}); | |||
$spacePortlet.append( | |||
$('<div>', { class: 'theme-menu__heading', text: 'Космос' }), | |||
$('<div>', { class: 'theme-menu__content' }) | |||
); | |||
const $form = $('<form>'); | |||
[ | |||
{ val: 'on', label: 'Включено' }, | |||
{ val: 'off', label: 'Выключено' } | |||
].forEach(opt => { | |||
const $wr = $('<div>', { class: 'space-client-prefs-radio' }); | |||
const $inp = $('<input>', { | |||
type: 'radio', | |||
name: 'space-animation-selection', | |||
id: `space-value-${opt.val}`, | |||
value: opt.val, | |||
checked: opt.val === currentVal | |||
}); | |||
const $lbl = $('<label>', { | |||
for: `space-value-${opt.val}`, | |||
text: opt.label | |||
}); | |||
$wr.append($inp, $lbl); | |||
$form.append($wr); | |||
}); | |||
$spacePortlet.find('.theme-menu__content').append( | |||
$('<ul>', { class: 'theme-menu__content-list' }) | |||
.append( | |||
$('<li>', { class: 'mw-list-item mw-list-item-js' }) | |||
.append($form) | |||
) | |||
); | |||
$afterPortlet.after($spacePortlet); | |||
applySpaceAnimation(currentVal); | |||
$form.on('change', 'input[name="space-animation-selection"]', function() { | |||
const newVal = $(this).val(); | |||
saveSpaceAnimation(newVal); | |||
applySpaceAnimation(newVal); | |||
}); | |||
} | |||
mw.themeUtils = { | |||
loadTheme, | |||
applyTheme, | |||
initThemeMenu, | |||
loadSpaceAnimation, | |||
saveSpaceAnimation, | |||
applySpaceAnimation, | |||
initSpaceMenu | |||
}; | |||
}(jQuery, mediaWiki)); | }(jQuery, mediaWiki)); | ||
Версия от 08:26, 31 января 2026
;(function($, mw){
const COOKIE = 'ss14_wikiTheme';
const COOKIE_SPACE = 'ss14_spaceAnimation';
function loadTheme() {
return $.cookie(COOKIE) || 'dark';
}
function saveTheme(theme) {
$.cookie(COOKIE, theme, { expires: 365, path: '/' });
}
function applyTheme(theme) {
const $body = $('body');
const themeClasses = ($body.attr('class') || '')
.split(/\s+/)
.filter(cls => cls.indexOf('wgl-theme-') === 0);
if (themeClasses.length) {
$body.removeClass(themeClasses.join(' '));
}
$body.addClass(`wgl-theme-${theme}`);
mw.hook('wgl.themeChanged').fire(theme);
}
function loadSpaceAnimation() {
return $.cookie(COOKIE_SPACE) || 'on';
}
function saveSpaceAnimation(val) {
$.cookie(COOKIE_SPACE, val, { expires: 365, path: '/' });
}
function applySpaceAnimation(val) {
const $body = $('body');
$body.attr('data-ss14-space-animation', val);
mw.hook('ss14.spaceAnimationChanged').fire(val);
}
function initThemeMenu($container, currentTheme) {
currentTheme = currentTheme || loadTheme();
const $portlet = $('<div>', {
class: 'mw-portlet mw-portlet-skin-client-prefs-skin-theme mw-portlet-js theme-menu',
id: 'skin-client-prefs-skin-theme'
});
$portlet.append(
$('<div>', { class: 'theme-menu__heading', text: 'Тема' }),
$('<div>', { class: 'theme-menu__content' })
);
const $form = $('<form>');
[
{ key: 'light', label: 'Светлая' },
{ key: 'normal', label: 'Стандартная' },
{ key: 'dark', label: 'Тёмная' },
{ key: 'ss14', label: 'Space Station 14' }
].forEach(opt => {
const $wr = $('<div>', { class: 'theme-client-prefs-radio' });
const $inp = $('<input>', {
type: 'radio',
name: 'theme-selection',
id: `theme-value-${opt.key}`,
value: opt.key,
checked: opt.key === currentTheme
});
const $lbl = $('<label>', {
for: `theme-value-${opt.key}`,
text: opt.label
});
$wr.append($inp, $lbl);
$form.append($wr);
});
$portlet.find('.theme-menu__content').append(
$('<ul>', { class: 'theme-menu__content-list' })
.append(
$('<li>', { class: 'mw-list-item mw-list-item-js' })
.append($form)
)
);
$container.append($portlet);
initSpaceMenu($portlet);
$form.on('change', 'input[name="theme-selection"]', function() {
const newTheme = $(this).val();
saveTheme(newTheme);
applyTheme(newTheme);
});
}
function initSpaceMenu($afterPortlet, currentVal) {
currentVal = currentVal || loadSpaceAnimation();
const $spacePortlet = $('<div>', {
class: 'mw-portlet mw-portlet-skin-client-prefs-skin-space mw-portlet-js space-menu',
id: 'skin-client-prefs-skin-space'
});
$spacePortlet.append(
$('<div>', { class: 'theme-menu__heading', text: 'Космос' }),
$('<div>', { class: 'theme-menu__content' })
);
const $form = $('<form>');
[
{ val: 'on', label: 'Включено' },
{ val: 'off', label: 'Выключено' }
].forEach(opt => {
const $wr = $('<div>', { class: 'space-client-prefs-radio' });
const $inp = $('<input>', {
type: 'radio',
name: 'space-animation-selection',
id: `space-value-${opt.val}`,
value: opt.val,
checked: opt.val === currentVal
});
const $lbl = $('<label>', {
for: `space-value-${opt.val}`,
text: opt.label
});
$wr.append($inp, $lbl);
$form.append($wr);
});
$spacePortlet.find('.theme-menu__content').append(
$('<ul>', { class: 'theme-menu__content-list' })
.append(
$('<li>', { class: 'mw-list-item mw-list-item-js' })
.append($form)
)
);
$afterPortlet.after($spacePortlet);
applySpaceAnimation(currentVal);
$form.on('change', 'input[name="space-animation-selection"]', function() {
const newVal = $(this).val();
saveSpaceAnimation(newVal);
applySpaceAnimation(newVal);
});
}
mw.themeUtils = {
loadTheme,
applyTheme,
initThemeMenu,
loadSpaceAnimation,
saveSpaceAnimation,
applySpaceAnimation,
initSpaceMenu
};
}(jQuery, mediaWiki));