PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.13
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.13
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / toggle / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.13, at blocks/toggle/frontend.js

67 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 function toArray(nl) {
3 return Array.prototype.slice.call(nl || []);
4 }
5
6 function initToggle(wrap) {
7 var trigger = wrap.querySelector('.bkbg-tgl-trigger');
8 var content = wrap.querySelector('.bkbg-tgl-content');
9 if (!trigger || !content) return;
10
11 var speed = parseInt(wrap.getAttribute('data-speed'), 10) || 280;
12
13 // Set initial max-height for open state
14 if (wrap.classList.contains('is-open')) {
15 content.style.maxHeight = content.scrollHeight + 'px';
16 }
17
18 trigger.addEventListener('click', function () {
19 var isOpen = wrap.classList.contains('is-open');
20
21 if (isOpen) {
22 // Closing: set explicit height first, then animate to 0
23 content.style.maxHeight = content.scrollHeight + 'px';
24 requestAnimationFrame(function () {
25 requestAnimationFrame(function () {
26 content.style.maxHeight = '0';
27 wrap.classList.remove('is-open');
28 trigger.setAttribute('aria-expanded', 'false');
29 content.setAttribute('aria-hidden', 'true');
30 });
31 });
32 } else {
33 // Opening
34 wrap.classList.add('is-open');
35 trigger.setAttribute('aria-expanded', 'true');
36 content.setAttribute('aria-hidden', 'false');
37 content.style.maxHeight = content.scrollHeight + 'px';
38
39 content.addEventListener('transitionend', function onEnd() {
40 if (wrap.classList.contains('is-open')) {
41 content.style.maxHeight = 'none';
42 }
43 content.removeEventListener('transitionend', onEnd);
44 });
45 }
46 });
47
48 // Keyboard support
49 trigger.addEventListener('keydown', function (e) {
50 if (e.key === 'Enter' || e.key === ' ') {
51 e.preventDefault();
52 trigger.click();
53 }
54 });
55 }
56
57 function init() {
58 toArray(document.querySelectorAll('.bkbg-tgl-wrap')).forEach(initToggle);
59 }
60
61 if (document.readyState === 'loading') {
62 document.addEventListener('DOMContentLoaded', init);
63 } else {
64 init();
65 }
66 })();
67