55#TOC { display : none ; }
66.header-section-number { display : none ; }
77li {list-style-type : none ; }
8- . search-input {
9- width : calc (100% - 200 px );
8+ # search-input {
9+ width : calc (100% - 100 px );
1010}
11- . search-but {
11+ # search-but {
1212 cursor : pointer ;
1313}
14- . search-but , . search-input {
14+ # search-but , # search-input {
1515 padding : 4px ;
1616 border : 1px solid #ccc ;
1717 border-radius : 3px ;
1818 outline : none ;
1919 font-size : 0.7em ;
2020 background-color : #fff ;
2121}
22- . search-but:hover , . search-input:focus {
22+ # search-but:hover , # search-input:focus {
2323 border-color : #55a9ff ;
2424}
25+ #search-from {
26+ border : none ;
27+ padding : 0 ;
28+ font-size : 0.7em ;
29+ }
2530</style >
2631
2732Looks like you've taken a wrong turn.
@@ -31,17 +36,17 @@ Some things that might be helpful to you though:
3136# Search
3237
3338<div >
34- <form action = " std/index.html " method = " get " >
35- <input id="std- search" class="search -input" type="search" name="search"
36- placeholder ="Search through the standard library"/ >
37- <button class="search-but">Search Standard Library</button>
38- </ form >
39- </ div >
40-
41- < div >
42- < form action = " https://duckduckgo.com/ " >
43- < input id="site-search" class="search-input " type="search" name="q"></input >
44- <input type="submit" value="Search DuckDuckGo" class="search-but" >
39+ <form id = " search-form " action = " https://duckduckgo.com/ " >
40+ <input id="search-input" type="search" name="q"></input>
41+ <input type="submit" value ="Search" id="search-but" >
42+ <!--
43+ Don't show the options by default,
44+ since "From the Standary Library" doesn't work without JavaScript
45+ -->
46+ <fieldset id="search-from" style="display:none" >
47+ <label><input name="from" value="library" type="radio"> From the Standard Library</label >
48+ <label>< input name="from" value="dro " type="radio" checked> From DuckDuckGo</label >
49+ </fieldset >
4550 </form >
4651</div >
4752
@@ -70,17 +75,28 @@ function get_url_fragments() {
7075 return op;
7176}
7277
73- function populate_site_search () {
74- var op = get_url_fragments ();
78+ function on_submit (event ) {
79+ var form = event .target ;
80+ var q = form[' q' ].value ;
81+
82+ event .preventDefault ();
7583
76- var search = document .getElementById (' site-search' );
77- search .value = op .join (' ' ) + " site:doc.rust-lang.org" ;
84+ if (form[' from' ].value === ' dro' ) {
85+ document .location .href = form .action + ' ?q=' + encodeURIComponent (q + ' site:doc.rust-lang.org' );
86+ } else if (form[' from' ].value === ' library' ) {
87+ document .location .href = ' std/index.html?search=' + encodeURIComponent (q);
88+ }
7889}
7990
80- function populate_rust_search () {
91+ function populate_search () {
92+ var form = document .getElementById (' search-form' );
93+ form .addEventListener (' submit' , on_submit);
94+ document .getElementById (' search-from' ).style .display = ' ' ;
95+
96+ form[' from' ].value = ' library' ;
97+
8198 var op = get_url_fragments ();
82- document .getElementById (' std- search' ).value = op .join (' ' );
99+ document .getElementById (' search-input ' ).value = op .join (' ' );
83100}
84- populate_site_search ();
85- populate_rust_search ();
101+ populate_search ();
86102</script >
0 commit comments