@@ -38,7 +38,6 @@ export default class Nav extends View {
38
38
this . $map = new Map ( ) ;
39
39
40
40
// Set up nav items - those with HREF # dispatch events
41
- console . log ( 'subnav' , this . queryAll ( 'li a.nav-link' ) ) ;
42
41
this . queryAll ( 'li a.nav-link' ) . forEach ( ( elem ) => {
43
42
this . $set ( elem ) ;
44
43
} ) ;
@@ -48,9 +47,9 @@ export default class Nav extends View {
48
47
49
48
// Determine current path and set the active link
50
49
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 ) ;
54
53
}
55
54
}
56
55
@@ -64,8 +63,8 @@ export default class Nav extends View {
64
63
} ) ;
65
64
} else {
66
65
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 ) ;
69
68
}
70
69
}
71
70
}
@@ -74,12 +73,12 @@ export default class Nav extends View {
74
73
* Set a class name on a specific navigational item and remove
75
74
* that class from other navigational items. Usually this is used
76
75
* 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
78
77
* @param {string } className - The class name which indicates
79
78
*/
80
- setClassName ( key , className ) {
79
+ setClassName ( node , className ) {
81
80
this . queryAll ( 'li a.nav-link' ) . forEach ( ( elem ) => {
82
- if ( elem . parentNode . id === key ) {
81
+ if ( elem . parentNode === node ) {
83
82
elem . classList . add ( className ) ;
84
83
} else {
85
84
elem . classList . remove ( className ) ;
0 commit comments