Skip to content
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

IBX-4012: [Sections] Recalculate last section padding on section height change #758

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/bundle/Resources/public/js/scripts/admin.anchor.navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
const headerContainer = header?.querySelector('.ibexa-edit-header__container');
const SECTION_ADJUST_MARGIN_TOP = 20;
const formContainerNode = doc.querySelector('.ibexa-edit-content');
const lastSectionObserver = new ResizeObserver(() => {
fitSections();
});
const getSectionGroupActiveItems = () => {
const sectionGroupNode = formContainerNode.querySelector('.ibexa-anchor-navigation__section-group') ?? formContainerNode;
const sections = sectionGroupNode.querySelectorAll('.ibexa-anchor-navigation__section');
Expand Down Expand Up @@ -68,7 +71,7 @@

currentlyVisibleSections = getSectionGroupActiveItems();

fitSections();
initFitSection();
};
const attachSectionsMenuEvents = () => {
const items = doc.querySelectorAll('.ibexa-anchor-navigation-menu .ibexa-anchor-navigation-menu__sections-item-btn');
Expand Down Expand Up @@ -96,7 +99,7 @@

return sections[sections.length - 1];
};
const fitSections = () => {
const initFitSection = () => {
const sectionGroup =
formContainerNode.querySelector('.ibexa-anchor-navigation__section-group--active') ??
formContainerNode.querySelector('.ibexa-anchor-navigation-sections');
Expand All @@ -105,16 +108,28 @@
return;
}

const contentColumn = doc.querySelector('.ibexa-main-container__content-column');
const firstSection = getFirstSection(sectionGroup);
const lastSection = getLastSection(sectionGroup);

if (!firstSection) {
if (!lastSection) {
return;
}

const contentContainer = lastSection.closest('.ibexa-edit-content__container');

fitSections();

lastSectionObserver.unobserve(contentContainer);
lastSectionObserver.observe(contentContainer);
};
const fitSections = () => {
const sectionGroup =
formContainerNode.querySelector('.ibexa-anchor-navigation__section-group--active') ??
formContainerNode.querySelector('.ibexa-anchor-navigation-sections');
const contentColumn = doc.querySelector('.ibexa-main-container__content-column');
const firstSection = getFirstSection(sectionGroup);
const lastSection = getLastSection(sectionGroup);
const contentContainer = lastSection.closest('.ibexa-edit-content__container');

if (!firstSection.isSameNode(lastSection) && lastSection.offsetHeight) {
const lastSectionHeight = lastSection.offsetHeight;
const headerHeight = headerContainer?.offsetHeight;
Expand Down Expand Up @@ -224,6 +239,6 @@
attachSectionsMenuEvents();
attachScrollContainerEvents();
attachListenForIsInvalidClass();
fitSections();
initFitSection();
ibexa.helpers.tooltips.parse(navigationMenu);
})(window, window.document, window.ibexa);