Skip to content

Commit

Permalink
Handle no-video link. (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
bstopp authored May 22, 2024
1 parent 0d4d91c commit 3ced32a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions blocks/hero/hero.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 3ced32a

Please sign in to comment.