MediaWiki:Common.js: различия между версиями
Страница интерфейса MediaWiki
Дополнительные действия
Нет описания правки |
Нет описания правки |
||
| Строка 1: | Строка 1: | ||
mw.hook('wikipage.content').add(function($content) { | mw.hook('wikipage.content').add(function($content) { | ||
$content.find('.yastre-carousel-container').each(function() { | $content.find('.yastre-carousel-container').each(function() { | ||
let $carousel = $(this); | let $carousel = $(this); | ||
Версия от 17:15, 20 февраля 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);
}
}
});
});