3 * Works by matching 'tabToggle<Key>' with 'tabContent<Key>' sections.
6 import {onSelect} from "../services/dom";
11 this.tabContentsByName = {};
12 this.tabButtonsByName = {};
13 this.allContents = [];
16 for (const [key, elems] of Object.entries(this.$manyRefs || {})) {
17 if (key.startsWith('toggle')) {
18 const cleanKey = key.replace('toggle', '').toLowerCase();
19 onSelect(elems, e => this.show(cleanKey));
20 this.allButtons.push(...elems);
21 this.tabButtonsByName[cleanKey] = elems;
23 if (key.startsWith('content')) {
24 const cleanKey = key.replace('content', '').toLowerCase();
25 this.tabContentsByName[cleanKey] = elems;
26 this.allContents.push(...elems);
32 this.allContents.forEach(c => {
33 c.classList.add('hidden');
34 c.classList.remove('selected');
36 this.allButtons.forEach(b => b.classList.remove('selected'));
38 const contents = this.tabContentsByName[key] || [];
39 const buttons = this.tabButtonsByName[key] || [];
40 if (contents.length > 0) {
41 contents.forEach(c => {
42 c.classList.remove('hidden')
43 c.classList.add('selected')
45 buttons.forEach(b => b.classList.add('selected'));