tree.js 853 B

1234567891011121314151617181920212223242526272829
  1. const CLASSNAME_EXPANDED = "bi bi-chevron-down";
  2. const CLASSNAME_COLLAPSED = "bi bi-chevron-up";
  3. window["makeTree"] = function (ulRoot) {
  4. let makeTree = (li) => {
  5. let button = li.children[0];
  6. let list = li.children[1];
  7. if (button && list && button.nodeName == 'SPAN' && list.nodeName == 'UL') {
  8. button.className = CLASSNAME_COLLAPSED;
  9. list.style.display = 'block';
  10. button.addEventListener("click", (e) => {
  11. let visible = list.style.display === 'block';
  12. if (visible) {
  13. button.className = CLASSNAME_EXPANDED;
  14. list.style.display = "none";
  15. } else {
  16. button.className = CLASSNAME_COLLAPSED;
  17. list.style.display = "block";
  18. }
  19. });
  20. for (var i = 0; i < list.children.length; ++i)
  21. makeTree(list.children[i]);
  22. }
  23. };
  24. for (var i = 0; i < ulRoot.children.length; ++i)
  25. makeTree(ulRoot.children[i]);
  26. }