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% - 100px );
10
+ }
11
+ #search-but {
12
+ cursor : pointer ;
13
+ }
14
+ #search-but , #search-input {
15
+ padding : 4px ;
16
+ border : 1px solid #ccc ;
17
+ border-radius : 3px ;
18
+ outline : none ;
19
+ font-size : 0.7em ;
20
+ background-color : #fff ;
21
+ }
22
+ #search-but :hover , #search-input :focus {
23
+ border-color : #55a9ff ;
24
+ }
25
+ #search-from {
26
+ border : none ;
27
+ padding : 0 ;
28
+ font-size : 0.7em ;
29
+ }
8
30
</style >
9
31
10
32
Looks like you've taken a wrong turn.
@@ -13,11 +35,20 @@ Some things that might be helpful to you though:
13
35
14
36
# Search
15
37
16
- <form action =" https://duckduckgo.com/ " >
17
- <input type="text" id="site-search" name="q" size="80"></input>
18
- <input type="submit" value="Search DuckDuckGo"></form>
19
-
20
- Rust doc search: <span id =" core-search " ></span >
38
+ <div >
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="duckduckgo" type="radio" checked> From DuckDuckGo</label>
49
+ </fieldset>
50
+ </form >
51
+ </div >
21
52
22
53
# Reference
23
54
@@ -44,26 +75,28 @@ function get_url_fragments() {
44
75
return op;
45
76
}
46
77
47
- function populate_site_search () {
48
- 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 ();
49
83
50
- var search = document .getElementById (' site-search' );
51
- search .value = op .join (' ' ) + " site:doc.rust-lang.org" ;
84
+ if (form[' from' ].value === ' duckduckgo' ) {
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
+ }
52
89
}
53
90
54
- function populate_rust_search () {
55
- var op = get_url_fragments ();
56
- var lt = op .pop ();
91
+ function populate_search () {
92
+ var form = document .getElementById (' search-form' );
93
+ form .addEventListener (' submit' , on_submit);
94
+ document .getElementById (' search-from' ).style .display = ' ' ;
57
95
58
- // #18540, use a single token
96
+ form[ ' from ' ]. value = ' library ' ;
59
97
60
- var a = document .createElement (" a" );
61
- a .href = " https://doc.rust-lang.org/core/?search=" + encodeURIComponent (lt);
62
- a .textContent = lt;
63
- var search = document .getElementById (' core-search' );
64
- search .innerHTML = " " ;
65
- search .appendChild (a);
98
+ var op = get_url_fragments ();
99
+ document .getElementById (' search-input' ).value = op .join (' ' );
66
100
}
67
- populate_site_search ();
68
- populate_rust_search ();
101
+ populate_search ();
69
102
</script >
0 commit comments