Skip to content

Commit 4989a84

Browse files
committed
main.js: consistency changes
1 parent fa41655 commit 4989a84

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

static/js/main.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
langPickerElement.removeChild(currentLangElement.parentNode);
3535
}
3636

37-
const toggleFunction = function () {
37+
var toggleFunction = function () {
3838
langPickerElement.classList.toggle('hidden');
39-
const isAriaExpanded =
39+
var isAriaExpanded =
4040
langPickerTogglerElement.getAttribute('aria-expanded') === 'true';
4141
langPickerTogglerElement.setAttribute('aria-expanded', !isAriaExpanded);
4242
};
@@ -54,11 +54,11 @@
5454
}
5555
});
5656
})();
57+
5758
(function () {
58-
const themeAttr = 'data-theme';
5959
var darkThemeSwitcherElement = document.querySelector('.dark-theme-switcher');
6060

61-
let preferredColorScheme = window.matchMedia('(prefers-color-scheme: dark)')
61+
var preferredColorScheme = window.matchMedia('(prefers-color-scheme: dark)')
6262
.matches
6363
? 'dark'
6464
: 'light';
@@ -69,8 +69,8 @@
6969
if (!getTheme()) {
7070
preferredColorScheme = event.matches ? 'dark' : 'light';
7171
document
72-
.querySelector('html')
73-
.setAttribute(themeAttr, preferredColorScheme);
72+
.documentElement
73+
.setAttribute('data-theme', preferredColorScheme);
7474
}
7575
});
7676

@@ -84,14 +84,15 @@
8484
});
8585

8686
function setTheme(theme) {
87-
document.querySelector('html').setAttribute(themeAttr, theme);
87+
document.documentElement.setAttribute('data-theme', theme);
8888
window.localStorage.setItem('theme', theme);
8989
}
9090

9191
function getTheme() {
9292
return window.localStorage.getItem('theme');
9393
}
9494
})();
95+
9596
(function () {
9697
var scrollToTop = document.querySelector('#scroll-to-top');
9798

@@ -110,6 +111,7 @@
110111

111112
(function () {
112113
'use strict';
114+
113115
var userAgent = navigator.userAgent;
114116
var osMatch = userAgent.match(/(Win|Mac|Linux)/);
115117
var os = (osMatch && osMatch[1]) || '';
@@ -165,10 +167,9 @@
165167
winText.textContent = winText.textContent.replace(/x(86|64)/, arch);
166168
}
167169
})();
168-
(function () {
169-
// This function is used to replace the anchor
170-
// link of Edit on GitHub
171170

171+
// This function is used to replace the anchor link of Edit on GitHub
172+
(function () {
172173
var editOnGitHubElement = document.getElementById('editOnGitHubLink');
173174
var editOnGitHubUrlElement = document.getElementById('editOnGitHubUrl');
174175

static/js/themeSwitcher.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
/* eslint-disable no-var */
12
(function () {
2-
const themeAttr = 'data-theme';
3-
const isInDarkMode =
3+
var isInDarkMode =
44
window.matchMedia &&
55
window.matchMedia('(prefers-color-scheme: dark)').matches;
66

@@ -11,7 +11,7 @@
1111
}
1212

1313
function setTheme(theme) {
14-
document.querySelector('html').setAttribute(themeAttr, theme);
14+
document.documentElement.setAttribute('data-theme', theme);
1515
}
1616

1717
function getTheme() {

0 commit comments

Comments
 (0)