diff --git a/blocks/v2-inpage-navigation/v2-inpage-navigation.css b/blocks/v2-inpage-navigation/v2-inpage-navigation.css deleted file mode 100644 index 7198253c7..000000000 --- a/blocks/v2-inpage-navigation/v2-inpage-navigation.css +++ /dev/null @@ -1,107 +0,0 @@ -.v2-inpage-navigation { -} - -.v2-inpage-navigation__wrapper { - display: flex; - box-shadow: 0px 4px 24px 0px rgba(0, 0, 0, 0.16); - height: 48px; -} - -.v2-inpage-navigation__dropdown { - flex-grow: 1; - position: relative; -} - -.v2-inpage-navigation__dropdown--open .v2-inpage-navigation__items { - display: block; -} - -.v2-inpage-navigation__items { - display: none; - list-style: none; - margin: 0; - padding: 0; - position: absolute; - top: 48px; - left: 0; - width: 100%; - background-color: var(--c-primary-white); - box-shadow: 0px 4px 24px 0px rgba(0, 0, 0, 0.16); - - /* display: flex; - flex-direction: column; */ -} -.v2-inpage-navigation__item button, -.v2-inpage-navigation__selected-item { - display: block; - margin: 0; - padding: 14px 24px; - background: none; - color: var(--c-primary-black); - font-family: var(--ff-body-bold); - font-size: var(--body-2-font-size); - line-height: var(--body-2-line-height); - cursor: pointer; -} - -.v2-inpage-navigation__item button:active, -.v2-inpage-navigation__selected-item:active { - background-color: #F1F1F1; -} - -.v2-inpage-navigation__item button { - max-width: none; - width: 100%; - text-align: left; -} - -.v2-inpage-navigation__selected-item { - display: flex; - justify-content: space-between; - align-items: center; -} - -.v2-inpage-navigation__selected-item::after { - content: ''; - width: 16px; - height: 16px; - background-color: red; -} - -/* Buttons */ -.v2-inpage-navigation__cta:any-link { - display: flex; - padding: 0 20px; - align-items: center; - font-family: var(--ff-body); - font-size: 14px; - font-style: normal; - font-weight: 500; - line-height: 18px; - letter-spacing: 1.12px; - background-color: var(--button-primary-red-enabled); - color: var(--c-primary-white); -} - -.v2-inpage-navigation__cta:hover, -.v2-inpage-navigation__cta:focus { - background-color: var(--button-primary-red-hover); -} - -.v2-inpage-navigation__cta:active { - background-color: var(--button-primary-red-pressed); -} - -.v2-inpage-navigation__cta--desktop { - display: none; -} - -@media (min-width: 1200px) { - .v2-inpage-navigation__cta--mobile { - display: none; - } - - .v2-inpage-navigation__cta--desktop { - display: block; - } -} diff --git a/blocks/v2-inpage-navigation/v2-inpage-navigation.js b/blocks/v2-inpage-navigation/v2-inpage-navigation.js deleted file mode 100644 index d40238805..000000000 --- a/blocks/v2-inpage-navigation/v2-inpage-navigation.js +++ /dev/null @@ -1,147 +0,0 @@ -import { - getMetadata, -} from '../../scripts/lib-franklin.js'; -import { - createElement, -} from '../../scripts/scripts.js'; - -const blockName = 'v2-inpage-navigation'; - -const getInpageNavigationButtons = () => { - // if we have a button title & button link - if (getMetadata('inpage-button') && getMetadata('inpage-link')) { - const titleMobile = getMetadata('inpage-button'); - const url = getMetadata('inpage-link'); - const link = createElement('a', `${blockName}__cta`, { - href: url, - title: titleMobile, - }); - const mobileText = createElement('span', `${blockName}__cta--mobile`); - mobileText.textContent = titleMobile; - link.appendChild(mobileText); - - const titleDesktop = getMetadata('inpage-button-large'); - if (titleDesktop) { - const desktopText = createElement('span', `${blockName}__cta--desktop`); - desktopText.textContent = titleDesktop; - link.setAttribute('title', titleDesktop); - link.appendChild(desktopText); - } - - return link; - } - - return []; -}; - -const gotoSection = (event) => { - // let waitingTime = 500; - const { target } = event; - const button = target.closest('button'); - - if (button) { - const { id } = button.dataset; - - const container = document.querySelector(`main .section[data-inpageid='${id}']`); - container?.scrollIntoView({ behavior: 'smooth' }); - - // // create an Observer instance - // const resizeObserver = new ResizeObserver((entries) => { - // console.log('Body height changed:', entries[0].target.clientHeight); - // }); - - // // start observing a DOM node - // resizeObserver.observe(document.body); - } -}; - -const updateActive = (id) => { - console.log('updateActive', id); - - const currentItem = document.querySelector(`.${blockName}__selected-item`); - const listItems = document.querySelector(`.${blockName}__item--active`); - listItems.classList.remove(`${blockName}__item--active`); - const itemsButton = document.querySelectorAll(`.${blockName}__items button`); - // console.log(itemsButton); - - const selectedButton = [...itemsButton].filter((button) => button.dataset.id === id); - if (!selectedButton[0]) return; - currentItem.textContent = selectedButton[0].textContent; - selectedButton[0].parentNode.classList.add(`${blockName}__item--active`); -}; - -const toggleList = (e) => { - console.log(e.target); - const dropdownWrapper = document.querySelector(`.${blockName}__dropdown`); - - if (e.target.classList.contains(`${blockName}__selected-item`)) { - dropdownWrapper.classList.toggle(`${blockName}__dropdown--open`); - } else { - dropdownWrapper.classList.remove(`${blockName}__dropdown--open`); - } -}; - -const listenScroll = () => { - const main = document.querySelector('main'); - const elements = document.querySelectorAll('main .section[data-inpageid]'); - - console.log(main, elements); - - const io = new IntersectionObserver((entries) => { - entries.forEach((entry) => { - if (entry.isIntersecting) { - // entry.target.classList.add('active'); - console.log(entry.intersectionRatio, entry.target.dataset.inpageid, entry.target); - updateActive(entry.target.dataset.inpageid); - } - }); - }, { - // root: main, - threshold: [0.2, 0.5, 0.7, 1], - }); - - elements.forEach((el) => { - io.observe(el); - }); -}; - -export default async function decorate(block) { - const buttons = getInpageNavigationButtons(); - - const wrapper = block.querySelector(':scope > div'); - wrapper.classList.add(`${blockName}__wrapper`); - const itemsWrapper = block.querySelector(':scope > div > div'); - - const dropdownWrapper = createElement('div', `${blockName}__dropdown`); - const activeItem = createElement('div', `${blockName}__selected-item`); - - const list = createElement('ul', `${blockName}__items`); - - [...itemsWrapper.children].forEach((item, index) => { - const classes = [`${blockName}__item`]; - if (index === 0) { - classes.push(`${blockName}__item--active`); - activeItem.textContent = item.textContent; - } - const listItem = createElement('li', classes); - - listItem.innerHTML = item.innerHTML; - list.appendChild(listItem); - }); - - dropdownWrapper.append(activeItem); - dropdownWrapper.append(list); - wrapper.append(dropdownWrapper); - - itemsWrapper.remove(); - - wrapper.appendChild(buttons); - - list.addEventListener('click', gotoSection); - - // Listener to toggle the dropdown or close it - document.addEventListener('click', toggleList); - - // listen scroll to change the url - listenScroll(); -}