File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 28
28
< header class ="navbar navbar-dark navbar-expand bg-dark flex-md-nowrap p-0 shadow sticky-header ">
29
29
< a class ="navbar-brand col-sm-3 col-md-2 mr-0 " href ="/ "> {{ site.title }}</ a >
30
30
< form class ="w-100 d-none d-md-flex " action ="/search " method ="get ">
31
- < input class ="form-control form-control-dark " type ="text " placeholder ="Search " aria-label ="Search " name ="q ">
31
+ < input id =" search-form " class ="form-control form-control-dark " type ="text " placeholder ="Search " aria-label ="Search " name ="q ">
32
32
</ form >
33
33
34
34
< ul class ="navbar-nav flex-row ml-md-auto d-none d-md-flex px-1 ">
76
76
< script src ="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/4.3.0/anchor.min.js "> </ script >
77
77
< script src ="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/highlight.min.js "> </ script >
78
78
< script src ="/assets/js/app.js "> </ script >
79
+ < script src ="/assets/js/search.js "> </ script >
79
80
</ body >
80
81
</ html >
Original file line number Diff line number Diff line change
1
+ $ ( ( ) => {
2
+ const searchForm = document . getElementById ( "search-form" )
3
+ const searchValue = ( new URLSearchParams ( location . search ) ) . get ( "q" )
4
+
5
+ if ( searchValue ) {
6
+ searchForm . value = searchValue
7
+ }
8
+
9
+ addEventListener ( "keydown" , ( e ) => {
10
+ switch ( e . key ) {
11
+ case '/' :
12
+ if ( document . activeElement === searchForm ) break
13
+
14
+ e . preventDefault ( )
15
+ searchForm . focus ( )
16
+ break
17
+ case 'Escape' :
18
+ if ( document . activeElement === searchForm ) {
19
+ searchForm . blur ( )
20
+ }
21
+ break
22
+ }
23
+ } )
24
+ } ) ;
You can’t perform that action at this time.
0 commit comments