From 3ced32a62b85c6f481ceea1266edd573de290402 Mon Sep 17 00:00:00 2001 From: Bryan Stopp Date: Wed, 22 May 2024 11:16:21 -0400 Subject: [PATCH] Handle no-video link. (#233) --- blocks/hero/hero.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/blocks/hero/hero.js b/blocks/hero/hero.js index d2db95ec..7da31eb1 100644 --- a/blocks/hero/hero.js +++ b/blocks/hero/hero.js @@ -45,17 +45,15 @@ function rotateImage(images) { export default async function decorate(block) { // check if it has a video - const video = block.querySelector('a[href*=".mp4"]'); - const videoWrapper = video && video.closest('div'); - videoWrapper.classList.add('video-wrapper'); - const videoLink = videoWrapper?.firstElementChild; - // transform link into a video tag + const videoLink = block.querySelector('a[href*=".mp4"]'); + let videoWrapper; if (videoLink) { - const parent = videoLink.parentElement; + videoWrapper = document.createElement('div'); + videoWrapper.classList.add('video-wrapper'); const videoHref = videoLink.href; videoLink.remove(); setTimeout(() => { - decorateVideo(parent, videoHref); + decorateVideo(videoWrapper, videoHref); }, 3000); }