MediaWiki:Common.js
Материал из GorbyWiki
Замечание: Возможно, после публикации вам придётся очистить кэш своего браузера, чтобы увидеть изменения.
- Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl+F5 или Ctrl+R (⌘+R на Mac)
- Google Chrome: Нажмите Ctrl+Shift+R (⌘+Shift+R на Mac)
- Edge: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl+F5
- Opera: Нажмите Ctrl+F5.
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
// Кнопки размера текста для статей и выступлений
$(document).ready(function() {
function getEl() {
return document.getElementById('article-text');
}
$('#btn-minus').on('click', function() {
var el = getEl();
if (el) {
var current = parseFloat(window.getComputedStyle(el).fontSize);
el.style.fontSize = (current - 2) + 'px';
}
});
$('#btn-reset').on('click', function() {
var el = getEl();
if (el) { el.style.fontSize = '1em'; }
});
$('#btn-plus').on('click', function() {
var el = getEl();
if (el) {
var current = parseFloat(window.getComputedStyle(el).fontSize);
el.style.fontSize = (current + 2) + 'px';
}
});
});
/* Кнопка «Наверх» — GorbyWiki */
(function () {
var btn = document.createElement('button');
btn.innerHTML = '<svg viewBox="0 0 20 20" fill="none" stroke="#faf8f3" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M10 14V6M6 10l4-4 4 4"/></svg>';
btn.title = 'Наверх';
btn.style.cssText = [
'position:fixed',
'bottom:32px',
'right:28px',
'width:48px',
'height:48px',
'border-radius:50%',
'background:#5c4033',
'border:none',
'display:flex',
'align-items:center',
'justify-content:center',
'cursor:pointer',
'opacity:0',
'transition:opacity 0.25s, background 0.15s',
'z-index:9999'
].join(';');
btn.onmouseenter = function () { btn.style.background = '#8b4513'; };
btn.onmouseleave = function () { btn.style.background = '#5c4033'; };
btn.onclick = function () { window.scrollTo({ top: 0, behavior: 'smooth' }); };
document.body.appendChild(btn);
window.addEventListener('scroll', function () {
var visible = window.scrollY > 300;
btn.style.opacity = visible ? '1' : '0';
btn.style.pointerEvents = visible ? 'auto' : 'none';
});
})();
