1(function (window, document) { 2 'use strict'; 3 4 var itemSelector = '.brxe-section, .brxe-container, .brxe-block, .brxe-div, .accordion-item'; 5 var styleId = 'gutenbricks-accordion-frontend-compat'; 6 7 function getAccordionItems(accordion) { 8 var wrappers = Array.prototype.filter.call( 9 accordion.children, 10 function (child) { 11 return child.classList && child.classList.contains('brxe-gb-inner-blocks'); 12 } 13 ); 14 15 return wrappers.reduce(function (items, wrapper) { 16 return items.concat( 17 Array.prototype.filter.call(wrapper.children, function (item) { 18 return item.matches && item.matches(itemSelector); 19 }) 20 ); 21 }, []); 22 } 23 24 function getDuration(accordion) { 25 if (!accordion.hasAttribute('data-transition')) return 200; 26 var value = Number(accordion.getAttribute('data-transition')); 27 return Number.isNaN(value) ? 0 : value; 28 } 29 30 function setExpanded(title, expanded) { 31 title.setAttribute('aria-expanded', expanded ? 'true' : 'false'); 32 if (expanded) { 33 title.setAttribute('aria-label', (window.bricksData && window.bricksData.i18n && window.bricksData.i18n.closeAccordion) || 'Close accordion'); 34 } else { 35 title.setAttribute('aria-label', (window.bricksData && window.bricksData.i18n && window.bricksData.i18n.openAccordion) || 'Open accordion'); 36 } 37 } 38 39 function slideUp(accordion, item, target, duration) { 40 target.style.display = 'block'; 41 target.style.transitionProperty = 'height, margin, padding'; 42 target.style.transitionDuration = duration + 'ms'; 43 target.style.height = target.offsetHeight + 'px'; 44 target.offsetHeight; 45 target.style.overflow = 'hidden'; 46 target.style.height = '0'; 47 target.style.paddingTop = '0'; 48 target.style.paddingBottom = '0'; 49 target.style.marginTop = '0'; 50 target.style.marginBottom = '0'; 51 item.classList.remove('brx-open'); 52 53 window.setTimeout(function () { 54 target.style.display = 'none'; 55 target.style.removeProperty('height'); 56 target.style.removeProperty('padding-top'); 57 target.style.removeProperty('padding-bottom'); 58 target.style.removeProperty('margin-top'); 59 target.style.removeProperty('margin-bottom'); 60 target.style.removeProperty('overflow'); 61 target.style.removeProperty('transition-duration'); 62 target.style.removeProperty('transition-property'); 63 document.dispatchEvent(new CustomEvent('bricks/accordion/close', { 64 detail: { elementId: accordion.getAttribute('data-script-id'), closeItem: item } 65 })); 66 }, duration); 67 } 68 69 function slideDown(accordion, item, target, duration) { 70 target.style.removeProperty('display'); 71 var display = window.getComputedStyle(target).display; 72 if (display === 'none') display = 'block'; 73 target.style.display = display; 74 var height = target.offsetHeight; 75 target.style.overflow = 'hidden'; 76 target.style.height = '0'; 77 target.style.paddingTop = '0'; 78 target.style.paddingBottom = '0'; 79 target.style.marginTop = '0'; 80 target.style.marginBottom = '0'; 81 target.offsetHeight; 82 target.style.transitionProperty = 'height, margin, padding'; 83 target.style.transitionDuration = duration + 'ms'; 84 target.style.height = height + 'px'; 85 target.style.removeProperty('padding-top'); 86 target.style.removeProperty('padding-bottom'); 87 target.style.removeProperty('margin-top'); 88 target.style.removeProperty('margin-bottom'); 89 item.classList.add('brx-open'); 90 91 window.setTimeout(function () { 92 target.style.removeProperty('height'); 93 target.style.removeProperty('overflow'); 94 target.style.removeProperty('transition-duration'); 95 target.style.removeProperty('transition-property'); 96 document.dispatchEvent(new CustomEvent('bricks/accordion/open', { 97 detail: { elementId: accordion.getAttribute('data-script-id'), openItem: item } 98 })); 99 }, duration); 100 } 101 102 function addCompatibilityStyles() { 103 if (document.getElementById(styleId)) return; 104 var style = document.createElement('style'); 105 style.id = styleId; 106 style.textContent = [ 107 '.brxe-accordion-nested > .brxe-gb-inner-blocks > .brx-open > .accordion-title-wrapper .brx-icon-transform { transform: var(--brx-icon-transform); }', 108 '.brxe-accordion-nested > .brxe-gb-inner-blocks > .brx-open > .accordion-title-wrapper .brx-icon-collapsed { display: none; }', 109 '.brxe-accordion-nested > .brxe-gb-inner-blocks > .brx-open > .accordion-title-wrapper .brx-icon-expanded { display: block; }' 110 ].join('\n'); 111 (document.head || document.documentElement).appendChild(style); 112 } 113 114 function initAccordion(accordion) { 115 var items = getAccordionItems(accordion); 116 if (!items.length) return; 117 addCompatibilityStyles(); 118 119 var duration = getDuration(accordion); 120 var independentToggle = (accordion.getAttribute('data-script-args') || '').indexOf('independentToggle') !== -1; 121
122 items.forEach(function (item) { 123 if (item.getAttribute('data-gutenbricks-accordion-listening') === 'true') return; 124 var title = item.querySelector('.accordion-title-wrapper'); 125 var content = item.querySelector('.accordion-content-wrapper'); 126 if (!title || !content) return; 127 128 item.setAttribute('data-gutenbricks-accordion-listening', 'true'); 129 if (item.classList.contains('brx-open')) setExpanded(title, true); 130 131 item.addEventListener('click', function (event) { 132 if (event.target && event.target.closest && event.target.closest('.bricks-active-selector-detector')) return; 133 var clickedTitle = event.target && event.target.closest ? event.target.closest('.accordion-title-wrapper') : null; 134 if (!clickedTitle || !item.contains(clickedTitle)) return; 135 event.stopPropagation(); 136 137 if (!independentToggle) { 138 items.forEach(function (openItem) { 139 if (openItem === item || !openItem.classList.contains('brx-open')) return; 140 var openContent = openItem.querySelector('.accordion-content-wrapper'); 141 var openTitle = openItem.querySelector('.accordion-title-wrapper'); 142 if (openContent) slideUp(accordion, openItem, openContent, duration); 143 if (openTitle) setExpanded(openTitle, false); 144 }); 145 } 146 147 var opening = !item.classList.contains('brx-open'); 148 try { 149 window.history.replaceState(null, null, opening ? ('#' + item.id) : ' '); 150 } catch (error) { 151 // History is optional, and some embedded previews use an opaque URL. 152 } 153 if (window.getComputedStyle(content).display === 'none') { 154 slideDown(accordion, item, content, duration); 155 } else { 156 slideUp(accordion, item, content, duration); 157 } 158 setExpanded(clickedTitle, opening); 159 }); 160 161 if (title.getAttribute('role') === 'button') { 162 title.addEventListener('keydown', function (event) { 163 if (event.key !== 'Enter' && event.key !== ' ') return; 164 event.preventDefault(); 165 title.click(); 166 }); 167 } 168 }); 169 } 170 171 function init() { 172 var accordions = document.querySelectorAll('.brxe-accordion-nested'); 173 Array.prototype.forEach.call(accordions, initAccordion); 174 } 175 176 window.GutenBricksAccordionCompatibility = { init: init }; 177 if (document.readyState === 'loading') { 178 document.addEventListener('DOMContentLoaded', init); 179 } else { 180 init(); 181 } 182 window.addEventListener('load', init); 183 document.addEventListener('bricks/ajax/nodes_added', init); 184})(window, document);
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.