Skip to content

Commit

Permalink
doc: save user preference for JS flavor
Browse files Browse the repository at this point in the history
PR-URL: #49526
Fixes: #49508
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
eldoy authored Sep 9, 2023
1 parent a4d0629 commit b500037
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions doc/api_assets/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@
updateHashes();
}

function setupFlavorToggles() {
const kFlavorPreference = 'customFlavor';
const flavorSetting = localStorage.getItem(kFlavorPreference) === 'true';
const flavorToggles = document.querySelectorAll('.js-flavor-toggle');

flavorToggles.forEach((toggleElement) => {
toggleElement.checked = flavorSetting;
toggleElement.addEventListener('change', (e) => {
const checked = e.target.checked;

if (checked) {
localStorage.setItem(kFlavorPreference, true);
} else {
localStorage.removeItem(kFlavorPreference);
}

flavorToggles.forEach((el) => {
el.checked = checked;
});
});
});
}

function setupCopyButton() {
const buttons = document.querySelectorAll('.copy-button');
buttons.forEach((button) => {
Expand Down Expand Up @@ -182,6 +205,8 @@
// Make link to other versions of the doc open to the same hash target (if it exists).
setupAltDocsLink();

setupFlavorToggles();

setupCopyButton();
}

Expand Down

0 comments on commit b500037

Please sign in to comment.