]> git.lizzy.rs Git - rust.git/commitdiff
Allow to go back to previous search
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 10 Nov 2017 18:40:46 +0000 (19:40 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 10 Nov 2017 18:40:46 +0000 (19:40 +0100)
src/librustdoc/html/static/main.js

index 2abc8f7eb6ad0baeb30a89e0cdb7eb0c89eb1301..150b083219ba1143a547c2c43786f16d5d28af4e 100644 (file)
             addClass(search, "hidden");
             removeClass(document.getElementById("main"), "hidden");
             var hash = ev.newURL.slice(ev.newURL.indexOf('#') + 1);
+            if (browserSupportsHistoryApi()) {
+                history.replaceState(hash, "", "#" + hash);
+            }
             var elem = document.getElementById(hash);
             if (elem) {
                 elem.scrollIntoView();
             });
         }
     });
+
+    var search_input = document.getElementsByClassName("search-input")[0];
+
+    if (search_input) {
+        search_input.onfocus = function() {
+            if (search.value !== "") {
+                addClass(document.getElementById("main"), "hidden");
+                removeClass(document.getElementById("search"), "hidden");
+            }
+        };
+    }
 }());
 
 // Sets the focus on the search bar at the top of the page