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() {
$('#btn-minus').click(function() {
var el = document.getElementById('article-text');
if (el) {
var current = parseFloat(window.getComputedStyle(el).fontSize);
el.style.fontSize = (current - 2) + 'px';
}
});
$('#btn-reset').click(function() {
var el = document.getElementById('article-text');
if (el) { el.style.fontSize = '1em'; }
});
$('#btn-plus').click(function() {
var el = document.getElementById('article-text');
if (el) {
var current = parseFloat(window.getComputedStyle(el).fontSize);
el.style.fontSize = (current + 2) + 'px';
}
});
});
/* Кнопка «Наверх» — GorbyWiki */
(function () {
var btn = document.createElement('button');
btn.innerHTML = '';
btn.title = 'Наверх';
btn.style.cssText = [
'position:fixed',
'bottom:32px',
'right:28px',
'width:48px',
'height:48px',
'border-radius:50%',
'background:#faf8f3',
'border:1.5px solid #d4c4a8',
'display:flex',
'align-items:center',
'justify-content:center',
'cursor:pointer',
'opacity:0',
'transition:opacity 0.25s, background 0.15s, border-color 0.15s',
'z-index:9999',
'box-shadow:none'
].join(';');
btn.onmouseenter = function () {
btn.style.background = '#fffaf0';
btn.style.borderColor = '#8b4513';
};
btn.onmouseleave = function () {
btn.style.background = '#faf8f3';
btn.style.borderColor = '#d4c4a8';
};
btn.onclick = function () {
window.scrollTo({ top: 0, behavior: 'smooth' });
};
document.body.appendChild(btn);
window.addEventListener('scroll', function () {
btn.style.opacity = window.scrollY > 300 ? '1' : '0';
btn.style.pointerEvents = window.scrollY > 300 ? 'auto' : 'none';
});
})();
