Skip to content

Commit

Permalink
Auto merge of rust-lang#80554 - GuillaumeGomez:more-js-cleanup, r=jyn514
Browse files Browse the repository at this point in the history
More js cleanup

Part of rust-lang#79052 (Same kind as rust-lang#80515).

This one is about some small fixes:
 * Replacing some loops with `onEachLazy`.
 * Removing unused function arguments.
 * Turn `buildHelperPopup` into a variable so it can be "replaced" once the function has been called once so it's not called again.

r? `@jyn514`
  • Loading branch information
bors committed Jan 4, 2021
2 parents 8989689 + 8b6304e commit 0cd459f
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,7 @@ function defocusSearchBar() {
document.addEventListener("keypress", handleShortcut);
document.addEventListener("keydown", handleShortcut);

function resetMouseMoved(ev) {
mouseMovedAfterSearch = true;
}

document.addEventListener("mousemove", resetMouseMoved);
document.addEventListener("mousemove", function() { mouseMovedAfterSearch = true; });

var handleSourceHighlight = (function() {
var prev_line_id = 0;
Expand Down Expand Up @@ -2151,14 +2147,14 @@ function defocusSearchBar() {
var code = document.createElement("code");
code.innerHTML = struct.text;

var x = code.getElementsByTagName("a");
var xlength = x.length;
for (var it = 0; it < xlength; it++) {
var href = x[it].getAttribute("href");
onEachLazy(code.getElementsByTagName("a"), function(elem) {
var href = elem.getAttribute("href");

if (href && href.indexOf("http") !== 0) {
x[it].setAttribute("href", rootPath + href);
elem.setAttribute("href", rootPath + href);
}
}
});

var display = document.createElement("h3");
addClass(display, "impl");
display.innerHTML = "<span class=\"in-band\"><table class=\"table-display\">" +
Expand Down Expand Up @@ -2547,14 +2543,12 @@ function defocusSearchBar() {
var hiddenElems = e.getElementsByClassName("hidden");
var needToggle = false;

var hlength = hiddenElems.length;
for (var i = 0; i < hlength; ++i) {
if (hasClass(hiddenElems[i], "content") === false &&
hasClass(hiddenElems[i], "docblock") === false) {
needToggle = true;
break;
var needToggle = onEachLazy(e.getElementsByClassName("hidden"), function(hiddenElem) {
if (hasClass(hiddenElem, "content") === false &&
hasClass(hiddenElem, "docblock") === false) {
return true;
}
}
});
if (needToggle === true) {
var inner_toggle = newToggle.cloneNode(true);
inner_toggle.onclick = toggleClicked;
Expand Down

0 comments on commit 0cd459f

Please sign in to comment.