aboutsummaryrefslogtreecommitdiffstats
path: root/src/wwwroot/scripts/tabs.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/wwwroot/scripts/tabs.js')
-rw-r--r--src/wwwroot/scripts/tabs.js31
1 files changed, 31 insertions, 0 deletions
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