Unify the search boxes

Instead of having the standard library search and DuckDuckGo search.
This change merges two of them, with radio buttons.
This commit is contained in:
Kazuyoshi Kato 2018-09-30 08:59:36 -07:00
parent f34805a893
commit ecb5142ede
1 changed files with 40 additions and 24 deletions

View File

@ -5,13 +5,13 @@
#TOC { display: none; } #TOC { display: none; }
.header-section-number { display: none; } .header-section-number { display: none; }
li {list-style-type: none; } li {list-style-type: none; }
.search-input { #search-input {
width: calc(100% - 200px); width: calc(100% - 100px);
} }
.search-but { #search-but {
cursor: pointer; cursor: pointer;
} }
.search-but, .search-input { #search-but, #search-input {
padding: 4px; padding: 4px;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 3px; border-radius: 3px;
@ -19,9 +19,14 @@ li {list-style-type: none; }
font-size: 0.7em; font-size: 0.7em;
background-color: #fff; background-color: #fff;
} }
.search-but:hover, .search-input:focus { #search-but:hover, #search-input:focus {
border-color: #55a9ff; border-color: #55a9ff;
} }
#search-from {
border: none;
padding: 0;
font-size: 0.7em;
}
</style> </style>
Looks like you've taken a wrong turn. Looks like you've taken a wrong turn.
@ -31,17 +36,17 @@ Some things that might be helpful to you though:
# Search # Search
<div> <div>
<form action="std/index.html" method="get"> <form id="search-form" action="https://duckduckgo.com/">
<input id="std-search" class="search-input" type="search" name="search" <input id="search-input" type="search" name="q"></input>
placeholder="Search through the standard library"/> <input type="submit" value="Search" id="search-but">
<button class="search-but">Search Standard Library</button> <!--
</form> Don't show the options by default,
</div> since "From the Standary Library" doesn't work without JavaScript
-->
<div> <fieldset id="search-from" style="display:none">
<form action="https://duckduckgo.com/"> <label><input name="from" value="library" type="radio"> From the Standard Library</label>
<input id="site-search" class="search-input" type="search" name="q"></input> <label><input name="from" value="dro" type="radio" checked> From DuckDuckGo</label>
<input type="submit" value="Search DuckDuckGo" class="search-but"> </fieldset>
</form> </form>
</div> </div>
@ -70,17 +75,28 @@ function get_url_fragments() {
return op; return op;
} }
function populate_site_search() { function on_submit(event) {
var op = get_url_fragments(); var form = event.target;
var q = form['q'].value;
var search = document.getElementById('site-search'); event.preventDefault();
search.value = op.join(' ') + " site:doc.rust-lang.org";
if (form['from'].value === 'dro') {
document.location.href = form.action + '?q=' + encodeURIComponent(q + ' site:doc.rust-lang.org');
} else if (form['from'].value === 'library') {
document.location.href = 'std/index.html?search=' + encodeURIComponent(q);
}
} }
function populate_rust_search() { function populate_search() {
var form = document.getElementById('search-form');
form.addEventListener('submit', on_submit);
document.getElementById('search-from').style.display = '';
form['from'].value = 'library';
var op = get_url_fragments(); var op = get_url_fragments();
document.getElementById('std-search').value = op.join(' '); document.getElementById('search-input').value = op.join(' ');
} }
populate_site_search(); populate_search();
populate_rust_search();
</script> </script>