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 <duhamelantoine1995@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
  • Loading branch information
eldoy authored and ruyadorno committed Sep 28, 2023
1 parent ac06607 commit 53fb5ae
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 53fb5ae

Please sign in to comment.