-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nested groups support in side nav
- Loading branch information
Showing
7 changed files
with
208 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.listree-submenu-heading { | ||
cursor: pointer | ||
} | ||
|
||
ul.listree { | ||
list-style: none | ||
} | ||
|
||
ul.listree-submenu-items { | ||
list-style: none; | ||
white-space: nowrap; | ||
padding-left: 10px | ||
} | ||
|
||
div.listree-submenu-heading.collapsed:before { | ||
content: "\25B6"; | ||
margin-right: 4px | ||
} | ||
|
||
div.listree-submenu-heading.expanded:before { | ||
content: "\25BC"; | ||
margin-right: 4px | ||
} | ||
|
||
.scrollable-menu { | ||
height: auto; | ||
max-width: 800px; | ||
overflow-y: hidden | ||
} | ||
|
||
.menu-list li ul { | ||
border-left: 0; | ||
margin: .25em; | ||
padding-left: .75em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
function listree() { | ||
|
||
const subMenuHeadingClass = "listree-submenu-heading"; | ||
const expandedClass = "expanded"; | ||
const collapsedClass = "collapsed"; | ||
const activeClass = "is-active"; | ||
const subMenuHeadings = document.getElementsByClassName(subMenuHeadingClass); | ||
|
||
Array | ||
.from(subMenuHeadings) | ||
.forEach(function(subMenuHeading) { | ||
// Collapse all the subMenuHeadings while searching for is-active class | ||
let foundActive = false; | ||
subMenuHeading.classList.add(collapsedClass); | ||
subMenuHeading.nextElementSibling.style.display = "none"; | ||
|
||
// Check if this sub-menu heading is active | ||
const liElements = subMenuHeading.nextElementSibling.children; | ||
for (let i = 0; i < liElements.length; i++) { | ||
if (liElements[i].hasChildNodes()) { | ||
if (liElements[i].children[0].tagName === "A") { | ||
if (liElements[i].children[0].classList.contains(activeClass)) { | ||
foundActive = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Expand all parent sub-menus until root menu is reached | ||
if (foundActive) { | ||
subMenuHeading.classList.remove(collapsedClass); | ||
subMenuHeading.classList.add(expandedClass); | ||
subMenuHeading.nextElementSibling.style.display = "block"; | ||
|
||
let currentSubMenu = subMenuHeading.parentElement; | ||
while (currentSubMenu !== null && !currentSubMenu.classList.contains("listree")) { | ||
if(currentSubMenu.tagName === "UL"){ | ||
if(currentSubMenu.previousElementSibling != null) { | ||
currentSubMenu.previousElementSibling.classList.remove(collapsedClass); | ||
currentSubMenu.previousElementSibling.classList.add(expandedClass); | ||
currentSubMenu.style.display = "block"; | ||
} | ||
} | ||
currentSubMenu = currentSubMenu.parentElement | ||
} | ||
} | ||
|
||
// Add the eventlistener to all subMenuHeadings | ||
subMenuHeading.addEventListener("click", function(event) { | ||
event.preventDefault(); | ||
const subMenuList = event.target.nextElementSibling; | ||
if (subMenuList.style.display === "none") { | ||
subMenuHeading.classList.remove(collapsedClass); | ||
subMenuHeading.classList.add(expandedClass); | ||
subMenuHeading.nextElementSibling.style.display = "block"; | ||
} else { | ||
subMenuHeading.classList.remove(expandedClass); | ||
subMenuHeading.classList.add(collapsedClass); | ||
subMenuHeading.nextElementSibling.style.display = "none"; | ||
} | ||
event.stopPropagation(); | ||
}); | ||
}); | ||
} |