Newer
Older
pre-www / src / assets / js / blocks / featured-tabs.js
window.addEventListener('load', (event) => {
    
    const featuredTabs = document.querySelectorAll('.block-featured-tabs')
  
    function checkFeaturedTabsHeight(tabs, container, activeTabContent){
        const contentHeight = parseInt(tabs.clientHeight + activeTabContent.clientHeight)
        console.log(contentHeight, container.clientHeight )
        if (contentHeight > parseInt(container.clientHeight)) {
            container.style.height = `${tabs.clientHeight + activeTabContent.clientHeight}px`
        } else if (contentHeight < parseInt(container.clientHeight)) {
            container.style.height = 'auto'
        }
    }
    
    featuredTabs.forEach(featuredTab => {
        const tabs = featuredTab.querySelector('.block-featured-tabs__tabs')
        const container = featuredTab.querySelector('[data-tabs-container]')  
        const activeTab = featuredTab.querySelector('.block-featured-tabs-tab.is-active')  
        const activeTabContent = activeTab.querySelector('.block-featured-tabs-tab__content')  
        checkFeaturedTabsHeight(tabs, container, activeTabContent)

        window.addEventListener('resize', function(){
            checkFeaturedTabsHeight(tabs, container, activeTabContent)
        } )
    })
})