about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2015-10-02 20:38:22 -0400
committerSteve Klabnik <steve@steveklabnik.com>2015-10-02 20:38:22 -0400
commitf368a1805934f2a5da99b9b47692577d0699f33e (patch)
tree8614886f7ab6b23f2a8443b73e2addcdfd962d85
parentbfb26033af68949646081429040db606a044db22 (diff)
parentf38bc2c45763f773c9373634dbbe58cc36bf8704 (diff)
downloadrust-f368a1805934f2a5da99b9b47692577d0699f33e.tar.gz
rust-f368a1805934f2a5da99b9b47692577d0699f33e.zip
Rollup merge of #28736 - nagisa:rustdocjsfix, r=alexcrichton
-rw-r--r--src/librustdoc/html/static/main.js30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 9a13d208546..5a6d7616832 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -133,7 +133,7 @@
     $(document).on("keypress", handleShortcut);
     $(document).on("keydown", handleShortcut);
     $(document).on("click", function(ev) {
-        if (!$(e.target).closest("#help > div").length) {
+        if (!$(ev.target).closest("#help > div").length) {
             $("#help").addClass("hidden");
             $("body").removeClass("blur");
         }
@@ -515,7 +515,6 @@
                 var $active = $results.filter('.highlighted');
 
                 if (e.which === 38) { // up
-                    e.preventDefault();
                     if (!$active.length || !$active.prev()) {
                         return;
                     }
@@ -523,7 +522,6 @@
                     $active.prev().addClass('highlighted');
                     $active.removeClass('highlighted');
                 } else if (e.which === 40) { // down
-                    e.preventDefault();
                     if (!$active.length) {
                         $results.first().addClass('highlighted');
                     } else if ($active.next().length) {
@@ -531,7 +529,6 @@
                         $active.removeClass('highlighted');
                     }
                 } else if (e.which === 13) { // return
-                    e.preventDefault();
                     if ($active.length) {
                         document.location.href = $active.find('a').prop('href');
                     }
@@ -722,20 +719,29 @@
         }
 
         function startSearch() {
-
-            $(".search-input").on("keyup",function() {
+            var searchTimeout;
+            $(".search-input").on("keyup input",function() {
+                clearTimeout(searchTimeout);
                 if ($(this).val().length === 0) {
                     window.history.replaceState("", "std - Rust", "?search=");
                     $('#main.content').removeClass('hidden');
                     $('#search.content').addClass('hidden');
+                } else {
+                    searchTimeout = setTimeout(search, 500);
                 }
             });
-
-            var keyUpTimeout;
-            $('.do-search').on('click', search);
-            $('.search-input').on('keyup', function() {
-                clearTimeout(keyUpTimeout);
-                keyUpTimeout = setTimeout(search, 500);
+            $('.search-form').on('submit', function(e){
+                e.preventDefault();
+                clearTimeout(searchTimeout);
+                search();
+            });
+            $('.search-input').on('change paste', function(e) {
+                // Do NOT e.preventDefault() here. It will prevent pasting.
+                clearTimeout(searchTimeout);
+                // 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.
+                setTimeout(search, 0);
             });
 
             // Push and pop states are used to add search results to the browser