Skip to content

Commit

Permalink
[Sections] Recalculate last section padding on section height change
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabowskiM committed Apr 19, 2023
1 parent 26d822f commit f56a65a
Showing 1 changed file with 21 additions and 6 deletions.
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);

0 comments on commit f56a65a

Please sign in to comment.