PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / src / blocks / toggle / frontend.ts

frontend.ts in Tableberg – Simple Gutenberg Table Block 1.1.5, at src/blocks/toggle/frontend.ts

61 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 document.addEventListener("DOMContentLoaded", () => {
2 const tabBlocks = document.querySelectorAll<HTMLElement>(".tab-block");
3
4 tabBlocks.forEach(tabBlock => {
5 const activeBackground = tabBlock.dataset.activeBackgroundColor;
6 const activeColor = tabBlock.dataset.activeColor;
7 const inactiveBackground = tabBlock.dataset.backgroundColor;
8 const inactiveColor = tabBlock.dataset.color;
9
10 const tables = tabBlock.querySelectorAll<HTMLElement>(
11 ".wp-block-tableberg-toggle > .wp-block-tableberg"
12 );
13 const headings = tabBlock.querySelectorAll<HTMLElement>(".tab-heading");
14
15 tables.forEach(table => {
16 table.style.display = "none";
17 });
18
19 headings.forEach((heading, index) => {
20 heading.style.setProperty("color", inactiveColor ?? null);
21 heading.style.setProperty(
22 "background-color",
23 inactiveBackground ?? null
24 );
25
26 if (heading.classList.contains("active")) {
27 tables[index].style.display = "block";
28 heading.style.setProperty("color", activeColor ?? null);
29 heading.style.setProperty(
30 "background-color",
31 activeBackground ?? null
32 );
33 }
34
35 heading.addEventListener("click", () => {
36 tables.forEach(tab => {
37 tab.style.display = "none";
38 });
39
40 tables[index].style.display = "block";
41
42 headings.forEach(heading => {
43 heading.classList.remove("active");
44 heading.style.setProperty("color", inactiveColor ?? null);
45 heading.style.setProperty(
46 "background-color",
47 inactiveBackground ?? null
48 );
49 });
50
51 heading.classList.add("active");
52 heading.style.setProperty("color", activeColor ?? null);
53 heading.style.setProperty(
54 "background-color",
55 activeBackground ?? null
56 );
57 });
58 });
59 });
60 });
61