Skip to content

Commit

Permalink
Adding support for privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
bandana147 committed Jul 23, 2024
1 parent f2491b8 commit 9a8d592
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 9 additions & 2 deletions libs/navigation/bootstrapper.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
export default async function bootstrapBlock(miloConfigs, blockConfig) {
const { miloLibs } = miloConfigs;
const { name, targetEl } = blockConfig;
const { setConfig, createTag, loadLink } = await import(`${miloLibs}/utils/utils.js`);
const { getConfig, setConfig, createTag, loadLink, loadScript } = await import(`${miloLibs}/utils/utils.js`);
setConfig({ ...miloConfigs });
const { default: initBlock } = await import(`${miloLibs}/blocks/${name}/${name}.js`);

const styles = [`${miloLibs}/blocks/${name}/${name}.css`, `${miloLibs}/navigation/navigation.css`];
styles.forEach((url) => loadLink(url, { rel: 'stylesheet' }));
const { default: initBlock } = await import(`${miloLibs}/blocks/${name}/${name}.js`);

if (!document.querySelector(targetEl)) {
const block = createTag(targetEl, { class: name });
document.body[blockConfig.appendType](block);
}
initBlock(document.querySelector(targetEl));
if (blockConfig.targetEl === 'footer') {
const { loadPrivacy } = await import(`${miloLibs}/scripts/delayed.js`);
setTimeout(() => {
loadPrivacy(getConfig, loadScript);
}, blockConfig.delay);
}
}
7 changes: 4 additions & 3 deletions libs/navigation/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ const envMap = {
};

export default async function loadBlock(configs = {}) {
const { locale, contentRoot, env = 'prod' } = configs;
const { locale, authoringPath, env = 'prod', privacyId, privacyLoadDelay = 3000 } = configs;
const branch = new URLSearchParams(window.location.search).get('navbranch');
const miloLibs = branch ? `https://${branch}--milo--adobecom.hlx.page` : envMap[env];

// Relative path can't be used, as the script will run on consumer's app
const { default: bootstrapBlock } = await import(`${miloLibs}/libs/navigation/bootstrapper.js`);
const { default: locales } = await import(`${miloLibs}/libs/utils/locales.js`);
const clientConfig = {
contentRoot,
privacyId,
contentRoot: authoringPath,
origin: miloLibs,
miloLibs: `${miloLibs}/libs`,
pathname: `/${locale || ''}`,
locales: configs.locales || locales,
};

blockConfig.delay = privacyLoadDelay;
bootstrapBlock(clientConfig, blockConfig);
}

0 comments on commit 9a8d592

Please sign in to comment.