Skip to content

Commit

Permalink
Moving getGnanSource to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
bandana147 committed Nov 25, 2024
1 parent 2dfaafd commit bf3917b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
13 changes: 2 additions & 11 deletions libs/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
loadIms,
decorateLinks,
loadScript,
getGnavSource,
} from '../../utils/utils.js';
import {
closeAllDropdowns,
Expand Down Expand Up @@ -1174,19 +1175,9 @@ class Gnav {
};
}

const getSource = async () => {
const { locale, dynamicNavKey } = getConfig();
let url = getMetadata('gnav-source') || `${locale.contentRoot}/gnav`;
if (dynamicNavKey) {
const { default: dynamicNav } = await import('../../features/dynamic-navigation/dynamic-navigation.js');
url = dynamicNav(url, dynamicNavKey);
}
return url;
};

export default async function init(block) {
const { mep } = getConfig();
const sourceUrl = await getSource();
const sourceUrl = await getGnavSource();
const newMobileNav = getMetadata('mobile-gnav-v2') !== 'false';
const [url, hash = ''] = sourceUrl.split('#');
if (hash === '_noActiveItem') {
Expand Down
15 changes: 12 additions & 3 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,16 @@ function decorateDefaults(el) {
});
}

export async function getGnavSource() {
const { locale, dynamicNavKey } = getConfig();
let url = getMetadata('gnav-source') || `${locale.contentRoot}/gnav`;
if (dynamicNavKey) {
const { default: dynamicNav } = await import('../features/dynamic-navigation/dynamic-navigation.js');
url = dynamicNav(url, dynamicNavKey);
}
return url;
};

function decorateHeader() {
const breadcrumbs = document.querySelector('.breadcrumbs');
breadcrumbs?.remove();
Expand All @@ -772,9 +782,8 @@ function decorateHeader() {
const dynamicNavActive = getMetadata('dynamic-nav') === 'on'
&& window.sessionStorage.getItem('gnavSource') !== null;
if (!dynamicNavActive && (baseBreadcrumbs || breadcrumbs || autoBreadcrumbs)) header.classList.add('has-breadcrumbs');
const gnavSource = getMetadata('gnav-source');
const gnavUrl = gnavSource.split('/');
const gnavName = gnavUrl[gnavUrl.length - 1];
const gnavSource = getGnavSource();
const gnavName = gnavSource.split('/').pop();

if (gnavName.match('localnav') && getMetadata('mobile-gnav-v2') !== 'false') {
// Preserving space to avoid CLS issue
Expand Down

0 comments on commit bf3917b

Please sign in to comment.