generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standalone GNav for Non-Milo Consumers (#2669)
* Adding configuration for header component * Adding test cases * Adding css changes * Updated for css * Setting the origin to federal * Removing promise array * Adding redirect uri in meta * Updating meta insert function * Lint fix * Making error message descriptive --------- Co-authored-by: Snehal Sonawane <sonawane@Snehals-MacBook-Pro.local>
- Loading branch information
1 parent
ccb9704
commit aea0827
Showing
5 changed files
with
122 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
/* Extracting the essential styles required for rendering the component independently */ | ||
.global-footer, .dialog-modal { | ||
.global-navigation, .global-footer, .dialog-modal { | ||
font-family: 'Adobe Clean', adobe-clean, 'Trebuchet MS', sans-serif; | ||
line-height: 27px; | ||
color: #2c2c2c; | ||
word-wrap: break-word; | ||
-webkit-font-smoothing: antialiased; | ||
} | ||
|
||
.global-footer a, .dialog-modal a { | ||
.global-navigation a, .global-footer a, .dialog-modal a { | ||
text-decoration: none; | ||
} | ||
|
||
.dialog-modal a { | ||
color: #035FE6; | ||
} | ||
|
||
.global-footer img { | ||
.global-navigation img, .global-footer img { | ||
max-width: 100%; | ||
height: auto; | ||
} | ||
|
||
.global-navigation { | ||
font-size: 18px; | ||
} | ||
|
||
header.global-navigation { | ||
height: 64px; | ||
visibility: hidden; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,73 @@ | ||
const blockConfig = { | ||
footer: { | ||
const blockConfig = [ | ||
{ | ||
key: 'header', | ||
name: 'global-navigation', | ||
targetEl: 'header', | ||
appendType: 'prepend', | ||
params: ['imsClientId'], | ||
}, | ||
{ | ||
key: 'footer', | ||
name: 'global-footer', | ||
targetEl: 'footer', | ||
appendType: 'appendChild', | ||
params: ['privacyId', 'privacyLoadDelay'], | ||
}, | ||
}; | ||
]; | ||
|
||
const envMap = { | ||
prod: 'https://www.adobe.com', | ||
stage: 'https://www.stage.adobe.com', | ||
qa: 'https://feds--milo--adobecom.hlx.page', | ||
qa: 'https://gnav--milo--adobecom.hlx.page', | ||
}; | ||
|
||
function getParamsConfigs(configs) { | ||
return blockConfig.reduce((acc, block) => { | ||
block.params.forEach((param) => { | ||
const value = configs[block.key]?.[param]; | ||
if (value !== undefined) { | ||
acc[param] = value; | ||
} | ||
}); | ||
return acc; | ||
}, {}); | ||
} | ||
|
||
export default async function loadBlock(configs, customLib) { | ||
const { footer, locale, env = 'prod' } = configs || {}; | ||
const { header, footer, authoringPath, env = 'prod', locale = '' } = configs || {}; | ||
const branch = new URLSearchParams(window.location.search).get('navbranch'); | ||
const miloLibs = branch ? `https://${branch}--milo--adobecom.hlx.page` : customLib || envMap[env]; | ||
|
||
if (!header && !footer) { | ||
console.error('Global navigation Error: header and footer configurations are missing.'); | ||
return; | ||
} | ||
// 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 [{ default: bootstrapBlock }, { default: locales }, { setConfig }] = await Promise.all([ | ||
import(`${miloLibs}/libs/navigation/bootstrapper.js`), | ||
import(`${miloLibs}/libs/utils/locales.js`), | ||
import(`${miloLibs}/libs/utils/utils.js`), | ||
]); | ||
|
||
const paramConfigs = getParamsConfigs(configs, miloLibs); | ||
const clientConfig = { | ||
origin: miloLibs, | ||
origin: `https://main--federal--adobecom.hlx.${env === 'prod' ? 'live' : 'page'}`, | ||
miloLibs: `${miloLibs}/libs`, | ||
pathname: `/${locale || ''}`, | ||
pathname: `/${locale}`, | ||
locales: configs.locales || locales, | ||
contentRoot: authoringPath || footer.authoringPath, | ||
...paramConfigs, | ||
}; | ||
if (footer) { | ||
const { authoringPath, privacyId, privacyLoadDelay = 3000 } = footer; | ||
blockConfig.delay = privacyLoadDelay; | ||
bootstrapBlock({ ...clientConfig, contentRoot: authoringPath, privacyId }, blockConfig.footer); | ||
} | ||
setConfig(clientConfig); | ||
|
||
blockConfig.forEach((block) => { | ||
const configBlock = configs[block.key]; | ||
if (configBlock) { | ||
bootstrapBlock(`${miloLibs}/libs`, { | ||
...block, | ||
...(block.key === 'header' && { unavComponents: configBlock.unavComponents, redirect: configBlock.redirect }), | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
window.loadNavigation = loadBlock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters