MediaWiki:Common.js: различия между версиями
Страница интерфейса MediaWiki
Дополнительные действия
Новая страница: «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 = (new...» |
Нет описания правки |
||
| (не показано 5 промежуточных версий этого же участника) | |||
| Строка 3: | Строка 3: | ||
let $carousel = $(this); | let $carousel = $(this); | ||
let $items = $carousel.find('.carousel-item'); | let $items = $carousel.find('.carousel-item'); | ||
if ($items.length < 2) return; | if ($items.length < 2) return; | ||
function updateCarousel(newIndex) { | function updateCarousel(newIndex) { | ||
| Строка 14: | Строка 14: | ||
$items.eq(newIndex).removeClass('hidden').addClass('active'); | $items.eq(newIndex).removeClass('hidden').addClass('active'); | ||
if (total > 2) { | if (total > 2) { | ||
$items.eq(prevIndex).removeClass('hidden').addClass('prev'); | $items.eq(prevIndex).removeClass('hidden').addClass('prev'); | ||
| Строка 39: | Строка 39: | ||
$carousel.on('touchstart', function(e) { | $carousel.on('touchstart', function(e) { | ||
touchstartX = e.changedTouches.screenX; | touchstartX = e.changedTouches[0].screenX; | ||
}, { passive: true }); | }, { passive: true }); | ||
$carousel.on('touchend', function(e) { | $carousel.on('touchend', function(e) { | ||
touchendX = e.changedTouches.screenX; | touchendX = e.changedTouches[0].screenX; | ||
handleSwipe(); | handleSwipe(); | ||
}, { passive: true }); | }, { passive: true }); | ||
| Строка 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');
});
});
});