Skip to content

Commit

Permalink
Merge pull request #56 from adobecom/MWPW-158182-google-yolo
Browse files Browse the repository at this point in the history
MWPW-158182 listen to milo events and activate google yolo
  • Loading branch information
vhargrave committed Sep 24, 2024
2 parents 51c1a74 + 7e52bc4 commit a505863
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 154 deletions.
6 changes: 3 additions & 3 deletions express/scripts/gnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ if (!window.hlx || window.hlx.gnav) {
await loadIMS();
loadFEDS();
setTimeout(() => {
import('./google-yolo.js').then((mod) => {
mod.default();
});
// import('./google-yolo.js').then((mod) => {
// mod.default();
// });
}, 4000);
}
/* Core Web Vitals RUM collection */
Expand Down
96 changes: 0 additions & 96 deletions express/scripts/google-yolo.js

This file was deleted.

22 changes: 13 additions & 9 deletions express/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
* governing permissions and limitations under the License.
*/

import { setLibs, buildAutoBlocks, decorateArea, removeIrrelevantSections } from './utils.js';
import {
setLibs,
buildAutoBlocks,
decorateArea,
removeIrrelevantSections,
getRedirectUri,
} from './utils.js';

// Add project-wide style path here.
const STYLES = ['/express/styles/styles.css'];

// Use 'https://milo.adobe.com/libs' if you cannot map '/libs' to milo's origin.
const LIBS = '/libs';

window.express = {};
const miloLibs = setLibs(LIBS);

// Add any config options.
const CONFIG = {
Expand Down Expand Up @@ -68,18 +73,15 @@ const CONFIG = {
'eb0dcb78-3e56-4b10-89f9-51831f2cc37f': 'express-pep',
},
links: 'on',
googleLoginURLCallback: getRedirectUri,
};

const urlParams = new URLSearchParams(window.location.search);

/*
* ------------------------------------------------------------
* Edit below at your own risk
* ------------------------------------------------------------
*/

const miloLibs = setLibs(LIBS);

document.body.dataset.device = navigator.userAgent.includes('Mobile') ? 'mobile' : 'desktop';
removeIrrelevantSections(document);
// LCP image decoration
Expand Down Expand Up @@ -186,6 +188,9 @@ function decorateHeroLCP(loadStyle, config, createTag, getMetadata) {

const footerSrc = createTag('meta', { name: 'footer-source', content: '/federal/footer/footer' });
document.head.append(footerSrc);

const googleLoginRedirect = createTag('meta', { name: 'google-login', content: 'desktop' });
document.head.append(googleLoginRedirect);
// end TODO remove metadata after we go live

const jarvisVisibleMeta = getMetadata('jarvis-immediately-visible')?.toLowerCase();
Expand Down Expand Up @@ -222,13 +227,12 @@ function decorateHeroLCP(loadStyle, config, createTag, getMetadata) {
const footerMeta = createTag('meta', { name: 'custom-footer', content: 'on' });
document.head.append(footerMeta);

// listenMiloEvents();
buildAutoBlocks();
decorateHeroLCP(loadStyle, config, createTag, getMetadata);
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('martech') !== 'off' && getMetadata('martech') !== 'off') {
import('./instrument.js').then((mod) => { mod.default(); });
}

const { default: replaceContent } = await import('./utils/content-replace.js');
await replaceContent(document.querySelector('main'));

Expand Down
53 changes: 7 additions & 46 deletions express/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/**
* The decision engine for where to get Milo's libs from.
*/
Expand All @@ -36,6 +35,7 @@ export const [setLibs, getLibs] = (() => {
* Note: This file should have no self-invoking functions.
* ------------------------------------------------------------
*/
export const expressObj = {};

const cachedMetadata = [];
const getMetadata = (name, doc = document) => {
Expand All @@ -48,6 +48,12 @@ export function getCachedMetadata(name) {
return cachedMetadata[name];
}

export async function getRedirectUri() {
const BlockMediator = await import('./block-mediator.min.js');
return BlockMediator.get('primaryCtaUrl')
|| document.querySelector('a.button.xlarge.same-fcta, a.primaryCTA')?.href;
}

export const yieldToMain = () => new Promise((resolve) => { setTimeout(resolve, 0); });

function createTag(tag, attributes, html, options = {}) {
Expand Down Expand Up @@ -268,51 +274,6 @@ export function lazyLoadLottiePlayer($block = null) {
}
}

// TODO we might be able to remove this before migrating
async function loadAEMGnav() {
const miloLibs = getLibs();
const { loadScript } = await import(`${miloLibs}/utils/utils.js`);
const header = document.querySelector('header');

if (header) {
header.addEventListener('click', (event) => {
if (event.target.id === 'feds-topnav') {
const root = window.location.href.split('/express/')[0];
window.location.href = `${root}/express/`;
}
});
header.innerHTML = '<div id="feds-header"></div>';
}
const footer = document.querySelector('footer');
if (footer) {
footer.innerHTML = `
<div id="feds-footer"></div>
`;
footer.setAttribute('data-status', 'loading');
}

const usp = new URLSearchParams(window.location.search);
const gnav = usp.get('gnav') || getMetadata('gnav');

const gnavUrl = '/express/scripts/gnav.js';
if (!(gnav === 'off' || document.querySelector(`head script[src="${gnavUrl}"]`))) {
loadScript(gnavUrl, 'module');
}
}

// TODO we might be able to remove this before migrating
export function listenMiloEvents() {
const lcpLoadedHandler = async () => {
await loadAEMGnav();
};
const postSectionLoadingHandler = async () => {
const footer = document.querySelector('footer');
delete footer.dataset.status;
};
window.addEventListener('milo:LCP:loaded', lcpLoadedHandler);
window.addEventListener('milo:postSection:loading', postSectionLoadingHandler);
}

function transpileMarquee(area) {
const handleSubCTAText = (oldContainer, newContainer) => {
const elAfterBtn = oldContainer.nextElementSibling;
Expand Down

0 comments on commit a505863

Please sign in to comment.