Skip to content

Commit 9d69c29

Browse files
committed
docs: use let and const in theme script
1 parent 39595a0 commit 9d69c29

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

docs/_includes/head_custom.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script>
22
(function() {
3-
var storageKey = "mcp-ruby-sdk-docs-theme";
4-
var validPreferences = ["system", "light", "dark"];
5-
var preferenceLabels = {
3+
const storageKey = "mcp-ruby-sdk-docs-theme";
4+
const validPreferences = ["system", "light", "dark"];
5+
const preferenceLabels = {
66
system: "System",
77
light: "Light",
88
dark: "Dark"
99
};
10-
var mediaQuery = window.matchMedia ?
10+
const mediaQuery = window.matchMedia ?
1111
window.matchMedia("(prefers-color-scheme: dark)") :
1212
{ matches: false };
1313

@@ -17,7 +17,7 @@
1717

1818
function getStoredPreference() {
1919
try {
20-
var preference = window.localStorage.getItem(storageKey);
20+
const preference = window.localStorage.getItem(storageKey);
2121
return isValidPreference(preference) ? preference : "system";
2222
} catch (error) {
2323
return "system";
@@ -41,7 +41,7 @@
4141
}
4242

4343
function nextPreference(preference) {
44-
var index = validPreferences.indexOf(preference);
44+
const index = validPreferences.indexOf(preference);
4545
if (index === -1 || index === validPreferences.length - 1) {
4646
return validPreferences[0];
4747
}
@@ -50,17 +50,17 @@
5050
}
5151

5252
function setThemeToggleLabel(preference) {
53-
var buttons = document.querySelectorAll("[data-theme-toggle]");
54-
var label = "Theme: " + preferenceLabels[preference];
55-
for (var index = 0; index < buttons.length; index += 1) {
53+
const buttons = document.querySelectorAll("[data-theme-toggle]");
54+
const label = "Theme: " + preferenceLabels[preference];
55+
for (let index = 0; index < buttons.length; index += 1) {
5656
buttons[index].setAttribute("aria-label", label);
5757
buttons[index].setAttribute("title", label);
5858
}
5959
}
6060

6161
function applyPreference(preference) {
62-
var safePreference = isValidPreference(preference) ? preference : "system";
63-
var theme = resolvedTheme(safePreference);
62+
const safePreference = isValidPreference(preference) ? preference : "system";
63+
const theme = resolvedTheme(safePreference);
6464

6565
if (window.jtd && typeof window.jtd.setTheme === "function") {
6666
window.jtd.setTheme(theme);
@@ -74,7 +74,7 @@
7474
apply: applyPreference,
7575
getPreference: getStoredPreference,
7676
save: function(preference) {
77-
var safePreference = isValidPreference(preference) ? preference : "system";
77+
const safePreference = isValidPreference(preference) ? preference : "system";
7878
savePreference(safePreference);
7979
applyPreference(safePreference);
8080
}
@@ -83,13 +83,13 @@
8383
applyPreference(getStoredPreference());
8484

8585
function initThemeToggle() {
86-
var buttons = document.querySelectorAll("[data-theme-toggle]");
86+
const buttons = document.querySelectorAll("[data-theme-toggle]");
8787
if (buttons.length === 0) {
8888
return;
8989
}
9090

9191
setThemeToggleLabel(getStoredPreference());
92-
for (var index = 0; index < buttons.length; index += 1) {
92+
for (let index = 0; index < buttons.length; index += 1) {
9393
buttons[index].addEventListener("click", function() {
9494
window.mcpDocsTheme.save(nextPreference(getStoredPreference()));
9595
});

0 commit comments

Comments
 (0)