Skip to content

Commit 3170321

Browse files
authored
Rollup merge of #96658 - Folyd:es6, r=GuillaumeGomez
Move callback to the () => {} syntax. Part of #93058. r? `@GuillaumeGomez`
2 parents da57b3a + 67ebeea commit 3170321

File tree

6 files changed

+109
-112
lines changed

6 files changed

+109
-112
lines changed

src/librustdoc/html/static/js/main.js

+49-56
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-env es6 */
22
/* eslint no-var: "error" */
33
/* eslint prefer-const: "error" */
4+
/* eslint prefer-arrow-callback: "error" */
45
// Local js definitions:
56
/* global addClass, getSettingValue, hasClass, searchState */
67
/* global onEach, onEachLazy, removeClass */
@@ -152,7 +153,7 @@ function hideThemeButtonState() {
152153
themePicker.style.borderBottomLeftRadius = "3px";
153154
}
154155

155-
window.hideSettings = function() {
156+
window.hideSettings = () => {
156157
// Does nothing by default.
157158
};
158159

@@ -190,10 +191,10 @@ window.hideSettings = function() {
190191

191192
themePicker.onclick = switchThemeButtonState;
192193
themePicker.onblur = handleThemeButtonsBlur;
193-
availableThemes.forEach(function(item) {
194+
availableThemes.forEach(item => {
194195
const but = document.createElement("button");
195196
but.textContent = item;
196-
but.onclick = function() {
197+
but.onclick = () => {
197198
switchTheme(window.currentTheme, window.mainTheme, item, true);
198199
useSystemTheme(false);
199200
};
@@ -300,15 +301,15 @@ function loadCss(cssFileName) {
300301
}
301302

302303

303-
getSettingsButton().onclick = function(event) {
304+
getSettingsButton().onclick = event => {
304305
event.preventDefault();
305306
loadScript(window.settingsJS);
306307
};
307308

308309
window.searchState = {
309310
loadingText: "Loading search results...",
310311
input: document.getElementsByClassName("search-input")[0],
311-
outputElement: function() {
312+
outputElement: () => {
312313
let el = document.getElementById("search");
313314
if (!el) {
314315
el = document.createElement("section");
@@ -328,32 +329,30 @@ function loadCss(cssFileName) {
328329
currentTab: 0,
329330
// tab and back preserves the element that was focused.
330331
focusedByTab: [null, null, null],
331-
clearInputTimeout: function() {
332+
clearInputTimeout: () => {
332333
if (searchState.timeout !== null) {
333334
clearTimeout(searchState.timeout);
334335
searchState.timeout = null;
335336
}
336337
},
337-
isDisplayed: function() {
338-
return searchState.outputElement().parentElement.id === ALTERNATIVE_DISPLAY_ID;
339-
},
338+
isDisplayed: () => searchState.outputElement().parentElement.id === ALTERNATIVE_DISPLAY_ID,
340339
// Sets the focus on the search bar at the top of the page
341-
focus: function() {
340+
focus: () => {
342341
searchState.input.focus();
343342
},
344343
// Removes the focus from the search bar.
345-
defocus: function() {
344+
defocus: () => {
346345
searchState.input.blur();
347346
},
348-
showResults: function(search) {
347+
showResults: search => {
349348
if (search === null || typeof search === 'undefined') {
350349
search = searchState.outputElement();
351350
}
352351
switchDisplayedElement(search);
353352
searchState.mouseMovedAfterSearch = false;
354353
document.title = searchState.title;
355354
},
356-
hideResults: function() {
355+
hideResults: () => {
357356
switchDisplayedElement(null);
358357
document.title = searchState.titleBeforeSearch;
359358
// We also remove the query parameter from the URL.
@@ -362,17 +361,17 @@ function loadCss(cssFileName) {
362361
getNakedUrl() + window.location.hash);
363362
}
364363
},
365-
getQueryStringParams: function() {
364+
getQueryStringParams: () => {
366365
const params = {};
367366
window.location.search.substring(1).split("&").
368-
map(function(s) {
367+
map(s => {
369368
const pair = s.split("=");
370369
params[decodeURIComponent(pair[0])] =
371370
typeof pair[1] === "undefined" ? null : decodeURIComponent(pair[1]);
372371
});
373372
return params;
374373
},
375-
setup: function() {
374+
setup: () => {
376375
const search_input = searchState.input;
377376
if (!searchState.input) {
378377
return;
@@ -386,13 +385,13 @@ function loadCss(cssFileName) {
386385
}
387386
}
388387

389-
search_input.addEventListener("focus", function() {
388+
search_input.addEventListener("focus", () => {
390389
search_input.origPlaceholder = search_input.placeholder;
391390
search_input.placeholder = "Type your search here.";
392391
loadSearch();
393392
});
394393

395-
if (search_input.value != '') {
394+
if (search_input.value !== '') {
396395
loadSearch();
397396
}
398397

@@ -620,7 +619,7 @@ function loadCss(cssFileName) {
620619
document.addEventListener("keydown", handleShortcut);
621620

622621
// delayed sidebar rendering.
623-
window.initSidebarItems = function(items) {
622+
window.initSidebarItems = items => {
624623
const sidebar = document.getElementsByClassName("sidebar-elems")[0];
625624
let others;
626625
const current = window.sidebarCurrent;
@@ -731,7 +730,7 @@ function loadCss(cssFileName) {
731730
}
732731
};
733732

734-
window.register_implementors = function(imp) {
733+
window.register_implementors = imp => {
735734
const implementors = document.getElementById("implementors-list");
736735
const synthetic_implementors = document.getElementById("synthetic-implementors-list");
737736
const inlined_types = new Set();
@@ -742,12 +741,12 @@ function loadCss(cssFileName) {
742741
//
743742
// By the way, this is only used by and useful for traits implemented automatically
744743
// (like "Send" and "Sync").
745-
onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) {
744+
onEachLazy(synthetic_implementors.getElementsByClassName("impl"), el => {
746745
const aliases = el.getAttribute("data-aliases");
747746
if (!aliases) {
748747
return;
749748
}
750-
aliases.split(",").forEach(function(alias) {
749+
aliases.split(",").forEach(alias => {
751750
inlined_types.add(alias);
752751
});
753752
});
@@ -781,7 +780,7 @@ function loadCss(cssFileName) {
781780
addClass(code, "code-header");
782781
addClass(code, "in-band");
783782

784-
onEachLazy(code.getElementsByTagName("a"), function(elem) {
783+
onEachLazy(code.getElementsByTagName("a"), elem => {
785784
const href = elem.getAttribute("href");
786785

787786
if (href && href.indexOf("http") !== 0) {
@@ -826,15 +825,15 @@ function loadCss(cssFileName) {
826825
let sectionIsCollapsed = false;
827826
if (hasClass(innerToggle, "will-expand")) {
828827
removeClass(innerToggle, "will-expand");
829-
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function(e) {
828+
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
830829
if (!hasClass(e, "type-contents-toggle")) {
831830
e.open = true;
832831
}
833832
});
834833
innerToggle.title = "collapse all docs";
835834
} else {
836835
addClass(innerToggle, "will-expand");
837-
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function(e) {
836+
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
838837
if (e.parentNode.id !== "implementations-list" ||
839838
(!hasClass(e, "implementors-toggle") &&
840839
!hasClass(e, "type-contents-toggle")))
@@ -861,7 +860,7 @@ function loadCss(cssFileName) {
861860
function setImplementorsTogglesOpen(id, open) {
862861
const list = document.getElementById(id);
863862
if (list !== null) {
864-
onEachLazy(list.getElementsByClassName("implementors-toggle"), function(e) {
863+
onEachLazy(list.getElementsByClassName("implementors-toggle"), e => {
865864
e.open = open;
866865
});
867866
}
@@ -872,7 +871,7 @@ function loadCss(cssFileName) {
872871
setImplementorsTogglesOpen("blanket-implementations-list", false);
873872
}
874873

875-
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function (e) {
874+
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
876875
if (!hideLargeItemContents && hasClass(e, "type-contents-toggle")) {
877876
e.open = true;
878877
}
@@ -890,9 +889,9 @@ function loadCss(cssFileName) {
890889

891890
(function() {
892891
// To avoid checking on "rustdoc-line-numbers" value on every loop...
893-
let lineNumbersFunc = function() {};
892+
let lineNumbersFunc = () => {};
894893
if (getSettingValue("line-numbers") === "true") {
895-
lineNumbersFunc = function(x) {
894+
lineNumbersFunc = x => {
896895
const count = x.textContent.split("\n").length;
897896
const elems = [];
898897
for (let i = 0; i < count; ++i) {
@@ -904,7 +903,7 @@ function loadCss(cssFileName) {
904903
x.parentNode.insertBefore(node, x);
905904
};
906905
}
907-
onEachLazy(document.getElementsByClassName("rust-example-rendered"), function(e) {
906+
onEachLazy(document.getElementsByClassName("rust-example-rendered"), e => {
908907
if (hasClass(e, "compile_fail")) {
909908
e.addEventListener("mouseover", function() {
910909
this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00";
@@ -935,34 +934,34 @@ function loadCss(cssFileName) {
935934
elem.addEventListener("click", f);
936935
}
937936
}
938-
handleClick("help-button", function(ev) {
937+
handleClick("help-button", ev => {
939938
displayHelp(true, ev);
940939
});
941-
handleClick(MAIN_ID, function() {
940+
handleClick(MAIN_ID, () => {
942941
hideSidebar();
943942
});
944943

945-
onEachLazy(document.getElementsByTagName("a"), function(el) {
944+
onEachLazy(document.getElementsByTagName("a"), el => {
946945
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
947946
// jumping to *before* jumping there. We can't do this in onHashChange, because it changes
948947
// the height of the document so we wind up scrolled to the wrong place.
949948
if (el.hash) {
950-
el.addEventListener("click", function() {
949+
el.addEventListener("click", () => {
951950
expandSection(el.hash.slice(1));
952951
hideSidebar();
953952
});
954953
}
955954
});
956955

957-
onEachLazy(document.querySelectorAll(".rustdoc-toggle > summary:not(.hideme)"), function(el) {
958-
el.addEventListener("click", function(e) {
959-
if (e.target.tagName != "SUMMARY" && e.target.tagName != "A") {
956+
onEachLazy(document.querySelectorAll(".rustdoc-toggle > summary:not(.hideme)"), el => {
957+
el.addEventListener("click", e => {
958+
if (e.target.tagName !== "SUMMARY" && e.target.tagName !== "A") {
960959
e.preventDefault();
961960
}
962961
});
963962
});
964963

965-
onEachLazy(document.getElementsByClassName("notable-traits"), function(e) {
964+
onEachLazy(document.getElementsByClassName("notable-traits"), e => {
966965
e.onclick = function() {
967966
this.getElementsByClassName('notable-traits-tooltiptext')[0]
968967
.classList.toggle("force-tooltip");
@@ -971,7 +970,7 @@ function loadCss(cssFileName) {
971970

972971
const sidebar_menu_toggle = document.getElementsByClassName("sidebar-menu-toggle")[0];
973972
if (sidebar_menu_toggle) {
974-
sidebar_menu_toggle.addEventListener("click", function() {
973+
sidebar_menu_toggle.addEventListener("click", () => {
975974
const sidebar = document.getElementsByClassName("sidebar")[0];
976975
if (!hasClass(sidebar, "shown")) {
977976
addClass(sidebar, "shown");
@@ -981,12 +980,12 @@ function loadCss(cssFileName) {
981980
});
982981
}
983982

984-
let buildHelperPopup = function() {
983+
let buildHelperPopup = () => {
985984
const popup = document.createElement("aside");
986985
addClass(popup, "hidden");
987986
popup.id = "help";
988987

989-
popup.addEventListener("click", function(ev) {
988+
popup.addEventListener("click", ev => {
990989
if (ev.target === popup) {
991990
// Clicked the blurred zone outside the help popup; dismiss help.
992991
displayHelp(false, ev);
@@ -1009,14 +1008,10 @@ function loadCss(cssFileName) {
10091008
["&#9166;", "Go to active search result"],
10101009
["+", "Expand all sections"],
10111010
["-", "Collapse all sections"],
1012-
].map(function(x) {
1013-
return "<dt>" +
1014-
x[0].split(" ")
1015-
.map(function(y, index) {
1016-
return (index & 1) === 0 ? "<kbd>" + y + "</kbd>" : " " + y + " ";
1017-
})
1018-
.join("") + "</dt><dd>" + x[1] + "</dd>";
1019-
}).join("");
1011+
].map(x => "<dt>" +
1012+
x[0].split(" ")
1013+
.map((y, index) => (index & 1) === 0 ? "<kbd>" + y + "</kbd>" : " " + y + " ")
1014+
.join("") + "</dt><dd>" + x[1] + "</dd>").join("");
10201015
const div_shortcuts = document.createElement("div");
10211016
addClass(div_shortcuts, "shortcuts");
10221017
div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
@@ -1034,9 +1029,7 @@ function loadCss(cssFileName) {
10341029
"You can look for items with an exact name by putting double quotes around \
10351030
your request: <code>\"string\"</code>",
10361031
"Look for items inside another one by searching for a path: <code>vec::Vec</code>",
1037-
].map(function(x) {
1038-
return "<p>" + x + "</p>";
1039-
}).join("");
1032+
].map(x => "<p>" + x + "</p>").join("");
10401033
const div_infos = document.createElement("div");
10411034
addClass(div_infos, "infos");
10421035
div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;
@@ -1056,7 +1049,7 @@ function loadCss(cssFileName) {
10561049
popup.appendChild(container);
10571050
insertAfter(popup, document.querySelector("main"));
10581051
// So that it's only built once and then it'll do nothing when called!
1059-
buildHelperPopup = function() {};
1052+
buildHelperPopup = () => {};
10601053
};
10611054

10621055
onHashChange(null);
@@ -1067,11 +1060,11 @@ function loadCss(cssFileName) {
10671060
(function () {
10681061
let reset_button_timeout = null;
10691062

1070-
window.copy_path = function(but) {
1063+
window.copy_path = but => {
10711064
const parent = but.parentElement;
10721065
const path = [];
10731066

1074-
onEach(parent.childNodes, function(child) {
1067+
onEach(parent.childNodes, child => {
10751068
if (child.tagName === 'A') {
10761069
path.push(child.textContent);
10771070
}
@@ -1097,7 +1090,7 @@ function loadCss(cssFileName) {
10971090
tmp = document.createTextNode('✓');
10981091
but.appendChild(tmp);
10991092
} else {
1100-
onEachLazy(but.childNodes, function(e) {
1093+
onEachLazy(but.childNodes, e => {
11011094
if (e.nodeType === Node.TEXT_NODE) {
11021095
tmp = e;
11031096
return true;

0 commit comments

Comments
 (0)