Skip to content

Commit c433541

Browse files
committed
wip: Provide comments for code
1 parent 8750535 commit c433541

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,49 @@
11
(function () {
22
const menuCollapse = function (hook, vm) {
3-
3+
// Hook to execute after the page is fully loaded https://github.com/docsifyjs/docsify/blob/develop/docs/write-a-plugin.md
44
hook.doneEach(() => {
5-
65
const parentItems = document.querySelectorAll('.sidebar-nav > ul > li');
76

87
parentItems.forEach(item => {
8+
/**
9+
* Skip items that already have link or not rendered
10+
* Check on empty string required because an original docsify menu does not provide hooks after load
11+
*/
12+
if (item.firstChild.nodeType !== Node.TEXT_NODE || item.firstChild.textContent.trim() === "") return;
13+
14+
// Check if the parent item has a sublist
915
const sublist = item.querySelector('ul');
1016

1117
if (sublist) {
18+
// Check if any nested items in the sublist have the 'active' class
1219
const nestedItems = sublist.querySelectorAll('li');
1320
const hasActiveItems = Array.from(nestedItems).some(nestedItem => nestedItem.classList.contains('active'));
1421

15-
if (item.firstChild.nodeType !== Node.TEXT_NODE || item.firstChild.textContent.trim() === "") {
16-
return
17-
}
18-
22+
/**
23+
* Add the 'collapse' class to items without active nested items, otherwise add 'active'
24+
* That is need to highlight menu item on a page load when subitem is active
25+
*/
1926
if (!hasActiveItems) {
2027
item.classList.add('collapse');
2128
} else {
2229
item.classList.add('active');
2330
item.classList.remove('collapse');
2431
}
2532

33+
// Add class to sublist
2634
sublist.classList.add('app-sub-sidebar');
2735

36+
// Wrap text item in a link to follow default menu behavior and classes
2837
const textNode = item.firstChild;
2938
const link = document.createElement('a');
3039
link.href = '#/';
3140
link.textContent = textNode.textContent;
3241
textNode.parentNode.replaceChild(link, textNode);
3342

34-
43+
// Add click event listener to link to prevent default behavior
3544
link.addEventListener('click', (e) => {
3645
e.preventDefault();
46+
// Close all other collapsed items when a link is clicked
3747
parentItems.forEach(otherItem => {
3848
if (otherItem !== item) {
3949
otherItem.classList.remove('collapse');
@@ -45,7 +55,7 @@
4555
});
4656
};
4757

48-
// Add plugin to docsify's plugin array
58+
// Add the plugin to the Docsify plugin array
4959
$docsify = $docsify || {};
5060
$docsify.plugins = [].concat(menuCollapse, $docsify.plugins || []);
5161
})();

html/docs/_sidebar.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1 @@
1-
- [Getting Started](start/before-you-start.md)
2-
- [Before You start](start/before-you-start.md)
3-
- [Requirements](start/requirements.md)
4-
- [Installation](start/installation.md)
5-
- [Docker Containers](start/docker-containers.md)
6-
- [Makefiles Reference](start/makefile-reference.md)
7-
- [Environment Variables](start/environment-variables.md)
8-
- [Sitemap](start/sitemap.md)
9-
- Application Concepts
10-
- [Development Requirements](guides/development-requirements.md)
11-
- [File Replacer](guides/file-replacer.md)
12-
- [Application Structure](guides/application-structure.md)
13-
- [Custom Modules](guides/custom-modules.md)
14-
- [Assets and Styles](guides/styles-assets.md)
15-
- Security
16-
- [Web Security](security/web-security.md)
1+
* [Getting Started](/)

0 commit comments

Comments
 (0)