Skip to content

Commit 87409ea

Browse files
authored
resolves #59 add expand/collapse all toggle to nav (PR #60)
1 parent fcdb172 commit 87409ea

File tree

4 files changed

+88
-5
lines changed

4 files changed

+88
-5
lines changed

src/css/nav.css

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,34 @@
103103
position: relative;
104104
}
105105

106+
.nav-menu-toggle {
107+
background: transparent url(../img/octicons-24.svg#view-unfold) no-repeat center;
108+
border: none;
109+
outline: none;
110+
width: 0.9rem;
111+
height: 0.9rem;
112+
opacity: 0.5;
113+
position: sticky;
114+
top: 0.8075rem;
115+
margin-right: -0.5rem;
116+
float: right;
117+
visibility: hidden;
118+
}
119+
120+
.nav-menu-toggle.is-active {
121+
background-image: url(../img/octicons-24.svg#view-fold);
122+
}
123+
124+
.nav-panel-menu.is-active:hover .nav-menu-toggle {
125+
visibility: visible;
126+
}
127+
106128
.nav-menu h3.title {
107129
color: var(--nav-heading-font-color);
108-
font-size: 1.05em;
130+
font-size: 0.9rem;
109131
font-weight: var(--body-font-weight-bold);
110-
margin: 0;
111-
padding-top: 0.25em;
132+
margin: 0.15rem 0 0;
133+
padding: 0;
112134
}
113135

114136
.nav-menu a {

src/img/octicons-24.svg

Lines changed: 46 additions & 0 deletions
Loading

src/js/01-nav.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
menuPanel.scrollTop = 0
2323
}
2424

25+
menuPanel.querySelector('.nav-menu-toggle').addEventListener('click', function () {
26+
var collapse = !this.classList.toggle('is-active')
27+
find(menuPanel, '.nav-item > .nav-item-toggle').forEach(function (btn) {
28+
collapse ? btn.parentElement.classList.remove('is-active') : btn.parentElement.classList.add('is-active')
29+
})
30+
if (currentPageItem) {
31+
if (collapse) activateCurrentPath(currentPageItem, false)
32+
scrollItemToMidpoint(menuPanel, currentPageItem.querySelector('.nav-link'))
33+
} else if (collapse) {
34+
menuPanel.scrollTop = 0
35+
}
36+
})
37+
2538
find(menuPanel, '.nav-item-toggle').forEach(function (btn) {
2639
var li = btn.parentElement
2740
btn.addEventListener('click', toggleActive.bind(li))
@@ -87,12 +100,13 @@
87100
window.addEventListener('hashchange', onHashChange)
88101
}
89102

90-
function activateCurrentPath (navItem) {
103+
function activateCurrentPath (navItem, trace) {
91104
var ancestorClasses
92105
var ancestor = navItem.parentNode
93106
while (!(ancestorClasses = ancestor.classList).contains('nav-menu')) {
94107
if (ancestor.tagName === 'LI' && ancestorClasses.contains('nav-item')) {
95-
ancestorClasses.add('is-active', 'is-current-path')
108+
ancestorClasses.add('is-active')
109+
if (trace !== false) ancestorClasses.add('is-current-path')
96110
}
97111
ancestor = ancestor.parentNode
98112
}

src/partials/nav-menu.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{#with page.navigation}}
22
<div class="nav-panel-menu is-active" data-panel="menu">
33
<nav class="nav-menu">
4+
<button class="nav-menu-toggle" title="Toggle expand/collapse all"></button>
45
{{#with @root.page.componentVersion}}
56
<h3 class="title"><a href="{{{relativize ./url}}}">{{./title}}</a></h3>
67
{{/with}}

0 commit comments

Comments
 (0)