MediaWiki:Vector.js: Difference between revisions
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
/* All JavaScript here will be loaded for users of the Vector skin */ | /* All JavaScript here will be loaded for users of the Vector skin */ | ||
mw.loader.using('mediawiki.util').then(function() { | mw.loader.using('mediawiki.util').then(function () { | ||
mw.hook('wikipage.content').add(function () { | |||
mw.hook('wikipage.content').add(function( | document.querySelectorAll('.news-slideshow-container').forEach(function (container) { | ||
var slides = container.querySelectorAll('.news-slideshow-slide'); | var slides = container.querySelectorAll('.news-slideshow-slide'); | ||
if (slides.length <= 1) return; | if (slides.length <= 1) return; | ||
var current = 0; | var current = 0; | ||
slides | var intervalId = null; | ||
var delay = 8000; // 8 seconds | |||
function showSlide(index) { | |||
slides.forEach(function (slide, i) { | |||
slide.classList.toggle('active', i === index); | |||
}); | |||
} | |||
function startSlideshow() { | |||
if (intervalId !== null) return; | |||
intervalId = setInterval(function () { | |||
current = (current + 1) % slides.length; | |||
showSlide(current); | |||
}, delay); | |||
} | |||
function stopSlideshow() { | |||
if (intervalId !== null) { | |||
clearInterval(intervalId); | |||
intervalId = null; | |||
} | |||
} | |||
// Initial state | |||
showSlide(current); | |||
startSlideshow(); | |||
// Pause on hover | |||
container.addEventListener('mouseenter', stopSlideshow); | |||
container.addEventListener('mouseleave', startSlideshow); | |||
}); | }); | ||
}); | }); | ||
}); | }); | ||
Revision as of 01:31, 25 January 2026
/* All JavaScript here will be loaded for users of the Vector skin */
mw.loader.using('mediawiki.util').then(function () {
mw.hook('wikipage.content').add(function () {
document.querySelectorAll('.news-slideshow-container').forEach(function (container) {
var slides = container.querySelectorAll('.news-slideshow-slide');
if (slides.length <= 1) return;
var current = 0;
var intervalId = null;
var delay = 8000; // 8 seconds
function showSlide(index) {
slides.forEach(function (slide, i) {
slide.classList.toggle('active', i === index);
});
}
function startSlideshow() {
if (intervalId !== null) return;
intervalId = setInterval(function () {
current = (current + 1) % slides.length;
showSlide(current);
}, delay);
}
function stopSlideshow() {
if (intervalId !== null) {
clearInterval(intervalId);
intervalId = null;
}
}
// Initial state
showSlide(current);
startSlideshow();
// Pause on hover
container.addEventListener('mouseenter', stopSlideshow);
container.addEventListener('mouseleave', startSlideshow);
});
});
});
document.addEventListener('click', function (e) {
const header = e.target.closest('.pf-collapsible');
if (!header) return;
const targetId = header.dataset.target;
const section = document.getElementById(targetId);
if (!section) return;
const isOpen = section.style.display === 'block';
section.style.display = isOpen ? 'none' : 'block';
});