generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 212
[MWPW-182991] Project Lingo: Language Banner #5269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sonawanesnehal3
wants to merge
44
commits into
stage
Choose a base branch
from
language-banner
base: stage
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+669
−36
Open
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
a5e3916
setInternational cookie for languages-selector as per news config and…
1d9d7f0
Updating for apac cookievalue for cases like news site
abe14c7
Language banner flow for BACOM
5680da5
Language banner flow for BACOM
4b145a7
add lang banner
nishantka d22e47c
Changes for fetching markets from DA BACOM and early loading of json
4bed2c9
Updated for config and to fetch css
ec56318
update akamai locale func
nishantka b07521d
lang banner UI updates
nishantka b031f1e
add min height
nishantka 1c1162d
Revert language-selector to stage version
db684de
Revert script.js to stage version
c9376dd
fix alignment
7b2c504
add analytics + ui udates
nishantka e2140f4
remove analytics testing changes
nishantka 33967c1
Adding unit tests and fix for setting us cookie
913ee7f
Adding unit tests and fix for setting us cookie
890cc3f
Code improvements and cleanup
9312ed0
lang banner fix cls
nishantka 79fbdc5
hide other promos when lang banner is shown
nishantka fae722a
test by adding as preload links
nishantka 8bcb5f3
dont show banner only if pref market not present
nishantka b1a59f0
Language banner load (#5264)
sonawanesnehal3 501fed7
Merge branch 'stage' into language-banner
nishantka dba6d12
add opt in for preload market json
nishantka d91fe2d
Updating for params and ut
9b0b00c
Updated for config
72823e6
Fix for es-lint error
c90d56c
Adding getMarketsUrl
2deaf7d
resolving conflicts
141d119
fix UT and analytics
nishantka 8878d03
Accommodating review comments
aa34b0c
fix padding
nishantka ee0cb86
fix focus ring
nishantka cb7be11
Adding fix for marketssource metadata
0b249ce
updating banner logic
nishantka 43d9705
remove unused variable from lang banner unit test
nishantka 7852f00
update gnav position based on lang banner
nishantka 29601ce
Updated for refactoring and addAndShow markets
06fecb3
update css for lang banner
nishantka 2434c94
update gnav position based on lang banner
nishantka e9d31c4
Load lang banner head calls together + lana logging + gnav mweb fixes
nishantka 2235aaa
Merge branch 'stage' into language-banner
nishantka 80c95f5
Adding lana logs for lingoProjectSuccessLogging
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| .language-banner { | ||
| display: flex; | ||
| padding: 12px 20px; | ||
| justify-content: center; | ||
| align-items: center; | ||
| min-height: var(--feds-language-banner-height); | ||
| gap: 8px; | ||
| align-self: stretch; | ||
| width: 100%; | ||
| background-color: #3B63FB; | ||
| box-sizing: border-box; | ||
| visibility: visible; | ||
| position: relative; | ||
| z-index: 11; | ||
| } | ||
|
|
||
| .language-banner-content { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: flex-start; | ||
| gap: 4px; | ||
| flex: 1 0 0; | ||
| } | ||
|
|
||
| .language-banner-text { | ||
| color: #FFF; | ||
| font-family: var(--body-font-family); | ||
| font-size: 12px; | ||
| font-style: normal; | ||
| font-weight: 400; | ||
| line-height: 18px; | ||
| } | ||
|
|
||
| .language-banner-link { | ||
| color: #FFF; | ||
| font-family: var(--body-font-family); | ||
| font-size: 12px; | ||
| font-style: normal; | ||
| font-weight: 700; | ||
| line-height: 18px; | ||
| text-decoration: underline; | ||
| text-decoration-skip-ink: none; | ||
| text-underline-position: from-font; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .language-banner-link:hover { | ||
| color: #FFF; | ||
| } | ||
|
|
||
| .language-banner-close { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| width: 20px; | ||
| height: 20px; | ||
| border: none; | ||
| cursor: pointer; | ||
| padding: 0; | ||
| background-color: transparent; | ||
| } | ||
|
|
||
| @media (min-width: 600px) { | ||
| .language-banner { | ||
| gap: 6px; | ||
| } | ||
|
|
||
| .language-banner-content { | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .language-banner-close { | ||
| position: absolute; | ||
| right: 24px; | ||
| top: 50%; | ||
| transform: translateY(-50%); | ||
| flex-direction: column; | ||
| width: auto; | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* eslint-disable no-underscore-dangle */ | ||
| import { getConfig, createTag, loadStyle, getTargetMarket } from '../../utils/utils.js'; | ||
|
|
||
| function buildBanner(market, translatedUrl) { | ||
| const banner = document.body.querySelector('.language-banner'); | ||
| if (!banner) return banner; | ||
| const messageContainer = createTag('div', { class: 'language-banner-content' }); | ||
| const messageText = createTag('span', { class: 'language-banner-text' }, `${market.text} ${market.languageName}.`); | ||
| const link = createTag('a', { class: 'language-banner-link', href: translatedUrl, 'daa-ll': `${market.prefix || 'us'}|Continue` }, market.continueText || 'Continue'); | ||
| const closeButton = createTag('button', { class: 'language-banner-close', 'aria-label': 'Close', 'daa-ll': 'Close' }); | ||
| closeButton.innerHTML = ` | ||
| <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none"> | ||
| <path d="M10 0.5C15.2467 0.5 19.5 4.75329 19.5 10C19.5 15.2467 15.2467 19.5 10 19.5C4.75329 19.5 0.5 15.2467 0.5 10C0.5 4.75329 4.75329 0.5 10 0.5Z" stroke="white"/> | ||
| <path d="M6 14.0002L14 6.00024" stroke="white" stroke-width="2"/> | ||
| <path d="M14 14.0002L6 6.00024" stroke="white" stroke-width="2"/> | ||
| </svg> | ||
| `; | ||
|
|
||
| messageContainer.append(messageText, link); | ||
| banner.append(messageContainer, closeButton); | ||
| return banner; | ||
| } | ||
|
|
||
| function fireAnalyticsEvent(event) { | ||
| const data = { | ||
| xdm: {}, | ||
| data: { web: { webInteraction: { name: event?.type } } }, | ||
| }; | ||
| if (event?.data) data.data._adobe_corpnew = { digitalData: event.data }; | ||
| window._satellite?.track('event', data); | ||
| } | ||
|
|
||
| export function sendAnalytics(event) { | ||
| if (window._satellite?.track) { | ||
| fireAnalyticsEvent(event); | ||
| } else { | ||
| window.addEventListener('alloy_sendEvent', () => { | ||
| fireAnalyticsEvent(event); | ||
| }, { once: true }); | ||
| } | ||
| } | ||
|
|
||
| async function showBanner(market, config) { | ||
| if (!market) return; | ||
|
|
||
| const { pathname } = window.location; | ||
| const currentPrefix = config.locale.prefix; | ||
| const pagePath = currentPrefix ? pathname.replace(currentPrefix, '') : pathname; | ||
| const translatedUrl = market.prefix | ||
| ? `${window.location.origin}/${market.prefix}${pagePath}` | ||
| : `${window.location.origin}${pagePath}`; | ||
|
|
||
| const banner = buildBanner(market, translatedUrl); | ||
| if (!banner) return; | ||
| const { codeRoot, miloLibs } = config; | ||
| loadStyle(`${miloLibs || codeRoot}/features/language-banner/language-banner.css`); | ||
|
|
||
| const pagePrefix = config.locale.prefix?.replace('/', '') || 'us'; | ||
| // eventName = "suggestedSite-currentSite|language-banner" | ||
| const eventName = `${market.prefix || 'us'}-${pagePrefix}|language-banner`; | ||
|
|
||
| banner.querySelector('.language-banner-link').addEventListener('click', async (e) => { | ||
| e.preventDefault(); | ||
| const { setInternational } = await import('../../utils/utils.js'); | ||
| setInternational(market.prefix || 'us'); | ||
| if (config.lingoProjectSuccessLogging === 'on') { | ||
| window.lana.log(`Click: ${eventName}`, { sampleRate: 100, tags: 'lingo, lingo-language-banner-click' }); | ||
| } | ||
| window.open(translatedUrl, '_self'); | ||
| }); | ||
|
|
||
| banner.querySelector('.language-banner-close').addEventListener('click', () => { | ||
| const domain = window.location.host.endsWith('.adobe.com') ? 'domain=adobe.com;' : ''; | ||
| document.cookie = `international=${pagePrefix};path=/;${domain}`; | ||
| if (config.lingoProjectSuccessLogging === 'on') { | ||
| window.lana.log(`Close: ${eventName}`, { sampleRate: 100, tags: 'lingo, lingo-language-banner-close' }); | ||
| } | ||
| banner.remove(); | ||
| }); | ||
|
|
||
| sendAnalytics(new Event(eventName)); | ||
| if (config.lingoProjectSuccessLogging === 'on') { | ||
| window.lana.log(`Load: ${eventName}`, { sampleRate: 100, tags: 'lingo, lingo-language-banner-load' }); | ||
| } | ||
| } | ||
|
|
||
| export default async function init() { | ||
| const market = getTargetMarket(); | ||
| if (market) { | ||
| await showBanner(market, getConfig()); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { getCountry } from './utils.js'; | ||
| /* eslint-disable no-console */ | ||
|
|
||
| /** | ||
| * Gets the Akamai country code from the geo2.adobe.com service. | ||
| * @param {boolean} [checkParams=false] - If true, checks URL parameters and session storage first. | ||
| * @returns {Promise<string|null>} A promise that resolves to the lowercase Akamai country code. | ||
| */ | ||
| export const getAkamaiCode = (checkedParams = false) => new Promise((resolve, reject) => { | ||
| let akamaiLocale = null; | ||
| if (!checkedParams) { | ||
| akamaiLocale = getCountry(); | ||
| } | ||
| if (akamaiLocale !== null) { | ||
| resolve(akamaiLocale.toLowerCase()); | ||
| } else { | ||
| /* c8 ignore next 5 */ | ||
| fetch('https://geo2.adobe.com/json/', { cache: 'no-cache' }).then((resp) => { | ||
| if (resp.ok) { | ||
| resp.json().then((data) => { | ||
| const code = data.country.toLowerCase(); | ||
| sessionStorage.setItem('akamai', code); | ||
| resolve(code); | ||
| }); | ||
| } else { | ||
| reject(new Error(`Something went wrong getting the akamai Code. Response status text: ${resp.statusText}`)); | ||
| } | ||
| }).catch((error) => { | ||
| reject(new Error(`Something went wrong getting the akamai Code. ${error.message}`)); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| export default getAkamaiCode; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.