Skip to content

Commit

Permalink
set active tab from URL parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Nov 17, 2023
1 parent f84d00f commit 254bae2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion static/js/tabpane-persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ function tdPersistKey(key, value) {
}
}

function getActiveTabFromURL() {
const urlParams = new URLSearchParams(window.location.search);
const activeTab = urlParams.get('tab');
return activeTab ? activeTab.toLowerCase() : null;
}

// Retrieve, increment, and store tab-select event count, then returns it.
function tdGetTabSelectEventCountAndInc() {
// @requires: tdSupportsLocalStorage();
Expand Down Expand Up @@ -112,5 +118,11 @@ window.addEventListener('DOMContentLoaded', () => {

var allTabsInThisPage = document.querySelectorAll(_tdPersistCssSelector());
tdRegisterTabClickHandler(allTabsInThisPage);
tdGetAndActivatePersistedTabs(allTabsInThisPage);

const activeTabKeyFromURL = getActiveTabFromURL();
if (activeTabKeyFromURL) {
tdActivateTabsWithKey(activeTabKeyFromURL);
} else {
tdGetAndActivatePersistedTabs(allTabsInThisPage);
}
});

0 comments on commit 254bae2

Please sign in to comment.