PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.11
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.11
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 / tabs / frontend.js

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

83 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 'use strict';
3
4 function initTabs(wrapper) {
5 var tabs = Array.prototype.slice.call(wrapper.querySelectorAll('.bkbg-tabs-tab'));
6 var panels = Array.prototype.slice.call(wrapper.querySelectorAll('.bkbg-tabs-panel'));
7
8 if (!tabs.length || !panels.length) return;
9
10 function activateTab(index) {
11 tabs.forEach(function (tab, i) {
12 var isActive = i === index;
13 tab.classList.toggle('is-active', isActive);
14 tab.setAttribute('aria-selected', isActive ? 'true' : 'false');
15 tab.setAttribute('tabIndex', isActive ? '0' : '-1');
16 });
17
18 panels.forEach(function (panel, i) {
19 var isActive = i === index;
20 panel.classList.toggle('is-active', isActive);
21 panel.setAttribute('aria-hidden', isActive ? 'false' : 'true');
22 if (isActive) {
23 // Restart animation
24 panel.style.animation = 'none';
25 // Force reflow
26 void panel.offsetHeight;
27 panel.style.animation = '';
28 }
29 });
30 }
31
32 tabs.forEach(function (tab, index) {
33 tab.addEventListener('click', function () {
34 activateTab(index);
35 });
36
37 // Keyboard navigation
38 tab.addEventListener('keydown', function (e) {
39 var key = e.key;
40 var tabbar = tab.closest('.bkbg-tabs-tabbar');
41 var tabList = Array.prototype.slice.call(tabbar ? tabbar.querySelectorAll('.bkbg-tabs-tab') : []);
42 var currentIndex = tabList.indexOf(tab);
43 var isVertical = wrapper.classList.contains('bkbg-tabs-pos-left');
44
45 var prevKey = isVertical ? 'ArrowUp' : 'ArrowLeft';
46 var nextKey = isVertical ? 'ArrowDown' : 'ArrowRight';
47
48 if (key === nextKey) {
49 e.preventDefault();
50 var next = (currentIndex + 1) % tabList.length;
51 tabList[next].focus();
52 activateTab(next);
53 } else if (key === prevKey) {
54 e.preventDefault();
55 var prev = (currentIndex - 1 + tabList.length) % tabList.length;
56 tabList[prev].focus();
57 activateTab(prev);
58 } else if (key === 'Home') {
59 e.preventDefault();
60 tabList[0].focus();
61 activateTab(0);
62 } else if (key === 'End') {
63 e.preventDefault();
64 tabList[tabList.length - 1].focus();
65 activateTab(tabList.length - 1);
66 }
67 });
68 });
69 }
70
71 // Init on DOMContentLoaded and handle dynamic insertion
72 function init() {
73 var wrappers = Array.prototype.slice.call(document.querySelectorAll('.bkbg-tabs-wrapper'));
74 wrappers.forEach(initTabs);
75 }
76
77 if (document.readyState === 'loading') {
78 document.addEventListener('DOMContentLoaded', init);
79 } else {
80 init();
81 }
82 })();
83