From 22fc4544ad1c25c2e4002f1e77ff325b29dd2a9b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 31 Dec 2020 13:21:27 +0100 Subject: [PATCH 1/2] Replace some loops with "onEachLazy" call --- src/librustdoc/html/static/main.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 1de4b0016c5..c542860ed68 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -2157,14 +2157,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 = "" + @@ -2553,14 +2553,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; From 8b6304ed6240c9e0f2776bce9a8c311c47e17e1f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 31 Dec 2020 13:21:50 +0100 Subject: [PATCH 2/2] Inline resetMouseMoved function directly into "mousemove" event handler --- src/librustdoc/html/static/main.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index c542860ed68..71067d2b67c 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -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;