// Gallery video hover/loop behaviour for grid thumbnails and full-size players. document.addEventListener("DOMContentLoaded", () => { // Hover play for grid videos. const gridVideos = document.querySelectorAll(".grid-video"); gridVideos.forEach((video) => { let hoverTimeout: number | undefined; video.addEventListener("mouseenter", () => { hoverTimeout = window.setTimeout(() => { video.play().catch(() => { // Ignore play errors (e.g. user interaction required). }); }, 150); }); video.addEventListener("mouseleave", () => { window.clearTimeout(hoverTimeout); video.pause(); video.currentTime = 0; }); }); // Video loop logic for the full video player. const fullVideos = document.querySelectorAll(".full-video"); fullVideos.forEach((video) => { const shouldLoop = video.dataset.loop === "true"; const duration = parseFloat(video.dataset.duration || "0") || 0; if (shouldLoop) { video.loop = true; } video.addEventListener("ended", () => { if (!shouldLoop && duration >= 30) { // Video longer than 30s - don't loop, show controls. video.controls = true; } }); // Ensure the loop attribute matches the actual duration. video.addEventListener("loadedmetadata", () => { const actualDuration = video.duration; if (actualDuration < 30) { video.loop = true; } else { video.loop = false; } }); }); });