@@ -22,7 +22,7 @@ var vdocs = {
2222 } ,
2323 hydrate : function ( ) {
2424 this . ui . hydrateTheme ( ) ;
25- this . ui . hydrateTOCPanel ( ) ;
25+ this . ui . hydrateSidebar ( ) ;
2626 this . ui . hydrateSearch ( ) ;
2727 vdocs . examples . init ( ) ;
2828 } ,
@@ -32,14 +32,24 @@ vdocs.ui = {
3232 btnChangeTheme : null ,
3333 currentTheme : 'dark' ,
3434
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' )
3843 } )
3944
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' )
4247 } )
48+
49+ //scroll to show selected topic
50+ const target = document . querySelector ( '.nav-entry.is-selected' ) ;
51+ target . scrollIntoView ( { behavior : 'smooth' , block : 'center' } ) ;
52+
4353 } ,
4454 hydrateTheme : function ( ) {
4555 this . btnChangeTheme = document . querySelector ( "header .change-theme" ) ;
@@ -80,9 +90,9 @@ vdocs.ui = {
8090 searchVisible : false ,
8191 hydrateSearch : function ( ) {
8292 // Initialize the search functionality when the DOM is fully loaded
83- this . searchInput = document . getElementById ( 'searchInput ' ) ;
93+ this . searchInput = document . getElementById ( 'search-input ' ) ;
8494
85- const searchKeys = document . getElementById ( 'searchKeys ' ) ;
95+ const searchKeys = document . getElementById ( 'search-kb-shortcut ' ) ;
8696 searchKeys . innerHTML = ( navigator . platform . includes ( 'Mac' ) ? '⌘' : 'Ctrl' ) + ' K' ;
8797
8898 var handleDocKey = ( e ) => {
@@ -92,37 +102,43 @@ vdocs.ui = {
92102 }
93103 } ;
94104
95-
105+ const closeBtn = document . getElementById ( 'search-results-close' ) ;
106+ closeBtn . addEventListener ( 'click' , ( event ) => {
107+ event . preventDefault ( ) ;
108+ this . hideSearchResults ( ) ;
109+ } ) ;
96110
97111 document . addEventListener ( 'keydown' , ( event ) => {
98112
99113 if ( ( event . ctrlKey || event . metaKey ) && event . key === 'k' ) {
100114 event . preventDefault ( ) ;
101- searchInput . focus ( ) ;
115+ this . searchInput . value = '' ;
116+ this . searchInput . focus ( ) ;
102117 } else if ( event . key === "Escape" && this . searchVisible ) {
103118 event . preventDefault ( ) ;
104119 this . hideSearchResults ( ) ;
105120 }
106121 } ) ;
107122
108- this . searchResults = document . getElementById ( 'searchResults' ) ;
123+ this . searchResults = document . getElementById ( 'search-results' ) ;
124+ this . searchResultsContainer = document . getElementById ( 'search-result-container' ) ;
109125
110126 this . searchInput . onfocus = ( ) => searchKeys . style . display = 'none' ;
111127 this . searchInput . onblur = ( ) => searchKeys . style . display = 'block' ;
112128 this . searchInput . onkeydown = ( event ) => {
129+
113130 if ( event . key === 'Enter' ) {
114131 this . handleSearch ( ) ;
115- //document.addEventListener('keydown', handleDocKey);
116132 } 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 ( ) ;
119135 return
120136 }
121137 this . hideSearchResults ( ) ;
122138 }
123139 } ;
124140
125- document . getElementById ( 'searchButton ' ) . addEventListener ( 'click' , ( evt ) => {
141+ document . getElementById ( 'search-button ' ) . addEventListener ( 'click' , ( evt ) => {
126142 this . handleSearch ( ) ;
127143 } ) ;
128144
@@ -152,8 +168,8 @@ vdocs.ui = {
152168 } ,
153169 hideSearchResults : function ( ) {
154170 this . searchVisible = false ;
155- this . searchInput . style . display = 'none' ;
156- //document.removeEventListener('keydown', handleDocKey );
171+
172+ this . sidebar . classList . remove ( "search-results-open" ) ;
157173 } ,
158174 handleSearch : function ( ) {
159175 vdocs . search . topic ( this . searchInput . value , ( items ) => this . showSearchResults ( items ) ) ;
@@ -169,15 +185,15 @@ vdocs.ui = {
169185 const sectionLink = this . helperGetLinkToSection ( item . section ) ;
170186
171187 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>
175191 </div>` ;
176192 } ) . join ( '' ) ;
177193
178194 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" ) ;
181197 } ,
182198
183199} ;
0 commit comments