drupal-caravane/web/themes/custom/caravane/assets/js/utils/layout-setup.js

72 lines
2.7 KiB
JavaScript
Raw Normal View History

2024-10-18 18:44:03 +02:00
import { useLayoutStore } from '../stores/layout';
export function handleReactiveness() {
const layoutStore = useLayoutStore();
layoutStore.setupResizeListenner();
// toggle collapse and scroll for etape liste
(function setEtapeListe() {
2024-10-18 18:44:03 +02:00
const listeEtape = document.querySelector('#etapes-liste');
const listeToggleButton = document.querySelector('#retractable-message');
const column = document.querySelector('.layout__region--third');
const header = document.querySelector('.layout-container > header');
2024-10-18 18:44:03 +02:00
const animationToggle = document.querySelector('#animation-toggle');
const EtapeListeScrollElements = {
listeEtape,
column,
listeEtapeContent: listeEtape.querySelector('.item-list'),
header,
animationToggle: animationToggle.querySelector('.animation-toggle-container')
}
layoutStore.shouldEtapeListeScroll(EtapeListeScrollElements);
if (!layoutStore.isDesktop) layoutStore.collapseEtapeListe(listeEtape, animationToggle);
2024-10-18 18:44:03 +02:00
window.addEventListener('resize', () => {
layoutStore.shouldEtapeListeScroll(EtapeListeScrollElements);
2024-10-18 18:44:03 +02:00
if (layoutStore.isDesktop && layoutStore.isEtapeListRetracted) {
layoutStore.expandEtapeListe(listeEtape, animationToggle);
2024-10-18 18:44:03 +02:00
} else if (!layoutStore.isDesktop && !layoutStore.isEtapeListRetracted) {
layoutStore.collapseEtapeListe(listeEtape, animationToggle);
2024-10-18 18:44:03 +02:00
}
});
listeToggleButton.addEventListener('click', () => {
2024-10-18 18:44:03 +02:00
if (!layoutStore.isDesktop) {
if (!layoutStore.isEtapeListRetracted) {
layoutStore.collapseEtapeListe(listeEtape, animationToggle);
2024-10-18 18:44:03 +02:00
} else {
layoutStore.expandEtapeListe(listeEtape, animationToggle);
layoutStore.shouldEtapeListeScroll(EtapeListeScrollElements);
2024-10-18 18:44:03 +02:00
}
}
2024-10-18 18:44:03 +02:00
});
})();
}
export function setMenuToggle() {
2024-10-22 11:50:33 +02:00
const layoutStore = useLayoutStore();
const menuBurger = document.querySelector('#hamburger');
2024-10-22 11:50:33 +02:00
const menuContainer = document.querySelector('#block-caravane-mainnavigation > #menu > ul');
2024-10-22 11:50:33 +02:00
layoutStore.setUpHamburgerToggle(menuBurger, menuContainer);
}
export function setHamburgerWhenLogged(drupalSettings) {
if (drupalSettings.user.uid != 0) {
const menuBurger = document.querySelector('#hamburger');
const menuTitle = document.querySelector('#menu-title');
const menuContainer = document.querySelector('#block-caravane-mainnavigation > #menu > ul');
const header = document.querySelector('.dialog-off-canvas-main-canvas');
const headerTop = header.getBoundingClientRect().top;
menuTitle.style.top = `${headerTop}px`;
menuBurger.style.top = `${headerTop}px`;
menuContainer.style.paddingTop = `${headerTop}px`;
}
}