From 8df386c952f8c854ed3cbab5c82e019f5d5bd2c9 Mon Sep 17 00:00:00 2001 From: Okan Sahin <39759830+mokimo@users.noreply.github.com> Date: Tue, 3 Sep 2024 20:09:17 +0200 Subject: [PATCH] Fix video CLS netting +10 lighthouse points (#2750) * 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 * Add default hash at in the right spot * Fix the figure/video interaction * Remove unused export statement * Keep the previous defaults --- libs/blocks/adobetv/adobetv.js | 35 +++++------------- libs/blocks/figure/figure.js | 35 +++++++++--------- libs/blocks/video/video.js | 40 ++++++--------------- libs/utils/decorate.js | 28 +++++++++++---- 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 +++++++++++------------------ 9 files changed, 97 insertions(+), 133 deletions(-) diff --git a/libs/blocks/adobetv/adobetv.js b/libs/blocks/adobetv/adobetv.js index 31cfc7a368..7635da82e3 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({ + src: a.href, + anchorTag: a, + hash: a.hash || 'autoplay', + }); } else { const embed = `