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 7c520fe
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion static/js/tabpane-persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,23 @@ function tdRegisterTabClickHandler(tabs) {
});
}

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

// Register listeners and activate tabs

window.addEventListener('DOMContentLoaded', () => {
if (!_tdSupportsLocalStorage()) return;

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

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

0 comments on commit 7c520fe

Please sign in to comment.