MediaWiki:Common.js: различия между версиями
Страница интерфейса MediaWiki
Дополнительные действия
Нет описания правки Метка: ручная отмена |
Нет описания правки |
||
| Строка 57: | Строка 57: | ||
} | } | ||
}); | }); | ||
$(document).ready(function() { | |||
$('.tabs-nav a.tab-link').on('click', function(e) { | |||
e.preventDefault(); | |||
var targetId = $(this).attr('href'); | |||
$(this).closest('.tab-container').find('.tab-link, .tab-pane').removeClass('active'); | |||
$(this).addClass('active'); | |||
$(targetId).addClass('active'); | |||
}); | |||
}); | |||
}); | }); | ||
Версия от 00:39, 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);
}
}
});
$(document).ready(function() {
$('.tabs-nav a.tab-link').on('click', function(e) {
e.preventDefault();
var targetId = $(this).attr('href');
$(this).closest('.tab-container').find('.tab-link, .tab-pane').removeClass('active');
$(this).addClass('active');
$(targetId).addClass('active');
});
});
});