Skip to content

Commit

Permalink
Update tab.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewel committed Aug 20, 2023
1 parent b88024f commit 06837bd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion members/static/members/js/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ document.addEventListener("DOMContentLoaded", function(event) {
Array.from(tabs.children).filter(element => element.tagName === "SECTION")
);

// Get the 'active' parameter value from the URL fragment
const urlFragment = window.location.hash.substr(1); // Remove the '#' symbol
const activeItemId = urlFragment.split("=")[1];

// Default to the first list item as active if the ID is not provided or doesn't match any item
const activeIndex = tabButtons.findIndex(button => button.id === activeItemId);
const defaultIndex = activeIndex !== -1 ? activeIndex : 0;

// Default to first as active
toggleActive(sections, tabButtons, 0);
toggleActive(sections, tabButtons, defaultIndex);

for (var button of tabButtons) {
button.addEventListener("click", event =>
toggleActive(sections, tabButtons, tabButtons.indexOf(event.srcElement))
);
const newUrl = window.location.pathname; // Remove any query parameters or hash from the URL
window.history.pushState({}, "", newUrl);
}
}
});
Expand Down

0 comments on commit 06837bd

Please sign in to comment.