PageSourceSearch

https://cmief.ca/wp-content/plugins/proactive-blocks/build/block-accordion/frontend.js

js cmief.ca collected 2026-10-04 02:40:25 UTC 5,514 bytes, 137 lines download raw bytes

1/******/ (function() { // webpackBootstrap
2var __webpack_exports__ = {};
3/*!*****************************************!*\
4  !*** ./src/block-accordion/frontend.js ***!
5  \*****************************************/
6let isAnimating = false;
7const accordionItems = document.querySelectorAll('.wp-block-proactive-accordion-item');
8accordionItems.forEach(entry => {
9  const header = entry.querySelector('.wp-block-proactive-accordion-item__header');
10  if (header) {
11    header.addEventListener('click', function () {
12      const content = entry.querySelector('.wp-block-proactive-accordion-item__content');
13      const expanded = entry.getAttribute('aria-expanded') === 'true';
14      if (content) {
15        if (expanded) {
16          closeAccordionItem(this, content);
17        } else {
18          openAccordionItem(this, content);
19        }
20      }
21    });
22  }
23});
24const accordion = document.querySelector('.wp-block-proactive-accordion');
25if (accordion) {
26  accordion.addEventListener('keydown', function (event) {
27    const header = event.target.querySelector('.wp-block-proactive-accordion-item__header');
28    const content = header ? header.nextElementSibling : null;
29    if (accordion.contains(document.activeElement)) {
30      if (event.key === 'ArrowDown' && header && header.nextElementSibling) {
31        event.preventDefault();
32        header.nextElementSibling.focus();
33      } else if (event.key === 'ArrowUp' && header && header.previousElementSibling) {
34        event.preventDefault();
35        header.previousElementSibling.focus();
36      } else if (event.key === 'Enter' && header) {
37        event.preventDefault();
38        const expanded = event.getAttribute('aria-expanded') === 'true';
39        if (expanded) {
40          closeAccordionItem(header, content);
41        } else {
42          openAccordionItem(header, content);
43        }
44      }
45    }
46  });
47}
48function closeAccordionItem(header, content) {
49  isAnimating = true;
50  content.style.height = content.scrollHeight + 'px';
51  setTimeout(function () {
52    content.style.height = 0;
53  }, 50);
54
55  // Get content style transition duration
56  const style = window.getComputedStyle(content);
57  const duration = parseFloat(style.transitionDuration) * 1000;
58  header.parentNode.setAttribute('aria-expanded', 'false');
59  setTimeout(function () {
60    content.setAttribute('hidden', '');
61    isAnimating = false;
62  }, duration);
63}
64function openAccordionItem(header, content) {
65  if (isAnimating) return;
66  const accordion = document.querySelector('.wp-block-proactive-accordion');
67  const toggle = accordion.getAttribute('data-toggle');
68  if (toggle === 'true') {
69    closeOtherAccordionItems(header);
70  }
71  const iframe = content.querySelector('iframe');
72  if (iframe) {
73    window.addEventListener('message', function (event) {
74      if (iframe.contentWindow === event.source) {
75        // if has scrollbar
76        if (iframe.scrollHeight < event.data || iframe.scrollHeight > event.data) {
77          content.style.height = `${event.data + 20}px`;
78        }
79      }
80    });
81  }
82  const style = window.getComputedStyle(content);
83  const duration = parseFloat(style.transitionDuration) * 1000;
84  content.removeAttribute('hidden');
85  content.style.height = content.scrollHeight + 'px';
86  header.parentNode.setAttribute('aria-expanded', 'true');
87  setTimeout(function () {
88    content.style.height = 'auto';
89  }, duration);
90}
91function closeOtherAccordionItems(clickedHeader) {
92  const accordion = document.querySelector('.wp-block-proactive-accordion');
93  const headers = accordion.querySelectorAll('.wp-block-proactive-accordion-item__header');
94  headers.forEach(function (header) {
95    if (header !== clickedHeader) {
96      const content = header.nextElementSibling;
97      closeAccordionItem(header, content);
98    }
99  });
100}
101
102// On window resize
103window.addEventListener('resize', function () {
104  const accordionItems = document.querySelectorAll('.wp-block-proactive-accordion');
105  accordionItems.forEach(entry => {
106    const content = entry.querySelector('.wp-block-proactive-accordion-item__content');
107    const inner = content.querySelector('.wp-block-proactive-accordion-item__content-inner');
108    if (entry.getAttribute('aria-expanded') === 'true') {
109      content.style.height = inner.clientHeight + 'px';
110    }
111  });
112});
113document.addEventListener('DOMContentLoaded', function () {
114  // Set first accordion item to open if data-open is true
115  const accordion = document.querySelector('.wp-block-proactive-accordion-item');
116  if (accordion) {
117    const firstItem = accordion.parentNode.dataset.first;
118    const firstHeader = accordion.querySelector('.wp-block-proactive-accordion-item__header');
119    const firstContent = accordion.querySelector('.wp-block-proactive-accordion-item__content');
120
121    // Check anchor link to see if it matches an accordion item
122    const hash = window.location.hash ? window.location.hash : false;
123    const anchorItem = document.querySelector(`${hash}`) ? document.querySelector(`${hash}`) : false;
124    if (anchorItem && hash !== false) {
125      const anchorHeader = anchorItem.querySelector('.wp-block-proactive-accordion-item__header');
126      const anchorContent = anchorItem.querySelector('.wp-block-proactive-accordion-item__content');
127      if (anchorHeader && anchorContent) {
128        openAccordionItem(anchorHeader, anchorContent);
129      }
130    } else if (firstItem == 'true' && firstHeader && firstContent) {
131      openAccordionItem(firstHeader, firstContent);
132    }
133  }
134});
135/******/ })()
136;
137//# 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.