|
1 | 1 | document.addEventListener("DOMContentLoaded", function() {
|
2 | 2 | // Select all <li> elements with the class "toctree-l1"
|
3 | 3 | var toctreeItems = document.querySelectorAll('li.toctree-l1');
|
| 4 | + |
4 | 5 | toctreeItems.forEach(function(item) {
|
5 |
| - // Check if the item has a nested <ul> |
| 6 | + // Find the link within the item |
| 7 | + var link = item.querySelector('a'); |
6 | 8 | var nestedList = item.querySelector('ul');
|
7 |
| - if (nestedList) { |
8 |
| - // Display the nested list by default |
9 |
| - nestedList.style.display = 'block'; |
| 9 | + |
| 10 | + if (link && nestedList) { |
| 11 | + // Create a span element for the "[+]" or "[-]" sign |
| 12 | + var expandSign = document.createElement('span'); |
| 13 | + expandSign.style.cursor = 'pointer'; // Make it look clickable |
| 14 | + |
| 15 | + // Check if this is the "Learn the Basics" section |
| 16 | + if (link.textContent.trim() === 'Learn the Basics') { |
| 17 | + nestedList.style.display = 'block'; // Expand the "Learn the Basics" section |
| 18 | + expandSign.textContent = '[-] '; // Show "[-]" since it's expanded |
| 19 | + } else { |
| 20 | + nestedList.style.display = 'none'; // Collapse other sections |
| 21 | + expandSign.textContent = '[+] '; // Show "[+]" since it's collapsed |
| 22 | + } |
| 23 | + |
| 24 | + // Insert the sign before the link |
| 25 | + link.parentNode.insertBefore(expandSign, link); |
| 26 | + |
| 27 | + // Add a click event to toggle the nested list |
| 28 | + expandSign.addEventListener('click', function() { |
| 29 | + if (nestedList.style.display === 'none') { |
| 30 | + nestedList.style.display = 'block'; |
| 31 | + expandSign.textContent = '[-] '; // Change to "[-]" when expanded |
| 32 | + } else { |
| 33 | + nestedList.style.display = 'none'; |
| 34 | + expandSign.textContent = '[+] '; // Change back to "[+]" when collapsed |
| 35 | + } |
| 36 | + }); |
10 | 37 | }
|
11 | 38 | });
|
12 | 39 | });
|
0 commit comments