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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
Строка 18: Строка 18:
     $('.боковая-панель-кнопка:first').click();
     $('.боковая-панель-кнопка:first').click();
      
      
     $('.допуск-контейнер').hover(function() {
     // Подключаем Tippy.js через CDN динамически
         var $tooltip = $(this).find('.допуск-подсказка');
if (!window.tippy) {
         var $container = $(this);
    var tippyScript = document.createElement('script');
    tippyScript.src = "https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js";
    tippyScript.onload = function() {
         var tippyCoreScript = document.createElement('script');
        tippyCoreScript.src = "https://unpkg.com/tippy.js@6/dist/tippy-bundle.umd.min.js";
         tippyCoreScript.onload = initTippy;
        document.head.appendChild(tippyCoreScript);
    };
    document.head.appendChild(tippyScript);


        var rect = $container[0].getBoundingClientRect();
    // Подключаем CSS
        var tooltipRect = $tooltip[0].getBoundingClientRect();
    var tippyCSS = document.createElement('link');
        var viewportWidth = $(window).width();
    tippyCSS.rel = "stylesheet";
        var viewportHeight = $(window).height();
    tippyCSS.href = "https://unpkg.com/tippy.js@6/dist/tippy.css";
    document.head.appendChild(tippyCSS);
} else {
    initTippy();
}


        var left = rect.left + rect.width / 2 - tooltipRect.width / 2;
// Инициализация Tippy после загрузки скриптов
        if (left + tooltipRect.width > viewportWidth - 10) left = viewportWidth - tooltipRect.width - 10;
function initTippy() {
        if (left < 10) left = 10;
    $('.допуск-контейнер').each(function() {
         $tooltip.css('left', left + 'px');
         var content = $(this).find('.допуск-подсказка').html(); // берем содержимое подсказки
 
         tippy(this, {
        var bottom = rect.height + 10; // по умолчанию снизу
            content: content,
         var top = 'auto';
            allowHTML: true,
 
            interactive: true,
        if (rect.bottom + tooltipRect.height + 10 > viewportHeight) {
            placement: 'auto',      // автоматический выбор позиции
             if (rect.top - tooltipRect.height - 10 >= 0) {
             maxWidth: '80vw',      // responsive
                top = rect.top - tooltipRect.height - 10 + 'px';
            theme: 'dark',          // темная тема
                bottom = 'auto';
             arrow: false,          // без стрелки
             } else {
            duration: [200, 200],  // плавное появление/исчезание
                top = rect.top + rect.height / 2 - tooltipRect.height / 2 + 'px';
            popperOptions: {
                 bottom = 'auto';
                 modifiers: [
            }
                    {
        }
                        name: 'preventOverflow',
 
                        options: {
        $tooltip.css({
                            padding: 8, // отступ от краев экрана
            'top': top,
                        },
            'bottom': bottom === 'auto' ? 'auto' : bottom + 'px',
                    },
            'opacity': 1,
                    {
             'transform': 'translateY(0)'
                        name: 'flip',
                        options: {
                            fallbackPlacements: ['top', 'bottom', 'right', 'left'],
                        },
                    },
                ],
             },
         });
         });
    });
}


    }, function() {
        $(this).find('.допуск-подсказка').css({
            'opacity': 0,
            'transform': 'translateY(10px)'
        });
    });
});
});

Версия от 12:45, 30 августа 2025

$(document).ready(function() {
    // Инициализация боковой панели
    $('.боковая-панель-кнопка').on('click', function() {
        var targetId = $(this).data('target');
        
        // Удаляем активный класс у всех кнопок
        $('.боковая-панель-кнопка').removeClass('active');
        // Добавляем активный класс текущей кнопке
        $(this).addClass('active');
        
        // Скрываем все разделы
        $('.боковая-панель-раздел').removeClass('default');
        // Показываем выбранный раздел
        $('#' + targetId).addClass('default');
    });
    
    // Активируем первую кнопку по умолчанию
    $('.боковая-панель-кнопка:first').click();
    
    // Подключаем Tippy.js через CDN динамически
if (!window.tippy) {
    var tippyScript = document.createElement('script');
    tippyScript.src = "https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js";
    tippyScript.onload = function() {
        var tippyCoreScript = document.createElement('script');
        tippyCoreScript.src = "https://unpkg.com/tippy.js@6/dist/tippy-bundle.umd.min.js";
        tippyCoreScript.onload = initTippy;
        document.head.appendChild(tippyCoreScript);
    };
    document.head.appendChild(tippyScript);

    // Подключаем CSS
    var tippyCSS = document.createElement('link');
    tippyCSS.rel = "stylesheet";
    tippyCSS.href = "https://unpkg.com/tippy.js@6/dist/tippy.css";
    document.head.appendChild(tippyCSS);
} else {
    initTippy();
}

// Инициализация Tippy после загрузки скриптов
function initTippy() {
    $('.допуск-контейнер').each(function() {
        var content = $(this).find('.допуск-подсказка').html(); // берем содержимое подсказки
        tippy(this, {
            content: content,
            allowHTML: true,
            interactive: true,
            placement: 'auto',      // автоматический выбор позиции
            maxWidth: '80vw',       // responsive
            theme: 'dark',          // темная тема
            arrow: false,           // без стрелки
            duration: [200, 200],   // плавное появление/исчезание
            popperOptions: {
                modifiers: [
                    {
                        name: 'preventOverflow',
                        options: {
                            padding: 8, // отступ от краев экрана
                        },
                    },
                    {
                        name: 'flip',
                        options: {
                            fallbackPlacements: ['top', 'bottom', 'right', 'left'],
                        },
                    },
                ],
            },
        });
    });
}

});