2026-02-21 13:59:57 -05:00
|
|
|
|
/**
|
2026-02-21 14:11:56 -05:00
|
|
|
|
* Gallery TV Slideshow
|
|
|
|
|
|
* Cycles through images inside gallery-TV blocks.
|
2026-02-21 13:59:57 -05:00
|
|
|
|
* Pauses off-screen via IntersectionObserver for performance.
|
2026-02-21 14:11:56 -05:00
|
|
|
|
* Respects prefers-reduced-motion.
|
2026-02-21 13:59:57 -05:00
|
|
|
|
*/
|
|
|
|
|
|
(function () {
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
2026-02-21 14:11:56 -05:00
|
|
|
|
var INTERVAL = 4000; // ms between slides
|
2026-02-21 13:59:57 -05:00
|
|
|
|
|
2026-02-21 14:11:56 -05:00
|
|
|
|
function boot() {
|
|
|
|
|
|
var stages = document.querySelectorAll('[data-gtv-slideshow]');
|
|
|
|
|
|
if (!stages.length) return;
|
2026-02-21 13:59:57 -05:00
|
|
|
|
|
2026-02-21 14:11:56 -05:00
|
|
|
|
/* Honour reduced-motion – show first slide only */
|
|
|
|
|
|
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
2026-02-21 13:59:57 -05:00
|
|
|
|
|
2026-02-21 14:11:56 -05:00
|
|
|
|
for (var i = 0; i < stages.length; i++) {
|
|
|
|
|
|
initSlideshow(stages[i]);
|
2026-02-21 13:59:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-21 14:11:56 -05:00
|
|
|
|
function initSlideshow(stage) {
|
|
|
|
|
|
var slides = stage.querySelectorAll('.gtv-slide');
|
|
|
|
|
|
if (slides.length < 2) return;
|
2026-02-21 13:59:57 -05:00
|
|
|
|
|
2026-02-21 14:11:56 -05:00
|
|
|
|
var state = { current: 0, paused: false, timer: null };
|
2026-02-21 13:59:57 -05:00
|
|
|
|
|
2026-02-21 14:11:56 -05:00
|
|
|
|
/* IntersectionObserver – pause when off-screen */
|
|
|
|
|
|
if ('IntersectionObserver' in window) {
|
|
|
|
|
|
new IntersectionObserver(function (entries) {
|
|
|
|
|
|
for (var j = 0; j < entries.length; j++) {
|
|
|
|
|
|
state.paused = !entries[j].isIntersecting;
|
2026-02-21 13:59:57 -05:00
|
|
|
|
}
|
2026-02-21 14:11:56 -05:00
|
|
|
|
if (!state.paused && !state.timer) {
|
|
|
|
|
|
state.timer = setInterval(function () { advance(slides, state); }, INTERVAL);
|
|
|
|
|
|
} else if (state.paused && state.timer) {
|
|
|
|
|
|
clearInterval(state.timer);
|
|
|
|
|
|
state.timer = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}, { rootMargin: '200px', threshold: 0.05 }).observe(stage);
|
2026-02-21 13:59:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-21 14:11:56 -05:00
|
|
|
|
/* Start cycling */
|
|
|
|
|
|
state.timer = setInterval(function () { advance(slides, state); }, INTERVAL);
|
2026-02-21 13:59:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-21 14:11:56 -05:00
|
|
|
|
function advance(slides, state) {
|
|
|
|
|
|
if (state.paused) return;
|
|
|
|
|
|
slides[state.current].classList.remove('is-active');
|
|
|
|
|
|
state.current = (state.current + 1) % slides.length;
|
|
|
|
|
|
slides[state.current].classList.add('is-active');
|
2026-02-21 13:59:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (document.readyState === 'loading') {
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', boot);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
boot();
|
|
|
|
|
|
}
|
|
|
|
|
|
})();
|