Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показаны 3 промежуточные версии этого же участника)
Строка 57: Строка 57:
         }
         }
     });
     });
   
    mw.hook('wikipage.content').add(function($content) {
    $content.on('click', '.tab-link', function() {
        var $this = $(this);
        var targetId = $this.attr('data-target');
        var $container = $this.closest('.tab-container');
        if (!targetId) return;
        $container.find('.tab-link').removeClass('active');
        $this.addClass('active');
        $container.find('.tab-pane').removeClass('active');
        $('#' + targetId).addClass('active');
    });
});
});
});

Текущая версия от 00:51, 13 апреля 2026

mw.hook('wikipage.content').add(function($content) {
    $content.find('.yastre-carousel-container').each(function() {
        let $carousel = $(this);
        let $items = $carousel.find('.carousel-item');
        if ($items.length < 2) return;

        function updateCarousel(newIndex) {
            $items.removeClass('active prev next hidden');
            $items.addClass('hidden');

            let total = $items.length;
            let prevIndex = (newIndex - 1 + total) % total;
            let nextIndex = (newIndex + 1) % total;

            $items.eq(newIndex).removeClass('hidden').addClass('active');

            if (total > 2) {
                $items.eq(prevIndex).removeClass('hidden').addClass('prev');
                $items.eq(nextIndex).removeClass('hidden').addClass('next');
            } else if (total === 2) {
                $items.eq(nextIndex).removeClass('hidden').addClass('next');
            }
        }

        $carousel.on('click', '.carousel-item.prev, .carousel-item.next', function(e) {
            e.preventDefault();
            e.stopPropagation();

            let currIndex = $items.index($carousel.find('.active'));
            if ($(this).hasClass('prev')) {
                updateCarousel((currIndex - 1 + $items.length) % $items.length);
            } else {
                updateCarousel((currIndex + 1) % $items.length);
            }
        });

        let touchstartX = 0;
        let touchendX = 0;

        $carousel.on('touchstart', function(e) {
            touchstartX = e.changedTouches[0].screenX;
        }, { passive: true });

        $carousel.on('touchend', function(e) {
            touchendX = e.changedTouches[0].screenX;
            handleSwipe();
        }, { passive: true });

        function handleSwipe() {
            let currIndex = $items.index($carousel.find('.active'));
            if (touchendX < touchstartX - 40) {
                updateCarousel((currIndex + 1) % $items.length);
            }
            if (touchendX > touchstartX + 40) {
                updateCarousel((currIndex - 1 + $items.length) % $items.length);
            }
        }
    });
    
    mw.hook('wikipage.content').add(function($content) {
    $content.on('click', '.tab-link', function() {
        var $this = $(this);
        var targetId = $this.attr('data-target');
        var $container = $this.closest('.tab-container');

        if (!targetId) return;

        $container.find('.tab-link').removeClass('active');
        $this.addClass('active');

        $container.find('.tab-pane').removeClass('active');
        $('#' + targetId).addClass('active');
    });
});
});