{"version":3,"file":"notice.js","names":[],"sources":["../resources/modern-javascript/notice.js"],"sourcesContent":["const transitionTimeoutDuration = 4000;\nlet windowResizing = null;\n\nconst setHeightProperty = () => {\n    const root = document.querySelector(':root');\n    root.style.setProperty('--notice-height', `${getNotice()?.clientHeight}px`);\n    root.style.setProperty('--notice-locale-height', `${getNoticeLocale()?.clientHeight || 0}px`);\n}\n\nconst getNotice = () => {\n    return document.querySelector('.notice');\n}\n\nconst getNoticeLocale = () => {\n    return document.querySelector('.notice-locale');\n}\n\nconst getHero = () => {\n    return document.querySelector('.hero');\n}\n\nconst activate = (item) => {\n    item.classList.add('notice__item--active');\n    item.removeAttribute('aria-hidden');\n    item.querySelector('a')?.removeAttribute('tabindex');\n    setHeightProperty();\n}\n\nconst deactivate = (item) => {\n    item.classList.remove('notice__item--active');\n    item.setAttribute('aria-hidden', true);\n    item.querySelector('a')?.setAttribute('tabindex', '-1');\n}\n\nconst animate = (items, oldId, newId) => {\n    deactivate(items[oldId]);\n    activate(items[newId]);\n\n    setTimeout(() => {\n        animate(items, newId, newId < items.length - 1 ? newId + 1 : 0);\n    }, transitionTimeoutDuration)\n}\n\nconst animateNotice = () => {\n    const notice = getNotice();\n    const items = notice.querySelectorAll('.notice__item');\n\n    setHeightProperty();\n\n    if (items.length > 1) {\n        items.forEach((item, i) => {\n            if (i > 0) {\n                deactivate(item);\n            }\n        });\n        setTimeout(() => {\n            animate(items, 0, 1);\n        }, transitionTimeoutDuration);\n    }\n}\n\nconst observe = () => {\n    const observer = new IntersectionObserver((entries, observer) => {\n        entries.forEach((entry) => {\n            if (entry.isIntersecting) {\n                getNotice().classList.remove('notice--solid');\n            } else {\n                getNotice().classList.add('notice--solid');\n            }\n        });\n    },{\n        rootMargin: '-56px 0px' // This should become a css variable related to header height\n    });\n\n    if (getHero()) {\n        observer.observe(getHero());\n    }\n\n    window.addEventListener('resize', () => {\n        if (windowResizing) {\n            cancelAnimationFrame(windowResizing);\n        }\n\n        windowResizing = requestAnimationFrame(() => {\n            windowResizing = null;\n            setHeightProperty();\n        });\n    });\n}\n\nif (document.readyState === 'loading') {\n    document.addEventListener('DOMContentLoaded', () => {\n        animateNotice();\n        observe();\n    });\n} else {\n    animateNotice();\n    observe();\n}\n"],"mappings":"AAAA,IAAM,EAA4B,IAC9B,EAAiB,KAEf,EAAA,UAA0B,CAAA,IACtB,EAAO,SAAS,cAAc,OAAO,EAC3C,EAAK,MAAM,YAAY,kBAAsB,EAAU,CAAC,EAAE,aAAA,IAAgB,EAC1E,EAAK,MAAM,YAAY,0BAA6B,EAAgB,CAAC,EAAE,cAAgB,GAAA,IAAK,CAChG,EAEM,EAAA,UAAkB,CACpB,OAAO,SAAS,cAAc,SAAS,CAC3C,EAEM,EAAA,UAAwB,CAC1B,OAAO,SAAS,cAAc,gBAAgB,CAClD,EAEM,EAAA,UAAgB,CAClB,OAAO,SAAS,cAAc,OAAO,CACzC,EAEM,EAAA,SAAY,EAAS,CAAA,IAAA,EACvB,EAAK,UAAU,IAAI,sBAAsB,EACzC,EAAK,gBAAgB,aAAa,GAClC,EAAA,EAAK,cAAc,GAAG,IAAC,MAAvB,EAAyB,gBAAgB,UAAU,EACnD,EAAkB,CACtB,EAEM,EAAA,SAAc,EAAS,CAAA,IAAA,EACzB,EAAK,UAAU,OAAO,sBAAsB,EAC5C,EAAK,aAAa,cAAe,EAAI,GACrC,EAAA,EAAK,cAAc,GAAG,IAAC,MAAvB,EAAyB,aAAa,WAAY,IAAI,CAC1D,EAEM,EAAA,SAAW,EAAO,EAAO,EAAU,CACrC,EAAW,EAAM,EAAM,EACvB,EAAS,EAAM,EAAM,EAErB,WAAA,UAAiB,CACb,EAAQ,EAAO,EAAO,EAAQ,EAAM,OAAS,EAAI,EAAQ,EAAI,CAAC,CAClE,EAAG,CAAyB,CAChC,EAEM,EAAA,UAAsB,CAExB,IAAM,EADS,EACI,CAAC,CAAC,iBAAiB,eAAe,EAErD,EAAkB,EAEd,EAAM,OAAS,IACf,EAAM,QAAA,S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