Skip to content

Commit

Permalink
Fixing dot media issue in locale
Browse files Browse the repository at this point in the history
  • Loading branch information
aishwaryamathuria committed May 30, 2024
1 parent ad6fa19 commit 09d4487
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions creativecloud/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ function getDecorateAreaFn() {
lcpImg?.setAttribute('fetchpriority', 'high');
if (lcpImg) lcpImgSet = true;
};

function replaceDotMedia(area = document) {
function isRootPage() {
const currUrl = new URL(window.location);
const pathSeg = currUrl.pathname.split('/').length;
if (pathSeg >= 3) return;
const locale = getConfig().locale?.prefix;
return (locale === '' && pathSeg < 3) || (locale !== '' && pathSeg < 4);
}

function replaceDotMedia(area = document) {
const resetAttributeBase = (tag, attr) => {
area.querySelectorAll(`${tag}[${attr}^="./media_"]`).forEach((el) => {
el[attr] = `${new URL(`${getConfig().contentRoot}${el.getAttribute(attr).substring(1)}`, window.location).href}`;
Expand Down Expand Up @@ -101,7 +105,7 @@ function getDecorateAreaFn() {
}

return (area, options) => {
replaceDotMedia();
if (isRootPage()) replaceDotMedia();
if (!lcpImgSet) loadLCPImage(area, options);
};
}
Expand Down

0 comments on commit 09d4487

Please sign in to comment.