5
5
#TOC { display : none ; }
6
6
.header-section-number { display : none ; }
7
7
li {list-style-type : none ; }
8
- . search-input {
9
- width : calc (100% - 200 px );
8
+ # search-input {
9
+ width : calc (100% - 100 px );
10
10
}
11
- . search-but {
11
+ # search-but {
12
12
cursor : pointer ;
13
13
}
14
- . search-but , . search-input {
14
+ # search-but , # search-input {
15
15
padding : 4px ;
16
16
border : 1px solid #ccc ;
17
17
border-radius : 3px ;
18
18
outline : none ;
19
19
font-size : 0.7em ;
20
20
background-color : #fff ;
21
21
}
22
- . search-but:hover , . search-input:focus {
22
+ # search-but:hover , # search-input:focus {
23
23
border-color : #55a9ff ;
24
24
}
25
+ #search-from {
26
+ border : none ;
27
+ padding : 0 ;
28
+ font-size : 0.7em ;
29
+ }
25
30
</style >
26
31
27
32
Looks like you've taken a wrong turn.
@@ -31,17 +36,17 @@ Some things that might be helpful to you though:
31
36
# Search
32
37
33
38
<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 >
45
50
</form >
46
51
</div >
47
52
@@ -70,17 +75,28 @@ function get_url_fragments() {
70
75
return op;
71
76
}
72
77
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 ();
75
83
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
+ }
78
89
}
79
90
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
+
81
98
var op = get_url_fragments ();
82
- document .getElementById (' std- search' ).value = op .join (' ' );
99
+ document .getElementById (' search-input ' ).value = op .join (' ' );
83
100
}
84
- populate_site_search ();
85
- populate_rust_search ();
101
+ populate_search ();
86
102
</script >
0 commit comments