8000 Use arrow functions · python/docsbuild-scripts@2a5adf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a5adf9

Browse files
committed
Use arrow functions
1 parent 84a3f9c commit 2a5adf9

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

templates/switchers.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,35 +55,36 @@ const _create_language_select = (current_language) => {
5555
return select;
5656
};
5757

58-
function navigate_to_first_existing(urls) {
58+
const _navigate_to_first_existing = (urls) => {
5959
// Navigate to the first existing URL in urls.
6060
const url = urls.shift();
6161
if (urls.length === 0 || url.startsWith("file:///")) {
6262
window.location.href = url;
6363
return;
6464
}
6565
fetch(url)
66-
.then(function(response) {
66+
.then((response) => {
6767
if (response.ok) {
6868
window.location.href = url;
6969
} else {
7070
navigate_to_first_existing(urls);
7171
}
7272
})
73-
.catch(function(error) {
73+
.catch((err) => {
74+
void err;
7475
navigate_to_first_existing(urls);
7576
});
76-
}
77+
};
7778

78-
function on_version_switch() {
79+
const _on_version_switch = () => {
7980
const selected_version = this.options[this.selectedIndex].value + '/';
8081
const url = window.location.href;
8182
const current_language = language_segment_from_url();
8283
const current_version = version_segment_from_url();
8384
const new_url = url.replace('/' + current_language + current_version,
8485
'/' + current_language + selected_version);
8586
if (new_url !== url) {
86-
navigate_to_first_existing([
87+
_navigate_to_first_existing([
8788
new_url,
8889
url.replace('/' + current_language + current_version,
8990
'/' + selected_version),
@@ -92,9 +93,9 @@ function on_version_switch() {
9293
'/'
9394
]);
9495
}
95-
}
96+
};
9697

97-
function on_language_switch() {
98+
const _on_language_switch = () => {
9899
let selected_language = this.options[this.selectedIndex].value + '/';
99100
const url = window.location.href;
100101
const current_language = language_segment_from_url();
@@ -104,12 +105,12 @@ function on_language_switch() {
104105
let new_url = url.replace('/' + current_language + current_version,
105106
'/' + selected_language + current_version);
106107
if (new_url !== url) {
107-
navigate_to_first_existing([
108+
_navigate_to_first_existing([
108109
new_url,
109110
'/'
110111
]);
111112
}
112-
}
113+
};
113114

114115
// Returns the path segment of the language as a string, like 'fr/'
115116
// or '' if not found.
@@ -143,7 +144,7 @@ const _initialise_switchers = () => {
143144
.querySelectorAll('.version_switcher_placeholder')
144145
.forEach((placeholder) => {
145146
const s = version_select.cloneNode(true);
146-
s.addEventListener('change', on_version_switch);
147+
s.addEventListener('change', _on_version_switch);
147148
placeholder.append(s);
148149
});
149150

@@ -152,7 +153,7 @@ const _initialise_switchers = () => {
152153
.querySelectorAll('.language_switcher_placeholder')
153154
.forEach((placeholder) => {
154155
const s = language_select.cloneNode(true);
155-
s.addEventListener('change', on_language_switch);
156+
s.addEventListener('change', _on_language_switch);
156157
placeholder.append(s);
157158
});
158159
};

0 commit comments

Comments
 (0)
0