diff options
| author | Folyd <lyshuhow@gmail.com> | 2022-05-03 12:03:17 +0800 |
|---|---|---|
| committer | Folyd <lyshuhow@gmail.com> | 2022-05-04 11:10:48 +0800 |
| commit | 67ebeea7a0d0689bf3f90c60bc64e6ad960c2372 (patch) | |
| tree | 2875db66bfeec3c315a13094b727b82134de191f /src/librustdoc/html/static/js/source-script.js | |
| parent | 468492c2af3993f18b1fe98052200575c4a2e678 (diff) | |
| download | rust-67ebeea7a0d0689bf3f90c60bc64e6ad960c2372.tar.gz rust-67ebeea7a0d0689bf3f90c60bc64e6ad960c2372.zip | |
Move callback to the () => {} syntax.
Fix lint Fix main.js Restore anonymous functions Fix Fix more
Diffstat (limited to 'src/librustdoc/html/static/js/source-script.js')
| -rw-r--r-- | src/librustdoc/html/static/js/source-script.js | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js index 6aee0da69f8..290bf40a8f5 100644 --- a/src/librustdoc/html/static/js/source-script.js +++ b/src/librustdoc/html/static/js/source-script.js @@ -1,6 +1,7 @@ /* eslint-env es6 */ /* eslint no-var: "error" */ /* eslint prefer-const: "error" */ +/* eslint prefer-arrow-callback: "error" */ // From rust: /* global search, sourcesIndex */ @@ -8,7 +9,7 @@ // Local js definitions: /* global addClass, getCurrentValue, hasClass, onEachLazy, removeClass, browserSupportsHistoryApi */ /* global updateLocalStorage */ -(function() { +(function () { function getCurrentFilePath() { const parts = window.location.pathname.split("/"); @@ -32,7 +33,7 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { fullPath += elem["name"] + "/"; - name.onclick = function() { + name.onclick = () => { if (hasClass(this, "expand")) { removeClass(this, "expand"); } else { @@ -134,7 +135,7 @@ function createSourceSidebar() { title.className = "title"; title.innerText = "Files"; sidebar.appendChild(title); - Object.keys(sourcesIndex).forEach(function(key) { + Object.keys(sourcesIndex).forEach(key => { sourcesIndex[key].name = key; hasFoundFile = createDirEntry(sourcesIndex[key], sidebar, "", currentFile, hasFoundFile); @@ -175,8 +176,8 @@ function highlightSourceLines(match) { if (x) { x.scrollIntoView(); } - onEachLazy(document.getElementsByClassName("line-numbers"), function(e) { - onEachLazy(e.getElementsByTagName("span"), function(i_e) { + onEachLazy(document.getElementsByClassName("line-numbers"), e => { + onEachLazy(e.getElementsByTagName("span"), i_e => { removeClass(i_e, "line-highlighted"); }); }); @@ -189,10 +190,10 @@ function highlightSourceLines(match) { } } -const handleSourceHighlight = (function() { +const handleSourceHighlight = (function () { let prev_line_id = 0; - const set_fragment = function(name) { + const set_fragment = name => { const x = window.scrollX, y = window.scrollY; if (browserSupportsHistoryApi()) { @@ -205,7 +206,7 @@ const handleSourceHighlight = (function() { window.scrollTo(x, y); }; - return function(ev) { + return ev => { let cur_line_id = parseInt(ev.target.id, 10); ev.preventDefault(); @@ -226,14 +227,14 @@ const handleSourceHighlight = (function() { }; }()); -window.addEventListener("hashchange", function() { +window.addEventListener("hashchange", () => { const match = window.location.hash.match(lineNumbersRegex); if (match) { return highlightSourceLines(match); } }); -onEachLazy(document.getElementsByClassName("line-numbers"), function(el) { +onEachLazy(document.getElementsByClassName("line-numbers"), el => { el.addEventListener("click", handleSourceHighlight); }); |
