Skip to content

Commit 6229cb7

Browse files
committed
Updated for nav and list
1 parent 04c4e85 commit 6229cb7

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

js/list.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ export default class List extends View {
5353
/**
5454
* Add or update an existing row. When adding a row, it is cloned from the template
5555
* and added to the end of the view element.
56-
* @param {Model} obj - The object which should be represented in the view.
5756
* @param {string} key - A unique identifier for the row.
5857
* @returns View - The view added or to be updated in the list
5958
* @fires List#list:click
6059
*/
61-
set(obj, key) {
60+
set(key) {
6261
let row = this.getForKey(key);
6362

6463
// Clone a row

js/nav.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -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);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@djthorpe/js-framework",
3-
"version": "0.0.37",
3+
"version": "0.0.38",
44
"description": "Javascript Framework",
55
"main": "dist/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)