Skip to content

Commit

Permalink
Merge branch 'stage' into timelinerollout
Browse files Browse the repository at this point in the history
  • Loading branch information
markpadbe committed Sep 18, 2024
2 parents 3500537 + 9323f28 commit 799d652
Show file tree
Hide file tree
Showing 27 changed files with 175 additions and 197 deletions.
34 changes: 7 additions & 27 deletions libs/blocks/adobetv/adobetv.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import { createIntersectionObserver } from '../../utils/utils.js';
import { applyHoverPlay, getVideoAttrs } from '../../utils/decorate.js';
import { decorateAnchorVideo } 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 = `<video ${attrs}>
<source src="${href}" type="video/mp4" />
</video>`;
if (!a.parentNode) return;
a.insertAdjacentHTML('afterend', video);
const videoElem = document.body.querySelector(`source[src="${href}"]`)?.parentElement;
applyHoverPlay(videoElem);
a.remove();
decorateAnchorVideo({
src: a.href,
anchorTag: a,
});
} else {
const embed = `<div class="milo-video">
<iframe src="${a.href}" class="adobetv" webkitallowfullscreen mozallowfullscreen allowfullscreen scrolling="no" allow="encrypted-media" title="Adobe Video Publishing Cloud Player" loading="lazy">
Expand All @@ -25,17 +18,4 @@ const loadAdobeTv = (a) => {
a.insertAdjacentHTML('afterend', embed);
a.remove();
}
};

export default function init(a) {
a.classList.add('hide-video');
if (a.textContent.includes('no-lazy')) {
loadAdobeTv(a);
} else {
createIntersectionObserver({
el: a,
options: { rootMargin: `${ROOT_MARGIN}px` },
callback: loadAdobeTv,
});
}
}
2 changes: 1 addition & 1 deletion libs/blocks/caas-config/caas-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ const PaginationPanel = () => {
options=${defaultOptions.paginationType}
/>
<${Select}
label="Animation Style"
label="Carousel Animation Style"
prop="paginationAnimationStyle"
options=${defaultOptions.paginationAnimationStyle}
/>
Expand Down
36 changes: 18 additions & 18 deletions libs/blocks/figure/figure.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { applyHoverPlay, getVideoAttrs } from '../../utils/decorate.js';
import { applyHoverPlay, decorateAnchorVideo } from '../../utils/decorate.js';
import { createTag } from '../../utils/utils.js';

function buildCaption(pEl) {
const figCaptionEl = document.createElement('figcaption');
Expand All @@ -15,23 +16,22 @@ function htmlToElement(html) {
}

function decorateVideo(clone, figEl) {
let video = clone.querySelector('video');
const videoLink = clone.querySelector('a[href*=".mp4"]');
if (videoLink) {
const { href, hash, dataset } = videoLink;
const attrs = getVideoAttrs(hash, dataset);
const videoElem = `<video ${attrs}>
<source src="${href}" type="video/mp4" />
</video>`;

videoLink.insertAdjacentHTML('afterend', videoElem);
videoLink.remove();
video = clone.querySelector('video');
}
if (video) {
video.removeAttribute('data-mouseevent');
applyHoverPlay(video);
figEl.prepend(video);
const videoTag = clone.querySelector('video');
const anchorTag = clone.querySelector('a[href*=".mp4"]');
if (anchorTag && !anchorTag.hash) anchorTag.hash = '#autoplay';
if (anchorTag) decorateAnchorVideo({ src: anchorTag.href, anchorTag });
if (videoTag) {
videoTag.removeAttribute('data-mouseevent');
if (videoTag.dataset?.videoSource) {
videoTag.appendChild(
createTag('source', {
src: videoTag.dataset?.videoSource,
type: 'video/mp4',
}),
);
}
applyHoverPlay(videoTag);
figEl.prepend(videoTag);
}
}

Expand Down
9 changes: 3 additions & 6 deletions libs/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class Gnav {
return 'linux';
};

const unavVersion = new URLSearchParams(window.location.search).get('unavVersion') || '1.1';
const unavVersion = new URLSearchParams(window.location.search).get('unavVersion') || '1.3';
await Promise.all([
loadScript(`https://${environment}.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js`),
loadStyles(`https://${environment}.adobeccstatic.com/unav/${unavVersion}/UniversalNav.css`),
Expand Down Expand Up @@ -608,9 +608,6 @@ class Gnav {
locale,
imsClientId: window.adobeid?.client_id,
theme: isDarkMode() ? 'dark' : 'light',
onReady: () => {
this.decorateAppPrompt({ getAnchorState: () => window.UniversalNav.getComponent?.('app-switcher') });
},
analyticsContext: {
consumer: {
name: 'adobecom',
Expand All @@ -627,8 +624,8 @@ class Gnav {

// Exposing UNAV config for consumers
CONFIG.universalNav.universalNavConfig = getConfiguration();
window.UniversalNav(CONFIG.universalNav.universalNavConfig);

await window.UniversalNav(CONFIG.universalNav.universalNavConfig);
this.decorateAppPrompt({ getAnchorState: () => window.UniversalNav.getComponent?.('app-switcher') });
isDesktop.addEventListener('change', () => {
window.UniversalNav.reload(CONFIG.universalNav.universalNavConfig);
});
Expand Down
1 change: 1 addition & 0 deletions libs/blocks/hero-marquee/hero-marquee.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
align-items: center;
}

.hero-marquee.no-min-height { min-height: unset; }
.hero-marquee.s-min-height { min-height: var(--s-min-height); }
.hero-marquee.l-min-height { min-height: var(--l-min-height); }

Expand Down
10 changes: 6 additions & 4 deletions libs/blocks/hero-marquee/hero-marquee.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,16 @@ function loadBreakpointThemes() {
export default async function init(el) {
el.classList.add('con-block');
let rows = el.querySelectorAll(':scope > div');
if (rows.length > 1 && rows[0].textContent !== '') {
if (rows.length <= 1) return;
const [head, ...tail] = rows;
rows = tail;
if (head.textContent.trim() === '') {
head.remove();
} else {
el.classList.add('has-bg');
const [head, ...tail] = rows;
handleObjectFit(head);
decorateBlockBg(el, head, { useHandleFocalpoint: true });
rows = tail;
}

// get first row that's not a keyword key/value row
const mainRowIndex = rows.findIndex((row) => {
const firstColText = row.children[0].textContent.toLowerCase().trim();
Expand Down
43 changes: 13 additions & 30 deletions libs/blocks/video/video.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { createIntersectionObserver, getConfig } from '../../utils/utils.js';
import { applyHoverPlay, getVideoAttrs, applyInViewPortPlay } from '../../utils/decorate.js';
import { getConfig } from '../../utils/utils.js';
import { decorateAnchorVideo } from '../../utils/decorate.js';

const ROOT_MARGIN = 1000;

const loadVideo = (a) => {
const { pathname, hash, dataset } = a;
export default function init(a) {
a.classList.add('hide-video');
if (!a.parentNode) {
a.remove();
return;
}
const { pathname } = a;
let videoPath = `.${pathname}`;
if (pathname.match('media_.*.mp4')) {
const { codeRoot } = getConfig();
Expand All @@ -14,28 +17,8 @@ const loadVideo = (a) => {
const mediaFilename = pathname.split('/').pop();
videoPath = `${root}${mediaFilename}`;
}

const attrs = getVideoAttrs(hash, dataset);
const video = `<video ${attrs}>
<source src="${videoPath}" type="video/mp4" />
</video>`;
if (!a.parentNode) return;
a.insertAdjacentHTML('afterend', video);
const videoElem = document.body.querySelector(`source[src="${videoPath}"]`)?.parentElement;
applyHoverPlay(videoElem);
applyInViewPortPlay(videoElem);
a.remove();
};

export default function init(a) {
a.classList.add('hide-video');
if (a.textContent.includes('no-lazy')) {
loadVideo(a);
} else {
createIntersectionObserver({
el: a,
options: { rootMargin: `${ROOT_MARGIN}px` },
callback: loadVideo,
});
}
decorateAnchorVideo({
src: videoPath,
anchorTag: a,
});
}
40 changes: 19 additions & 21 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-console */

import {
createTag, getConfig, loadLink, loadScript, localizeLink, updateConfig,
} from '../../utils/utils.js';
import { createTag, getConfig, loadLink, loadScript, localizeLink } from '../../utils/utils.js';
import { getEntitlementMap } from './entitlements.js';

/* c8 ignore start */
Expand Down Expand Up @@ -359,6 +357,7 @@ function modifySelectorTerm(termParam) {
'primary-cta': 'strong a',
'secondary-cta': 'em a',
'action-area': '*:has(> em a, > strong a)',
'any-marquee-section': 'main > div:has([class*="marquee"])',
'any-marquee': '[class*="marquee"]',
'any-header': ':is(h1, h2, h3, h4, h5, h6)',
};
Expand All @@ -372,7 +371,7 @@ function modifySelectorTerm(termParam) {
const startText = startTextMatch ? startTextMatch[0].toLowerCase() : '';
const startTextPart1 = startText.split(/\.|:/)[0];
const endNumberMatch = term.match(/[0-9]*$/);
const endNumber = endNumberMatch ? endNumberMatch[0] : '';
const endNumber = endNumberMatch && startText.match(/^[a-zA-Z]/) ? endNumberMatch[0] : '';
if (!startText || htmlEls.includes(startText)) return term;
if (otherSelectors.includes(startText)) {
term = term.replace(startText, '> div');
Expand Down Expand Up @@ -791,28 +790,13 @@ export async function getManifestConfig(info, variantOverride = false) {
}

manifestConfig.manifestPath = normalizePath(manifestPath);
const selectedVariantName = await getPersonalizationVariant(
manifestConfig.selectedVariantName = await getPersonalizationVariant(
manifestConfig.manifestPath,
manifestConfig.variantNames,
variantLabel,
);

if (selectedVariantName && manifestConfig.variantNames.includes(selectedVariantName)) {
manifestConfig.run = true;
manifestConfig.selectedVariantName = selectedVariantName;
manifestConfig.selectedVariant = manifestConfig.variants[selectedVariantName];
} else {
/* c8 ignore next 2 */
manifestConfig.selectedVariantName = 'default';
manifestConfig.selectedVariant = 'default';
}
const placeholders = manifestPlaceholders || data?.placeholders?.data;
if (placeholders) {
updateConfig(
parsePlaceholders(placeholders, getConfig(), manifestConfig.selectedVariantName),
);
}

manifestConfig.placeholderData = manifestPlaceholders || data?.placeholders?.data;
manifestConfig.name = name;
manifestConfig.manifest = manifestPath;
manifestConfig.manifestUrl = manifestUrl;
Expand Down Expand Up @@ -900,6 +884,20 @@ export function cleanAndSortManifestList(manifests) {
} else {
manifestObj[manifest.manifestPath] = manifest;
}

const manifestConfig = manifestObj[manifest.manifestPath];
const { selectedVariantName, variantNames, placeholderData } = manifestConfig;
if (selectedVariantName && variantNames.includes(selectedVariantName)) {
manifestConfig.run = true;
manifestConfig.selectedVariantName = selectedVariantName;
manifestConfig.selectedVariant = manifestConfig.variants[selectedVariantName];
} else {
/* c8 ignore next 2 */
manifestConfig.selectedVariantName = 'default';
manifestConfig.selectedVariant = 'default';
}

parsePlaceholders(placeholderData, getConfig(), manifestConfig.selectedVariantName);
} catch (e) {
console.warn(e);
window.lana?.log(`MEP Error parsing manifests: ${e.toString()}`);
Expand Down
29 changes: 23 additions & 6 deletions libs/utils/decorate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createTag } from './utils.js';
import { createTag, createIntersectionObserver } from './utils.js';

export function decorateButtons(el, size) {
const buttons = el.querySelectorAll('em a, strong a, p > a strong');
Expand Down Expand Up @@ -113,8 +113,6 @@ export async function decorateBlockBg(block, node, { useHandleFocalpoint = false
const allVP = [['mobile-only'], ['tablet-only'], ['desktop-only']];
const viewports = childCount === 2 ? binaryVP : allVP;
[...node.children].forEach((child, i) => {
const videoLink = child.querySelector('a[href*=".mp4"]');
if (videoLink && !videoLink.hash) videoLink.hash = 'autoplay';
if (childCount > 1) child.classList.add(...viewports[i]);
const pic = child.querySelector('picture');
if (useHandleFocalpoint && pic
Expand Down Expand Up @@ -200,7 +198,7 @@ export function getImgSrc(pic) {
return source?.srcset ? `poster='${source.srcset}'` : '';
}

export function getVideoAttrs(hash, dataset) {
function getVideoAttrs(hash, dataset) {
const isAutoplay = hash?.includes('autoplay');
const isAutoplayOnce = hash?.includes('autoplay1');
const playOnHover = hash?.includes('hoverplay');
Expand Down Expand Up @@ -258,7 +256,7 @@ export function handleObjectFit(bgRow) {
});
}

export function getVideoIntersectionObserver() {
function getVideoIntersectionObserver() {
if (!window?.videoIntersectionObs) {
window.videoIntersectionObs = new window.IntersectionObserver((entries) => {
entries.forEach((entry) => {
Expand All @@ -279,7 +277,7 @@ export function getVideoIntersectionObserver() {
return window.videoIntersectionObs;
}

export function applyInViewPortPlay(video) {
function applyInViewPortPlay(video) {
if (!video) return;
if (video.hasAttribute('data-play-viewport')) {
const observer = getVideoIntersectionObserver();
Expand Down Expand Up @@ -309,3 +307,22 @@ export function decorateMultiViewport(el) {
}
return foreground;
}

export function decorateAnchorVideo({ src, anchorTag }) {
if (!src.length || !(anchorTag instanceof HTMLElement)) return;
if (anchorTag.closest('.marquee, .aside, .hero-marquee') && !anchorTag.hash) anchorTag.hash = '#autoplay';
const { dataset, parentElement } = anchorTag;
const video = `<video ${getVideoAttrs(anchorTag.hash, dataset)} data-video-source=${src}></video>`;
anchorTag.insertAdjacentHTML('afterend', video);
const videoEl = parentElement.querySelector('video');
createIntersectionObserver({
el: parentElement,
options: { rootMargin: '1000px' },
callback: () => {
videoEl?.appendChild(createTag('source', { src, type: 'video/mp4' }));
},
});
applyHoverPlay(videoEl);
applyInViewPortPlay(videoEl);
anchorTag.remove();
}
11 changes: 0 additions & 11 deletions test/blocks/adobetv/adobetv.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ document.body.innerHTML = await readFile({ path: './mocks/body.html' });
const { default: init } = await import('../../../libs/blocks/adobetv/adobetv.js');

describe('adobetv autoblock', () => {
it('decorates no-lazy video', async () => {
const block = document.querySelector('.video.no-lazy');
const a = block.querySelector('a');
a.textContent = 'no-lazy';
block.append(a);

init(a);
const video = await waitForElement('.video.no-lazy iframe');
expect(video).to.exist;
});

it('creates video block', async () => {
const wrapper = document.body.querySelector('.adobe-tv');
const a = wrapper.querySelector(':scope > a');
Expand Down
2 changes: 1 addition & 1 deletion test/blocks/adobetv/mocks/body.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<main>
<div class="video no-lazy">
<div class="video">
<a href="https://video.tv.adobe.com/v/3410934t1">
https://video.tv.adobe.com/v/3410934t1
</a>
Expand Down
5 changes: 3 additions & 2 deletions test/blocks/figure/figure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ describe('init', () => {
init(blockEl);

const figures = blockEl.querySelectorAll('.figure');
expect(figures[0].querySelector('a > picture')).to.be.exist;
expect(figures[1].querySelector('a > video')).to.be.exist;
expect(figures[0].querySelector('a > picture')).to.exist;
expect(figures[1].querySelector('a > video')).to.exist;
expect(figures[1].querySelector('a > video > source')).to.exist;
});

it('should not add any classes to the block element when no pictures are present', () => {
Expand Down
Loading

0 comments on commit 799d652

Please sign in to comment.