From e9fa6999fba638b4ff1847a063655a5687d6d88a Mon Sep 17 00:00:00 2001 From: Okan Sahin <39759830+mokimo@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:46:43 +0200 Subject: [PATCH] MWPW-155412: Fix video CLS netting +10 lighthouse points (#2724) * fix cls by adding the videoEl without a source * adapt the video hover and in view port play * Remove no-lazy and return earlier * Fix linting issue * Consolidate duplicated logic * Move functions into the init function * Move root margin and use optional chaining * Only query for the videoEl once --- libs/blocks/adobetv/adobetv.js | 35 +++++------------- libs/blocks/video/video.js | 41 ++++++--------------- libs/utils/decorate.js | 24 +++++++++++-- test/blocks/adobetv/adobetv.test.js | 11 ------ test/blocks/adobetv/mocks/body.html | 2 +- test/blocks/marquee/marquee.test.js | 21 ++++++++--- test/blocks/video/mocks/body.html | 2 +- test/blocks/video/video.test.js | 56 +++++++++++------------------ 8 files changed, 80 insertions(+), 112 deletions(-) diff --git a/libs/blocks/adobetv/adobetv.js b/libs/blocks/adobetv/adobetv.js index 31cfc7a368..5a13b37cfd 100644 --- a/libs/blocks/adobetv/adobetv.js +++ b/libs/blocks/adobetv/adobetv.js @@ -1,22 +1,16 @@ -import { createIntersectionObserver } from '../../utils/utils.js'; -import { applyHoverPlay, getVideoAttrs } from '../../utils/decorate.js'; +import { turnAnchorIntoVideo } from '../../utils/decorate.js'; -const ROOT_MARGIN = 1000; - -const loadAdobeTv = (a) => { +export default function init(a) { + a.classList.add('hide-video'); const bgBlocks = ['aside', 'marquee', 'hero-marquee']; if (a.href.includes('.mp4') && bgBlocks.some((b) => a.closest(`.${b}`))) { a.classList.add('hide'); - const { href, hash, dataset } = a; - const attrs = getVideoAttrs(hash || 'autoplay', dataset); - const video = ``; if (!a.parentNode) return; - a.insertAdjacentHTML('afterend', video); - const videoElem = document.body.querySelector(`source[src="${href}"]`)?.parentElement; - applyHoverPlay(videoElem); - a.remove(); + turnAnchorIntoVideo({ + hash: a.hash || 'autoplay', + src: a.href, + anchorTag: a, + }); } else { const embed = `