about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2020-05-31 14:27:33 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2020-05-31 14:27:33 +0200
commit7a2efa3a106389e9cd5c8bf3ab8f809398e77053 (patch)
tree9eec4d3b10416cbc1e3061eb5565f50852cb1439
parentbcf57d8f20830683d0b66e231010903146a298e7 (diff)
downloadrust-7a2efa3a106389e9cd5c8bf3ab8f809398e77053.tar.gz
rust-7a2efa3a106389e9cd5c8bf3ab8f809398e77053.zip
Put input timeout clearance inside a function
-rw-r--r--src/librustdoc/html/static/main.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index c349b59e562..6169d5ce8e8 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -92,6 +92,13 @@ function getSearchElement() {
 
     var titleBeforeSearch = document.title;
 
+    function clearInputTimeout() {
+        if (searchTimeout !== null) {
+            clearTimeout(searchTimeout);
+            searchTimeout = null;
+        }
+    }
+
     function getPageId() {
         var id = document.location.href.split("#")[1];
         if (id) {
@@ -345,10 +352,7 @@ function getSearchElement() {
         if (hasClass(help, "hidden") === false) {
             displayHelp(false, ev, help);
         } else if (hasClass(search, "hidden") === false) {
-            if (searchTimeout !== null) {
-                clearTimeout(searchTimeout);
-                searchTimeout = null;
-            }
+            clearInputTimeout();
             ev.preventDefault();
             hideSearchResults(search);
             document.title = titleBeforeSearch;
@@ -1805,7 +1809,7 @@ function getSearchElement() {
 
         function startSearch() {
             var callback = function() {
-                clearTimeout(searchTimeout);
+                clearInputTimeout();
                 if (search_input.value.length === 0) {
                     if (browserSupportsHistoryApi()) {
                         history.replaceState("", window.currentCrate + " - Rust", "?search=");
@@ -1819,10 +1823,7 @@ function getSearchElement() {
             search_input.oninput = callback;
             document.getElementsByClassName("search-form")[0].onsubmit = function(e) {
                 e.preventDefault();
-                if (searchTimeout !== null) {
-                    clearTimeout(searchTimeout);
-                    searchTimeout = null;
-                }
+                clearInputTimeout();
                 search();
             };
             search_input.onchange = function(e) {
@@ -1831,10 +1832,7 @@ function getSearchElement() {
                     return;
                 }
                 // Do NOT e.preventDefault() here. It will prevent pasting.
-                if (searchTimeout !== null) {
-                    clearTimeout(searchTimeout);
-                    searchTimeout = null;
-                }
+                clearInputTimeout();
                 // zero-timeout necessary here because at the time of event handler execution the
                 // pasted content is not in the input field yet. Shouldn’t make any difference for
                 // change, though.