@@ -8,23 +8,25 @@ function goto(dest, stub = false) {
8
8
const loc = dest . startsWith ( 'pages/' ) ? dest . match ( / p a g e s \/ ( .+ ) \. m d / ) [ 1 ] : dest
9
9
// this triggers redirect to load the page content
10
10
if ( stub ) {
11
- // history.pushState(null, window.location.hostname, loc);
11
+ history . pushState ( null , window . location . hostname , loc ) ;
12
12
}
13
13
else {
14
- // history.pushState(null, window.location.hostname, '/' + loc);
14
+ history . pushState ( null , window . location . hostname , '/' + loc ) ;
15
15
}
16
16
const source = findSource ( dest )
17
17
current = source ;
18
- loadContent ( source ) ;
19
- clearNavHighlights ( ) ;
18
+ loadContent ( source ) ;
19
+ highlightNavPath ( ) ;
20
20
}
21
21
22
22
function findCategory ( path ) {
23
-
24
- const cat = jsonData . find ( i => path . startsWith ( i . path ) )
23
+ const values = path . split ( '/' )
24
+
25
+ let cat = jsonData . find ( i => i . name === values [ 0 ] )
25
26
console . log ( 'FIND CAT' , path , cat )
26
27
return cat ;
27
28
}
29
+
28
30
function findSource ( path ) {
29
31
console . log ( "Find Source" , path , typeof path )
30
32
if ( path && path . endsWith ( '.md' ) )
@@ -60,18 +62,21 @@ function getQueryParams() {
60
62
}
61
63
62
64
// Function to generate categories for header buttons
63
- function generateCategories ( data , priority ) {
65
+ function generateCategories ( data ) {
64
66
const headerButtons = document . getElementById ( 'category-list' ) ;
65
67
headerButtons . innerHTML = '' ; // Clear existing buttons
66
68
for ( const item of data ) {
69
+ console . log ( "GEN CAT" , category , item )
67
70
const button = document . createElement ( 'button' ) ;
68
71
button . textContent = item . name ;
69
72
button . addEventListener ( 'click' , ( ) => {
70
73
switchCategory ( item . children , item . name ) ;
71
74
} ) ;
72
75
headerButtons . appendChild ( button ) ;
73
- if ( category == null || ( priority && priority === item . name ) ) {
76
+ if ( category == null ) {
74
77
category = item . name ;
78
+ }
79
+ if ( category == item . name ) {
75
80
switchCategory ( item . children , item . name ) ;
76
81
}
77
82
}
@@ -83,9 +88,10 @@ function switchCategory(data, source) {
83
88
navbar . innerHTML = '' ; // Clear existing content
84
89
generateNavbar ( data , navbar ) ;
85
90
console . log ( "CHANGING CATEGORY" , category , source , current )
86
- if ( typeof current === 'string' && category == source ) {
87
- highlightNavPath ( )
88
- }
91
+ highlightNavPath ( )
92
+ // if (typeof current === 'string' && category == source) {
93
+ // highlightNavPath()
94
+ // }
89
95
}
90
96
91
97
// Function to generate the navbar HTML based on JSON data
@@ -130,23 +136,26 @@ function generateNavbar(data, parentElement, depth = 0) {
130
136
link . setAttribute ( 'data-path' , item . path ) ; // Add data-path attribute
131
137
link . addEventListener ( "click" , function ( ) {
132
138
console . log ( "ITEM CLICK" , item . path ) ;
133
- const allLinks = document . querySelectorAll ( '.navbar a, .navbar button' ) ;
134
- for ( const link of allLinks ) {
135
- link . classList . remove ( 'selected' , 'selected-file' ) ;
136
- }
137
- this . classList . add ( 'selected' , 'selected-file' ) ;
138
- let parent = this . parentElement ;
139
- while ( parent && parent . classList . contains ( 'dropdown-container' ) ) {
140
- const siblingButton = parent . previousElementSibling ;
141
- if ( siblingButton ) {
142
- siblingButton . classList . add ( 'selected' ) ;
143
- }
144
- parent = parent . parentElement ;
145
- }
146
- // open content
147
- console . log ( "NAV 1" , item , category )
139
+ current = item . path
140
+ // const allLinks = document.querySelectorAll('.navbar a, .navbar button');
141
+ // for (const link of allLinks) {
142
+ // link.classList.remove('selected', 'selected-file');
143
+ // }
144
+ // this.classList.add('selected', 'selected-file');
145
+ // let parent = this.parentElement;
146
+ // while (parent && parent.classList.contains('dropdown-container')) {
147
+ // const siblingButton = parent.previousElementSibling;
148
+ // if (siblingButton) {
149
+ // siblingButton.classList.add('selected');
150
+ // }
151
+ // parent = parent.parentElement;
152
+ // }
153
+ // // open content
154
+ // console.log("NAV 1", item, category)
148
155
149
- current = item . path ;
156
+ // current = item.path;
157
+ // highlightNavPath()
158
+ goto ( item . path )
150
159
loadContent ( this . getAttribute ( 'data-path' ) )
151
160
} ) ;
152
161
parentElement . appendChild ( link ) ;
@@ -164,40 +173,30 @@ function clearNavHighlights() {
164
173
}
165
174
// Function to initialize the selection based on the query parameter
166
175
function highlightNavPath ( ) {
176
+ console . warn ( "HIGHLIGHT" , category , current ) ;
167
177
clearNavHighlights ( )
168
178
if ( ! current ) return ;
169
- const newcat = findCategory ( current )
170
- const source = findSource ( current ) ;
179
+ if ( ! category ) return ;
180
+ // switchCategory(newcat.name)
181
+ // history.replaceState(null, 'Firebase Me: ' + paths[paths.length - 1], '/' + paths.join('/'))
171
182
172
- if ( ! newcat ) {
173
- loadContent ( source )
174
- return ;
175
- }
176
- else {
177
- // history.replaceState(null, 'Firebase Me: ' + paths[paths.length - 1], '/' + paths.join('/'))
178
- }
179
183
180
184
// find target button and iterate through parents
181
185
const target = findNavButtonByPath ( current )
182
186
183
- console . log ( "HIGHLIGHT NAV TARGET" , target )
184
- // FIXME: known issue
185
- // 1. if you pick a nav item
186
- // 2. change the category
187
- // 3. pick another item
188
- // 4. and change the category again
189
- // 5. target == undefined
190
- // why? no idea.
191
- if ( target )
192
- target . classList . add ( 'selected' , 'selected-file' ) ;
193
- let parent = target . parentElement ;
194
- while ( parent && parent . classList . contains ( 'dropdown-container' ) ) {
195
- const siblingButton = parent . previousElementSibling ;
196
- if ( siblingButton ) {
197
- siblingButton . classList . add ( 'selected' , 'open' ) ;
187
+ console . log ( "HIGHLIGHT NAV TARGET" , target , 'category' , category , 'current' , current )
188
+
189
+ if ( target ) {
190
+ target . classList . add ( 'selected' , 'selected-file' ) ;
191
+ let parent = target . parentElement ;
192
+ while ( parent && parent . classList . contains ( 'dropdown-container' ) ) {
193
+ const siblingButton = parent . previousElementSibling ;
194
+ if ( siblingButton ) {
195
+ siblingButton . classList . add ( 'selected' , 'open' ) ;
196
+ }
197
+ parent . style . display = "block" ;
198
+ parent = parent . parentElement ;
198
199
}
199
- parent . style . display = "block" ;
200
- parent = parent . parentElement ;
201
200
}
202
201
// trigger content
203
202
console . log ( "NAV current" )
0 commit comments