Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions view/base/web/js/tabbis.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,29 @@ class tabbisClass {

// Setup
setup() {
const panes = document.querySelectorAll(this.getOption('paneGroup'));
const tabs = document.querySelectorAll(this.getOption('tabGroup'));

tabs.forEach((tabGroups, groupIndex) => {
const paneGroups = panes[groupIndex];
const tabContainer = tabGroups.closest('.qdb-container');
const paneGroups = tabContainer ? tabContainer.querySelector(this.getOption('paneGroup')) : null;
const activeIndex = this.getActiveIndex(tabGroups, groupIndex);

if (!paneGroups) {
return;
}

tabGroups.setAttribute('role', 'tablist');
this.tabOptions[groupIndex] = JSON.parse(tabGroups.getAttribute('tabbis-options'));
this.tabOptions[groupIndex] = JSON.parse(tabGroups.getAttribute('tabbis-options'));

// Reset items
this.resetTabs([ ...tabGroups.children ]);
this.resetPanes([ ...paneGroups.children ]);

[ ...tabGroups.children ].forEach((tabItem, tabIndex) => {
const paneItem = paneGroups.children[tabIndex];
if (!paneItem) {
return;
}

// Add attributes
this.addTabAttributes(tabItem, groupIndex);
Expand All @@ -52,8 +59,9 @@ class tabbisClass {
}
});

if (activeIndex !== null) {
this.toggle([ ...tabGroups.children ][activeIndex]);
const activeTab = [ ...tabGroups.children ][activeIndex];
if (activeTab) {
this.toggle(activeTab, groupIndex);
}
});
}
Expand Down Expand Up @@ -172,15 +180,28 @@ class tabbisClass {
}
}

resetForTab(tab) {
const pane = this.getPaneForTab(tab);
this.resetTabs([ ...tab.parentNode.children ]);
this.resetPanes([ ...pane.parentElement.children ]);
}
resetForTab(tab) {
const pane = this.getPaneForTab(tab);
if (!pane) {
return;
}
this.resetTabs([ ...tab.parentNode.children ]);
this.resetPanes([ ...pane.parentElement.children ]);
}

getPaneForTab(tab) {
return document.querySelector('[aria-controled-by="'+tab.getAttribute('aria-controls')+'"]');
}
getPaneForTab(tab) {
const tabContainer = tab.closest('.qdb-container');
const paneSelector = '[aria-controled-by="'+tab.getAttribute('aria-controls')+'"]';

if (tabContainer) {
const pane = tabContainer.querySelector(paneSelector);
if (pane) {
return pane;
}
}

return document.querySelector(paneSelector);
}

// Activate
activate(tab, i) {
Expand All @@ -206,9 +227,9 @@ class tabbisClass {

}

isActiveTab(tab) {
return tab.getAttribute('aria-selected') === "true";
}
isActiveTab(tab) {
return !!tab && tab.getAttribute('aria-selected') === "true";
}

// Activate tab
activateTab(tab) {
Expand Down