about summary refs log tree commit diff
path: root/src/librustdoc/html/static/js/scrape-examples.js
diff options
context:
space:
mode:
authorFolyd <lyshuhow@gmail.com>2022-05-03 12:03:17 +0800
committerFolyd <lyshuhow@gmail.com>2022-05-04 11:10:48 +0800
commit67ebeea7a0d0689bf3f90c60bc64e6ad960c2372 (patch)
tree2875db66bfeec3c315a13094b727b82134de191f /src/librustdoc/html/static/js/scrape-examples.js
parent468492c2af3993f18b1fe98052200575c4a2e678 (diff)
downloadrust-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/scrape-examples.js')
-rw-r--r--src/librustdoc/html/static/js/scrape-examples.js21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/librustdoc/html/static/js/scrape-examples.js b/src/librustdoc/html/static/js/scrape-examples.js
index 865ed7190f3..491b3950ae6 100644
--- a/src/librustdoc/html/static/js/scrape-examples.js
+++ b/src/librustdoc/html/static/js/scrape-examples.js
@@ -1,6 +1,7 @@
 /* eslint-env es6 */
 /* eslint no-var: "error" */
 /* eslint prefer-const: "error" */
+/* eslint prefer-arrow-callback: "error" */
 /* global addClass, hasClass, removeClass, onEachLazy */
 
 (function () {
@@ -38,7 +39,7 @@
 
         if (locs.length > 1) {
             // Toggle through list of examples in a given file
-            const onChangeLoc = function(changeIndex) {
+            const onChangeLoc = changeIndex => {
                 removeClass(highlights[locIndex], 'focus');
                 changeIndex();
                 scrollToLoc(example, locs[locIndex][0]);
@@ -52,15 +53,15 @@
             };
 
             example.querySelector('.prev')
-                .addEventListener('click', function() {
-                    onChangeLoc(function() {
+                .addEventListener('click', () => {
+                    onChangeLoc(() => {
                         locIndex = (locIndex - 1 + locs.length) % locs.length;
                     });
                 });
 
             example.querySelector('.next')
-                .addEventListener('click', function() {
-                    onChangeLoc(function() {
+                .addEventListener('click', () => {
+                    onChangeLoc(() => {
                         locIndex = (locIndex + 1) % locs.length;
                     });
                 });
@@ -68,7 +69,7 @@
 
         const expandButton = example.querySelector('.expand');
         if (expandButton) {
-            expandButton.addEventListener('click', function () {
+            expandButton.addEventListener('click', () => {
                 if (hasClass(example, "expanded")) {
                     removeClass(example, "expanded");
                     scrollToLoc(example, locs[0][0]);
@@ -84,22 +85,22 @@
 
     const firstExamples = document.querySelectorAll('.scraped-example-list > .scraped-example');
     onEachLazy(firstExamples, updateScrapedExample);
-    onEachLazy(document.querySelectorAll('.more-examples-toggle'), function(toggle) {
+    onEachLazy(document.querySelectorAll('.more-examples-toggle'), toggle => {
         // Allow users to click the left border of the <details> section to close it,
         // since the section can be large and finding the [+] button is annoying.
         onEachLazy(toggle.querySelectorAll('.toggle-line, .hide-more'), button => {
-            button.addEventListener('click', function() {
+            button.addEventListener('click', () => {
                 toggle.open = false;
             });
         });
 
         const moreExamples = toggle.querySelectorAll('.scraped-example');
-        toggle.querySelector('summary').addEventListener('click', function() {
+        toggle.querySelector('summary').addEventListener('click', () => {
             // Wrapping in setTimeout ensures the update happens after the elements are actually
             // visible. This is necessary since updateScrapedExample calls scrollToLoc which
             // depends on offsetHeight, a property that requires an element to be visible to
             // compute correctly.
-            setTimeout(function() { onEachLazy(moreExamples, updateScrapedExample); });
+            setTimeout(() => { onEachLazy(moreExamples, updateScrapedExample); });
         }, {once: true});
     });
 })();