Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Commit 3826be4

Browse files
author
Matthew Gaunt
committed
Merge pull request #14 from addyosmani/selected-item
Add menu highlighting based on route
2 parents 3efe29e + df2a119 commit 3826be4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/scripts/controller/ActivityController.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export default class ActivityController {
1414
// Show loading dialog while we get content
1515
this.loader.classList.remove('is-hidden');
1616

17+
this.updateNavDrawer(path);
18+
1719
fetch('/partials' + path)
1820
.then((response) => {
1921
if (response.status === 404) {
@@ -61,4 +63,17 @@ export default class ActivityController {
6163
', sorry about that.';
6264
this.mainContainer.appendChild(paragraphElement);
6365
}
66+
67+
updateNavDrawer(path) {
68+
var nodeList = document.querySelectorAll('.side-nav__body a');
69+
[].forEach.call(nodeList, function(el) {
70+
// Reset active states
71+
el.classList.remove('active');
72+
// We could compare against path, but easier to compare
73+
// against the current document href
74+
if (el.href === document.location.href) {
75+
el.classList.add('active');
76+
}
77+
});
78+
}
6479
}

src/styles/core/_side-nav.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,8 @@
134134
line-height: 48px;
135135
text-decoration: none;
136136
}
137+
138+
.side-nav__blog-post.active {
139+
font-weight: bold;
140+
background-color: rgba(0,0,0,.05);
141+
}

0 commit comments

Comments
 (0)