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