@@ -22,7 +22,7 @@ var vdocs = {
22
22
} ,
23
23
hydrate : function ( ) {
24
24
this . ui . hydrateTheme ( ) ;
25
- this . ui . hydrateTOCPanel ( ) ;
25
+ this . ui . hydrateSidebar ( ) ;
26
26
this . ui . hydrateSearch ( ) ;
27
27
vdocs . examples . init ( ) ;
28
28
} ,
@@ -32,14 +32,24 @@ vdocs.ui = {
32
32
btnChangeTheme : null ,
33
33
currentTheme : 'dark' ,
34
34
35
- hydrateTOCPanel : function ( ) {
36
- document . getElementsByClassName ( "aside-topics-open" ) [ 0 ] . addEventListener ( "click" , ( event ) => {
37
- document . getElementsByClassName ( "aside-topics" ) [ 0 ] . style . setProperty ( 'display' , 'block' )
35
+ tocPanel : null ,
36
+ sidebar : null ,
37
+ hydrateSidebar : function ( ) {
38
+ this . sidebar = document . getElementById ( "sidebar-main" ) ;
39
+ this . tocPanel = document . getElementById ( "topics" ) ;
40
+
41
+ document . querySelector ( ".sidebar-open-btn" ) . addEventListener ( "click" , ( event ) => {
42
+ this . sidebar . style . setProperty ( 'display' , 'block' )
38
43
} )
39
44
40
- document . getElementsByClassName ( "aside-topics- close" ) [ 0 ] . addEventListener ( "click" , ( event ) => {
41
- document . getElementsByClassName ( "aside-topics" ) [ 0 ] . style . setProperty ( 'display' , 'none' )
45
+ document . querySelector ( ".sidebar- close-btn" ) . addEventListener ( "click" , ( event ) => {
46
+ this . sidebar . style . setProperty ( 'display' , 'none' )
42
47
} )
48
+
49
+ //scroll to show selected topic
50
+ const target = document . querySelector ( '.nav-entry.is-selected' ) ;
51
+ target . scrollIntoView ( { behavior : 'smooth' , block : 'center' } ) ;
52
+
43
53
} ,
44
54
hydrateTheme : function ( ) {
45
55
this . btnChangeTheme = document . querySelector ( "header .change-theme" ) ;
@@ -80,9 +90,9 @@ vdocs.ui = {
80
90
searchVisible : false ,
81
91
hydrateSearch : function ( ) {
82
92
// Initialize the search functionality when the DOM is fully loaded
83
- this . searchInput = document . getElementById ( 'searchInput ' ) ;
93
+ this . searchInput = document . getElementById ( 'search-input ' ) ;
84
94
85
- const searchKeys = document . getElementById ( 'searchKeys ' ) ;
95
+ const searchKeys = document . getElementById ( 'search-kb-shortcut ' ) ;
86
96
searchKeys . innerHTML = ( navigator . platform . includes ( 'Mac' ) ? '⌘' : 'Ctrl' ) + ' K' ;
87
97
88
98
var handleDocKey = ( e ) => {
@@ -92,37 +102,43 @@ vdocs.ui = {
92
102
}
93
103
} ;
94
104
95
-
105
+ const closeBtn = document . getElementById ( 'search-results-close' ) ;
106
+ closeBtn . addEventListener ( 'click' , ( event ) => {
107
+ event . preventDefault ( ) ;
108
+ this . hideSearchResults ( ) ;
109
+ } ) ;
96
110
97
111
document . addEventListener ( 'keydown' , ( event ) => {
98
112
99
113
if ( ( event . ctrlKey || event . metaKey ) && event . key === 'k' ) {
100
114
event . preventDefault ( ) ;
101
- searchInput . focus ( ) ;
115
+ this . searchInput . value = '' ;
116
+ this . searchInput . focus ( ) ;
102
117
} else if ( event . key === "Escape" && this . searchVisible ) {
103
118
event . preventDefault ( ) ;
104
119
this . hideSearchResults ( ) ;
105
120
}
106
121
} ) ;
107
122
108
- this . searchResults = document . getElementById ( 'searchResults' ) ;
123
+ this . searchResults = document . getElementById ( 'search-results' ) ;
124
+ this . searchResultsContainer = document . getElementById ( 'search-result-container' ) ;
109
125
110
126
this . searchInput . onfocus = ( ) => searchKeys . style . display = 'none' ;
111
127
this . searchInput . onblur = ( ) => searchKeys . style . display = 'block' ;
112
128
this . searchInput . onkeydown = ( event ) => {
129
+
113
130
if ( event . key === 'Enter' ) {
114
131
this . handleSearch ( ) ;
115
- //document.addEventListener('keydown', handleDocKey);
116
132
} else if ( event . key === 'Escape' ) {
117
- if ( document . getElementById ( ' searchResults' ) . style . display === 'none' ) {
118
- searchInput . blur ( ) ;
133
+ if ( this . searchResults . style . display === 'none' ) {
134
+ this . searchInput . blur ( ) ;
119
135
return
120
136
}
121
137
this . hideSearchResults ( ) ;
122
138
}
123
139
} ;
124
140
125
- document . getElementById ( 'searchButton ' ) . addEventListener ( 'click' , ( evt ) => {
141
+ document . getElementById ( 'search-button ' ) . addEventListener ( 'click' , ( evt ) => {
126
142
this . handleSearch ( ) ;
127
143
} ) ;
128
144
@@ -152,8 +168,8 @@ vdocs.ui = {
152
168
} ,
153
169
hideSearchResults : function ( ) {
154
170
this . searchVisible = false ;
155
- this . searchInput . style . display = 'none' ;
156
- //document.removeEventListener('keydown', handleDocKey );
171
+
172
+ this . sidebar . classList . remove ( "search-results-open" ) ;
157
173
} ,
158
174
handleSearch : function ( ) {
159
175
vdocs . search . topic ( this . searchInput . value , ( items ) => this . showSearchResults ( items ) ) ;
@@ -169,15 +185,15 @@ vdocs.ui = {
169
185
const sectionLink = this . helperGetLinkToSection ( item . section ) ;
170
186
171
187
return `
172
- <div class="result-item ">
173
- <a href="${ sectionLink } " class="result -link">${ item . section } </a>
174
- <p>${ item . snippet } </p>
188
+ <div class="nav-entry is-search-result ">
189
+ <a href="${ sectionLink } " class="nav-entry -link">${ item . section } </a>
190
+ <p class="nav-entry-text" >${ item . snippet } </p>
175
191
</div>` ;
176
192
} ) . join ( '' ) ;
177
193
178
194
this . searchVisible = true ;
179
- this . searchResults . innerHTML = rows ;
180
- this . searchResults . style . display = 'block' ;
195
+ this . searchResultsContainer . innerHTML = rows ;
196
+ this . sidebar . classList . add ( "search-results-open" ) ;
181
197
} ,
182
198
183
199
} ;
0 commit comments