| | |
| | | this.tabs = new Map(); |
| | | |
| | | this.hasHash = false; |
| | | this.shouldNotify = true; |
| | | this.init(); |
| | | } |
| | | init() { |
| | |
| | | |
| | | const tab = e.target.closest(this.selectors.tab); |
| | | if (tab) { |
| | | if (tab.dataset.skip) { |
| | | delete config.preCheck; |
| | | } |
| | | this.switchTab(tab.dataset.tab, config); |
| | | } |
| | | } |
| | |
| | | ui.sections.forEach(section => { |
| | | if (section.querySelector('.tabs')) { |
| | | options.hasChildren = true; |
| | | this.registerTab(section, {parent: tabsId}); |
| | | this.registerTab(section, {parent: tabsId, ... options}); |
| | | } |
| | | }); |
| | | |
| | |
| | | let config = { |
| | | id: tabsId, |
| | | ui: ui, |
| | | updateURL: options.updateURL ?? true |
| | | updateURL: options.updateURL ?? true, |
| | | ... options |
| | | }; |
| | | if (Object.hasOwn(options, 'preCheck')) { |
| | | config.preCheck = options.preCheck; |
| | |
| | | ui.nav.addEventListener('click', this.clickHandler); |
| | | ui.select?.addEventListener('change', this.changeHandler); |
| | | this.tabs.set(tabsId, config); |
| | | this.shouldNotify = false; |
| | | this.determineActiveTab(config); |
| | | |
| | | this.shouldNotify = true; |
| | | return config; |
| | | } |
| | | |
| | |
| | | config = (typeof config === 'string') ? this.tabs.get(config) : config; |
| | | if (!config) return; |
| | | let activeTab = config.ui.sections.filter(section => section.classList.contains('active')); |
| | | |
| | | if (Object.hasOwn(config, 'preCheck') && !config.preCheck(activeTab[0], tab, config)) return; |
| | | |
| | | if (document.activeElement && this.isInTabs(document.activeElement, config)) document.activeElement.blur(); |
| | |
| | | if (config?.updateURL) this.updateURL(config); |
| | | if (config.ui.select) this.maybeUpdateSelect(tab, config); |
| | | |
| | | if (this.shouldNotify) { |
| | | this.a11y.announce(`Switched to ${tab} tab`); |
| | | } |
| | | } |
| | | updateChildTabs(id) { |
| | | Array.from(this.tabs.values()).filter(conf => conf.parent === id).forEach(inst => { |
| | | let firstBtn = inst.ui.buttons[0].dataset.tab??false; |