Skip to content

Commit d6a877c

Browse files
committed
Add README.md
1 parent d87eb28 commit d6a877c

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
### How to use bs5-nav-tree v0.2
2+
#### Initializing the tree
3+
1. Make sure you have a list object with id "nav-tree" like ``<ul id="nav-tree"></ul>`` and, all list items must have its own id like ``<li id="li1"></li>``. If you want to search on tree add "data-searchable" attribute to the list, and if you want to show empty groups after search add "data-show-empty-groups" attribute to the list.
4+
5+
For example:
6+
```html
7+
<ul id="nav-tree" data-searchable data-show-empty-groups>
8+
<li id="li8">
9+
<a>
10+
Collapse 3
11+
</a>
12+
<ul>
13+
<li id="li9">
14+
<a href="#">
15+
Link 4
16+
</a>
17+
</li>
18+
<li id="li10">
19+
<a href="#">
20+
Link 5
21+
</a>
22+
</li>
23+
</ul>
24+
</li>
25+
</ul>
26+
```
27+
2. Add this to your js file:
28+
```js
29+
const nav = new NavTree({ obj_id: "#nav-tree" });
30+
```
31+
32+
#### Updating the tree
33+
```js
34+
nav.update(menu_html);
35+
```
36+
37+
### How to use bs5-nav-tree v0.1
38+
__This is a very primitive version, so I do NOT recommend using it.__ But you want to use it:
39+
#### Initializing the tree
40+
1. Make sure you have a list object with id "menu-tree". All elements of the list must have an id. If you want to search on tree add "searchable" attribute to the list, and if you want to show empty groups after search add "show-empty" attribute to the list.
41+
42+
For example:
43+
```html
44+
<ul id="menu-tree" searchable show-empty>
45+
<li id="li8">
46+
<a id="a8">
47+
Collapse 3
48+
</a>
49+
<ul id="ul3">
50+
<li id="li9">
51+
<a id="a9" href="#">
52+
Link 4
53+
</a>
54+
</li>
55+
<li id="li10">
56+
<a id="a10" href="#">
57+
Link 5
58+
</a>
59+
</li>
60+
</ul>
61+
</li>
62+
</ul>
63+
```
64+
65+
1. Add this to your js file:
66+
```js
67+
let menu = document.querySelector('#menu-tree');
68+
69+
init_tree(menu);
70+
71+
if (menu.getAttribute("searchable") !== null) {
72+
menu.parentElement.prepend(htmlToElement(searchInput));
73+
74+
init_search(menu.getAttribute("show-empty") !== null);
75+
}
76+
```
77+
#### Updating the tree
78+
```js
79+
update_tree(menu, menu_html)
80+
```
81+

0 commit comments

Comments
 (0)