36 lines
1004 B
JavaScript
36 lines
1004 B
JavaScript
import { runAfterInitialLoad } from "../shared/schedule-idle.js";
|
|
|
|
function ensureVideoSource(video) {
|
|
const url = video.dataset.src;
|
|
if (!url) return Promise.resolve();
|
|
if (video.src) return Promise.resolve();
|
|
|
|
return new Promise((resolve) => {
|
|
const done = () => resolve();
|
|
video.addEventListener("loadeddata", done, { once: true });
|
|
video.addEventListener("error", done, { once: true });
|
|
video.src = url;
|
|
video.load();
|
|
});
|
|
}
|
|
|
|
export function initHeroMotionVideo() {
|
|
const shell = document.querySelector(".hero__portrait-shell");
|
|
const video = shell?.querySelector("[data-hero-motion-video]");
|
|
if (!shell || !(video instanceof HTMLVideoElement)) return;
|
|
|
|
function showAndPlay() {
|
|
shell.classList.add("hero__portrait-shell--motion-visible");
|
|
video
|
|
.play()
|
|
.then(() => {})
|
|
.catch(() => {});
|
|
}
|
|
|
|
runAfterInitialLoad(() => {
|
|
ensureVideoSource(video).then(() => {
|
|
showAndPlay();
|
|
});
|
|
});
|
|
}
|