@@ -38,7 +38,6 @@ export default class Nav extends View {
3838 this . $map = new Map ( ) ;
3939
4040 // Set up nav items - those with HREF # dispatch events
41- console . log ( 'subnav' , this . queryAll ( 'li a.nav-link' ) ) ;
4241 this . queryAll ( 'li a.nav-link' ) . forEach ( ( elem ) => {
4342 this . $set ( elem ) ;
4443 } ) ;
@@ -48,9 +47,9 @@ export default class Nav extends View {
4847
4948 // Determine current path and set the active link
5049 const path = window . location . pathname . pathSplit ( ) . join ( '/' ) ;
51- const key = this . $map . get ( path ) ;
52- if ( key ) {
53- this . setClassName ( key , CLASS_ACTIVE ) ;
50+ const item = this . $map . get ( path ) ;
51+ if ( item ) {
52+ this . setClassName ( item , CLASS_ACTIVE ) ;
5453 }
5554 }
5655
@@ -64,8 +63,8 @@ export default class Nav extends View {
6463 } ) ;
6564 } else {
6665 const navLink = new URL ( node . href ) . pathname . pathSplit ( ) . join ( '/' ) ;
67- if ( node . parentNode . id ) {
68- this . $map . set ( navLink , node . parentNode . id ) ;
66+ if ( node . parentNode . tagName === 'LI' ) {
67+ this . $map . set ( navLink , node . parentNode ) ;
6968 }
7069 }
7170 }
@@ -74,12 +73,12 @@ export default class Nav extends View {
7473 * Set a class name on a specific navigational item and remove
7574 * that class from other navigational items. Usually this is used
7675 * to mark a specific dropdown item as active, for example.
77- * @param {string } key - The id of the navigational item
76+ * @param {Node } node - The navigational <li> which contains a link
7877 * @param {string } className - The class name which indicates
7978 */
80- setClassName ( key , className ) {
79+ setClassName ( node , className ) {
8180 this . queryAll ( 'li a.nav-link' ) . forEach ( ( elem ) => {
82- if ( elem . parentNode . id === key ) {
81+ if ( elem . parentNode === node ) {
8382 elem . classList . add ( className ) ;
8483 } else {
8584 elem . classList . remove ( className ) ;
0 commit comments