2023-05-29 16:02:28 +00:00
|
|
|
"use strict";
|
|
|
|
|
2023-05-30 06:41:49 +00:00
|
|
|
let tabToFind = location.hash.length > 1 ? location.hash.substring(1) : null;
|
|
|
|
for (let tabber of document.body.querySelectorAll(".wds-tabber")) {
|
2023-05-29 16:02:28 +00:00
|
|
|
let [tabs, contents] = getTabs(tabber);
|
|
|
|
|
|
|
|
for (let i in tabs) {
|
|
|
|
let tab = tabs[i];
|
|
|
|
let content = contents[i];
|
2023-05-30 06:41:49 +00:00
|
|
|
|
2023-05-29 16:02:28 +00:00
|
|
|
tab.addEventListener("click", function(e) {
|
2023-05-30 06:41:49 +00:00
|
|
|
setCurrentTab(tabber, tab, content);
|
2023-05-29 16:02:28 +00:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
2023-05-30 06:41:49 +00:00
|
|
|
if (tab.dataset.hash === tabToFind) {
|
|
|
|
setCurrentTab(tabber, tab, content);
|
|
|
|
}
|
2023-05-29 16:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
document.body.classList.remove("bw-tabs-nojs");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getTabs(tabber) {
|
|
|
|
let tabs = [];
|
|
|
|
let contents = [];
|
|
|
|
|
|
|
|
for (let i of tabber.querySelector(".wds-tabs__wrapper").querySelectorAll(".wds-tabs__tab")) {
|
|
|
|
tabs.push(i);
|
|
|
|
}
|
|
|
|
for (let i of tabber.children) {
|
|
|
|
if (!i.matches(".wds-tab__content")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
contents.push(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [tabs, contents];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentTab(tabber) {
|
|
|
|
let tab = null;
|
|
|
|
let content = null;
|
|
|
|
|
|
|
|
tab = tabber.querySelector(".wds-tabs__wrapper").querySelector(".wds-tabs__tab.wds-is-current");
|
|
|
|
for (let i of tabber.children) {
|
|
|
|
if (!i.matches(".wds-tab__content.wds-is-current")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
content = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [tab, content];
|
|
|
|
}
|
2023-05-30 06:41:49 +00:00
|
|
|
|
|
|
|
function setCurrentTab(tabber, tab, content) {
|
|
|
|
let [currentTab, currentContent] = getCurrentTab(tabber);
|
|
|
|
if (currentTab) {
|
|
|
|
currentTab.classList.remove("wds-is-current");
|
|
|
|
}
|
|
|
|
if (currentContent) {
|
|
|
|
currentContent.classList.remove("wds-is-current");
|
|
|
|
}
|
|
|
|
|
|
|
|
tab.classList.add("wds-is-current");
|
|
|
|
content.classList.add("wds-is-current");
|
2023-05-30 07:01:14 +00:00
|
|
|
if (tab.dataset.hash) {
|
2023-11-13 03:35:07 +00:00
|
|
|
let fragment = "#" + tab.dataset.hash;
|
|
|
|
if (location.hash !== fragment) {
|
|
|
|
history.pushState(null, "", fragment);
|
|
|
|
}
|
2023-05-30 07:01:14 +00:00
|
|
|
}
|
2023-05-30 06:41:49 +00:00
|
|
|
}
|