// don't let click events propagate outside of navigation container
navContainer.addEventListener('click', concealEvent)
- if (currentPageItem) activateCurrentPath(currentPageItem)
-
find('.nav-menu').forEach(function (navTree) {
var panel = navTree.parentElement.dataset.panel
find('.nav-item', navTree).forEach(function (item, idx) {
})
})
- if (!state.expandedItems) {
- state.expandedItems = getExpandedItems()
- saveState()
- }
+ var expandedItems = state.expandedItems || (state.expandedItems = [])
- state.expandedItems.forEach(function (itemId) {
- var item = document.querySelector('.nav-item[data-id="' + itemId + '"]')
- if (item) {
+ if (expandedItems.length) {
+ find(
+ expandedItems
+ .map(function (itemId) {
+ return '.nav-item[data-id="' + itemId + '"]'
+ })
+ .join(',')
+ ).forEach(function (item) {
item.classList.add('is-active')
- }
- })
+ })
+ }
+
+ if (currentPageItem) {
+ activateCurrentPath(currentPageItem).forEach(function (itemId) {
+ if (expandedItems.indexOf(itemId) < 0) {
+ expandedItems.push(itemId)
+ }
+ })
+ }
saveState()
})
function activateCurrentPath (navItem) {
+ var ids = [navItem.dataset.id]
var ancestorClasses
var ancestor = navItem.parentNode
while (!(ancestorClasses = ancestor.classList).contains('nav-menu')) {
if (ancestor.tagName === 'LI' && ancestorClasses.contains('nav-item')) {
ancestorClasses.add('is-active', 'is-current-path')
+ ids.push(ancestor.dataset.id)
}
ancestor = ancestor.parentNode
}
+ navItem.classList.add('is-active')
+ return ids
}
function toggleNavigation (e) {