From 9383a2fb09ffb60cfe63683106945bd688affa59 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Wed, 1 Jun 2022 21:13:43 +0200 Subject: feat: Initial commit after clean slate --- src/wwwroot/scripts/tabs.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/wwwroot/scripts/tabs.js (limited to 'src/wwwroot/scripts/tabs.js') diff --git a/src/wwwroot/scripts/tabs.js b/src/wwwroot/scripts/tabs.js new file mode 100644 index 0000000..69d670c --- /dev/null +++ b/src/wwwroot/scripts/tabs.js @@ -0,0 +1,31 @@ +export function initTabs() { + let firstActiveIsShown = false; + document.querySelectorAll(".tab-content-container[data-tab]").forEach(contentContainer => { + if (contentContainer.classList.contains("active") && !firstActiveIsShown) { + firstActiveIsShown = true; + return; + } + contentContainer.style.display = "none"; + }); + + document.querySelectorAll(".tab-button[data-tab]").forEach(button => { + button.addEventListener("click", handleButtonClick); + }); + + function handleButtonClick(element) { + if (element.originalTarget.dataset.tab) { + document.querySelectorAll(".tab-button[data-tab]").forEach(b => { + if (b.dataset.tab === element.originalTarget.dataset.tab) + b.classList.add("active"); + else + b.classList.remove("active"); + }); + document.querySelectorAll(".tab-content-container[data-tab]").forEach(c => { + if (c.dataset.tab === element.originalTarget.dataset.tab) + c.style.display = ""; + else + c.style.display = "none"; + }); + } + } +} \ No newline at end of file -- cgit v1.3