Skip to content

Commit

Permalink
disable mobile scroll always for feds popup
Browse files Browse the repository at this point in the history
  • Loading branch information
sharmrj committed Jan 13, 2025
1 parent 5755250 commit 9ed6994
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions libs/blocks/global-navigation/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,30 @@ export function closeAllDropdowns({ type } = {}) {
if (isDesktop.matches) setCurtainState(false);
}

export const disableMobileScroll = () => {
if (!PERSONALIZATION_TAGS.safari()) return;
document.body.style.top = `-${window.scrollY}px`;
document.body.classList.add('disable-ios-scroll');

Check warning on line 319 in libs/blocks/global-navigation/utilities/utilities.js

View check run for this annotation

Codecov / codecov/patch

libs/blocks/global-navigation/utilities/utilities.js#L318-L319

Added lines #L318 - L319 were not covered by tests
};

export const enableMobileScroll = () => {
if (!PERSONALIZATION_TAGS.safari()) return;
if (!document.body.style.top) return;
const y = Math.abs(parseInt(document.body.style.top, 10));
if (Number.isNaN(y)) return;
document.body.classList.remove('disable-ios-scroll');
document.body.style.removeProperty('top');

Check warning on line 328 in libs/blocks/global-navigation/utilities/utilities.js

View check run for this annotation

Codecov / codecov/patch

libs/blocks/global-navigation/utilities/utilities.js#L324-L328

Added lines #L324 - L328 were not covered by tests
window.scroll(0, y || 0, { behavior: 'instant' });
};

export function trigger({ element, event, type } = {}) {
if (event) event.preventDefault();
const isOpen = element?.getAttribute('aria-expanded') === 'true';
closeAllDropdowns({ type });
if (isOpen) return false;
if (isOpen) {
if (!isDesktop.matches) disableMobileScroll();
return false;
}
element.setAttribute('aria-expanded', 'true');
return true;
}
Expand Down Expand Up @@ -414,22 +433,6 @@ export const closeAllTabs = (tabs, tabpanels) => {
tabs.forEach((t) => t.setAttribute('aria-selected', 'false'));
};

export const disableMobileScroll = () => {
if (!PERSONALIZATION_TAGS.safari()) return;
document.body.style.top = `-${window.scrollY}px`;
document.body.classList.add('disable-ios-scroll');
};

export const enableMobileScroll = () => {
if (!PERSONALIZATION_TAGS.safari()) return;
if (!document.body.style.top) return;
const y = Math.abs(parseInt(document.body.style.top, 10));
if (Number.isNaN(y)) return;
document.body.classList.remove('disable-ios-scroll');
document.body.style.removeProperty('top');
window.scroll(0, y || 0, { behavior: 'instant' });
};

export const transformTemplateToMobile = async (popup, item, localnav = false) => {
const notMegaMenu = popup.parentElement.tagName === 'DIV';
const originalContent = popup.innerHTML;
Expand Down

0 comments on commit 9ed6994

Please sign in to comment.