Skip to content

Commit

Permalink
Add script to store query parameter in local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
gvdongen committed Dec 15, 2023
1 parent f997181 commit 7ada7f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ const config = {
},
},
themes: ["docusaurus-json-schema-plugin"],
scripts: [
'/js/store-query-parameter.js',
]
};

module.exports = config;
21 changes: 21 additions & 0 deletions static/js/store-query-parameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This script stores the 'sdk' parameter value in the local storage
// so that the preferred SDK tab stays selected, as the user clicks through the UI.
// The default docusaurus behavior only stores the sdk preference in local storage if the user clicked on a specific tab,
// it didn't store the query parameters in local storage. So the query parameters would get lost on subsequent clicks.
const storeSelectedSDK = function () {
console.info("Running sdk language parameter recognition script: " + window.location.search);
const urlParams = new URLSearchParams(window.location.search);
const sdkParam = urlParams.get('sdk');

// Check if the 'sdk' parameter is present in the URL
if (sdkParam !== null) {
// Store the 'sdk' parameter value in the local storage
console.info("Setting sdk local storage parameter to: " + sdkParam);
localStorage.setItem('docusaurus.tab.sdk', sdkParam);
}
}

// On window load
window.onload = storeSelectedSDK;
// On any subsequent click which doesn't reload the page
document.addEventListener('click', storeSelectedSDK);

0 comments on commit 7ada7f8

Please sign in to comment.