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

Материал из GorbyWiki
Новая страница: «Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице: // Кнопки размера текста для статей $(document).ready(function() { $('#btn-minus').click(function() { var el = document.getElementById('article-text'); if (el) { var current = parseFloat(window.getComputedStyle(el).fontSize)...»
 
Нет описания правки
 
(не показаны 2 промежуточные версии этого же участника)
Строка 1: Строка 1:
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
// Кнопки размера текста для статей
// Кнопки размера текста для статей и выступлений
$(document).ready(function() {
$(document).ready(function() {
     $('#btn-minus').click(function() {
    function getEl() {
         var el = document.getElementById('article-text');
        return document.getElementById('article-text');
    }
     $('#btn-minus').on('click', function() {
         var el = getEl();
         if (el) {
         if (el) {
             var current = parseFloat(window.getComputedStyle(el).fontSize);
             var current = parseFloat(window.getComputedStyle(el).fontSize);
Строка 9: Строка 12:
         }
         }
     });
     });
     $('#btn-reset').click(function() {
     $('#btn-reset').on('click', function() {
         var el = document.getElementById('article-text');
         var el = getEl();
         if (el) { el.style.fontSize = '1em'; }
         if (el) { el.style.fontSize = '1em'; }
     });
     });
     $('#btn-plus').click(function() {
     $('#btn-plus').on('click', function() {
         var el = document.getElementById('article-text');
         var el = getEl();
         if (el) {
         if (el) {
             var current = parseFloat(window.getComputedStyle(el).fontSize);
             var current = parseFloat(window.getComputedStyle(el).fontSize);
Строка 21: Строка 24:
     });
     });
});
});
/* Кнопка «Наверх» — 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';
  });
})();

Текущая версия от 15:19, 22 апреля 2026

/* Размещённый здесь код 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';
  });
})();