|
1 | 1 | {{> header}}
|
2 | 2 |
|
| 3 | +<script type="text/javascript" charset="utf-8"> |
| 4 | + function getKey(ev) { |
| 5 | + if ("key" in ev && typeof ev.key != "undefined") { |
| 6 | + return ev.key; |
| 7 | + } |
| 8 | + return String.fromCharCode(ev.charCode || ev.keyCode); |
| 9 | + } |
| 10 | +</script> |
| 11 | + |
3 | 12 | {{#if varsb.show_search_form}}
|
4 | 13 | <div class="container landing">
|
5 | 14 | <h1 class="brand"><i class="fa fa-cubes fa-fw"></i> Docs.rs</h1>
|
6 | 15 |
|
7 | 16 | <form action="/releases/search" method="GET" class="landing-search-form">
|
8 |
| - <div><input class="search-input" name="query" type="text" placeholder="Search" autofocus></div> |
| 17 | + <div><input class="search-input" id="search" name="query" type="text" placeholder="Click or press 'S' to search" autofocus></div> |
9 | 18 | <div class="buttons">
|
10 | 19 | <button type="submit" class="pure-button pure-button-normal">Search</button>
|
11 | 20 | <button type="submit" class="pure-button pure-button-normal" id="i-am-feeling-lucky-button">I'm Feeling Lucky</button>
|
|
21 | 30 | document.getElementsByClassName("landing-search-form")[0].appendChild(input);
|
22 | 31 | return true;
|
23 | 32 | };
|
| 33 | + function handleShortcut(ev) { |
| 34 | + if (ev.ctrlKey || ev.altKey || ev.metaKey || document.activeElement.tagName === "INPUT") { |
| 35 | + return; |
| 36 | + } |
| 37 | + switch (getKey(ev)) { |
| 38 | + case "s": |
| 39 | + case "S": |
| 40 | + ev.preventDefault(); |
| 41 | + document.getElementById("search").focus(); |
| 42 | + break; |
| 43 | + } |
| 44 | + } |
| 45 | + document.onkeypress = handleShortcut; |
| 46 | + document.onkeydown = handleShortcut; |
24 | 47 | </script>
|
25 | 48 | </div>
|
26 | 49 | {{/if}}
|
|
31 | 54 | <div class="release">
|
32 | 55 | <a href="/releases"><strong>Recent Releases</strong></a> <a href="/releases/feed" title="Atom feed"><i class="fa fa-rss-square"></i></a>
|
33 | 56 | </div>
|
| 57 | + {{else}} |
| 58 | + <script type="text/javascript" charset="utf-8"> |
| 59 | + var active = null; |
| 60 | +
|
| 61 | + function handleKey(ev) { |
| 62 | + if (ev.ctrlKey || ev.altKey || ev.metaKey || document.activeElement.tagName === "INPUT") { |
| 63 | + return; |
| 64 | + } |
| 65 | + if (ev.which === 38) { // Down arrow |
| 66 | + if (active === null) { |
| 67 | + active = document.getElementsByClassName("recent-releases-container")[0].getElementsByTagName("li")[0]; |
| 68 | + } else if (active.nextElementSibling) { |
| 69 | + active.classList.remove("selected"); |
| 70 | + active = active.nextElementSibling; |
| 71 | + } |
| 72 | + active.classList.add("selected"); |
| 73 | + } else if (ev.which === 40) { // Up arrow |
| 74 | + if (active === null) { |
| 75 | + active = document.getElementsByClassName("recent-releases-container")[0].getElementsByTagName("li")[0]; |
| 76 | + } else if (active.previousElementSibling) { |
| 77 | + active.classList.remove("selected"); |
| 78 | + active = active.previousElementSibling; |
| 79 | + } |
| 80 | + active.classList.add("selected"); |
| 81 | + active.focus(); |
| 82 | + } else if (e.which === 13) { // Return |
| 83 | + if (active !== null) { |
| 84 | + document.location.href = active.getElementsByTagName("a")[0].href; |
| 85 | + } |
| 86 | + } else { |
| 87 | + switch (getKey(ev)) { |
| 88 | + case "s": |
| 89 | + case "S": |
| 90 | + ev.preventDefault(); |
| 91 | + document.getElementsByClassName("search-input-nav")[0].focus(); |
| 92 | + break; |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + document.onkeypress = handleKey; |
| 97 | + document.onkeydown = handleKey; |
| 98 | + var crates = Array.prototype.slice.call(document.getElementsByClassName("recent-releases-container")[0].getElementsByTagName("li")); |
| 99 | + for (var i = 0; i < crates.length; ++i) { |
| 100 | + crates[i].addEventListener("mouseover", function(event) { |
| 101 | + this.classList.remove("selected"); |
| 102 | + active = null; |
| 103 | + }); |
| 104 | + crates[i].addEventListener("mouseout", function(event) { |
| 105 | + this.classList.remove("selected"); |
| 106 | + active = null; |
| 107 | + }); |
| 108 | + } |
| 109 | + </script> |
34 | 110 | {{/if}}
|
35 | 111 |
|
36 | 112 | <ul>
|
|
0 commit comments