Skip to content

Commit

Permalink
improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
rushatgabhane committed Feb 2, 2024
1 parent 1189848 commit 0bb79c4
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions docs/assets/js/selector.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
function selectOption(s) {
if (!s) {
function selectOption(select) {
if (!select) {
return;
}

// Keep all selects on the page in sync
const allSelects = document.querySelectorAll('select');
for (let i = 0; i < allSelects.length; i++) {
allSelects[i].selectedIndex = s.selectedIndex;
}
syncSelectors(select.selectedIndex);

Check failure on line 6 in docs/assets/js/selector.js

View workflow job for this annotation

GitHub Actions / lint

'syncSelectors' was used before it was defined

const allOptions = Array.from(s.options);
const selectedValue = s.options[s.selectedIndex].value;
const allOptions = Array.from(select.options);
const selectedValue = select.options[select.selectedIndex].value;

// Hide section that isn't selected, and show section that is selected.
allOptions.forEach((option) => {
Expand All @@ -29,4 +25,11 @@ function selectOption(s) {
});
}

function syncSelectors(selectedIndex) {
const allSelects = document.querySelectorAll('select');
for (let i = 0; i < allSelects.length; i++) {
allSelects[i].selectedIndex = selectedIndex;
}
}

window.onload = selectOption(document.getElementsByClassName('selector')[0]);

0 comments on commit 0bb79c4

Please sign in to comment.