1/******/ (function() { // webpackBootstrap 2var __webpack_exports__ = {}; 3/*!************************************!*\ 4 !*** ./src/block-tabs/frontend.js ***! 5 \************************************/ 6var _window$location$hash; 7// Get all instances of proactiveTabsBlocks 8const proactiveTabsBlocks = document.querySelectorAll('.wp-block-proactive-tabs'); 9const hashURL = (_window$location$hash = window.location.hash) !== null && _window$location$hash !== void 0 ? _window$location$hash : false; 10 11// OPEN TAB FUNCTIONS ON DESKTOP 12 13const openTab = e => { 14 // Check if the clicked element is a tab button 15 if (!e.target.matches('.wp-block-proactive-tabs__tabs-list__tab button')) { 16 return; 17 } 18 const tab = e.target.closest('.wp-block-proactive-tabs__tabs-list__tab'); 19 const allTabs = [...tab.parentNode.querySelectorAll('.wp-block-proactive-tabs__tabs-list__tab')]; 20 const tabIndex = allTabs.indexOf(tab); 21 22 // Get the parent container of the tabs and contents 23 const container = tab.closest('.wp-block-proactive-tabs'); 24 const allContents = [...container.querySelectorAll('.wp-block-proactive-tab')]; 25 allTabs.forEach((tab, index) => { 26 if (index === tabIndex) { 27 tab.classList.add('active'); 28 allContents[index].style.display = 'block'; 29 setTimeout(() => { 30 allContents[index].classList.add('active'); 31 }, 10); 32 } else { 33 tab.classList.remove('active'); 34 allContents[index].style.display = 'none'; 35 allContents[index].classList.remove('active'); 36 } 37 }); 38}; 39 40// OPEN ACCORDION MENU IF ENABLED ON MOBILE 41 42const openAccordion = (e, toggle, initial) => { 43 // Check if the clicked element is a tab button 44 if (!e.target.matches('.proactive-tab__mobile')) { 45 return; 46 } 47 const tab = e.target; 48 const content = tab.nextElementSibling; 49 if (toggle) { 50 // Get the parent container of the tabs and contents 51 const container = tab.closest('.wp-block-proactive-tabs'); 52 const allTabs = container.querySelectorAll('.proactive-tab__mobile'); 53 allTabs.forEach(otherTab => { 54 if (otherTab !== tab) { 55 const otherContent = otherTab.nextElementSibling; 56 otherTab.setAttribute('aria-expanded', 'false'); 57 otherContent.classList.remove('active'); 58 otherContent.style.display = 'none'; 59 } 60 }); 61 } 62 if (tab.getAttribute('aria-expanded') === 'true') { 63 tab.setAttribute('aria-expanded', 'false'); 64 content.style.display = 'none'; 65 content.classList.remove('active'); 66 } else { 67 tab.setAttribute('aria-expanded', 'true'); 68 content.style.display = 'block'; 69 content.classList.add('active'); 70 } 71 if (!initial) { 72 // Scroll to the active tab 73 const offset = tab.getBoundingClientRect().top + window.scrollY - 120; 74 window.scrollTo({ 75 top: offset, 76 behavior: 'smooth' 77 }); 78 } 79}; 80 81// LOOP THROUGH ALL BLOCKS AND SET THE ACTIVE TAB 82 83proactiveTabsBlocks.forEach(block => { 84 // Check block settings 85 const mobileAccordion = block.dataset.accordions === 'true'; 86 const firstOpen = block.dataset.first === 'true'; 87 const toggle = block.dataset.toggle === 'true'; 88 let activeTab = firstOpen ? 0 : block.dataset.activeTab - 1; 89 90 // Check if the hash is set and if it matches the current block 91 if (hashURL && block.querySelector(hashURL)) { 92 const tab = block.querySelector(hashURL); 93 const tabs = block.querySelectorAll('.wp-block-proactive-tab'); 94 const index = [...tabs].indexOf(tab); 95 activeTab = index; 96 } 97 if (window.innerWidth < 782 && mobileAccordion) { 98 // Set the Open Accordion 99 openAccordion({ 100 target: block.querySelectorAll('.proactive-tab__mobile')[activeTab] 101 }, toggle, true); 102 block.addEventListener('click', e => openAccordion(e, toggle, false)); 103 } else { 104 // Set the Open Tab 105 openTab({ 106 target: block.querySelectorAll('.wp-block-proactive-tabs__tabs-list__tab button')[activeTab] 107 }); 108 block.addEventListener('click', openTab); 109 } 110 111 // Resize 112 window.addEventListener('resize', () => { 113 if (window.innerWidth < 782 && mobileAccordion) { 114 block.addEventListener('click', e => openAccordion(e, toggle, false)); 115 } else { 116 block.addEventListener('click', openTab); 117 } 118 }); 119}); 120/******/ })() 121; 122//# sourceMappingURL=frontend.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.