Skip to content

Commit 6e36cac

Browse files
committed
Expand only Learn the Basics
1 parent 7c7f0ed commit 6e36cac

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

_static/js/custom.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
document.addEventListener("DOMContentLoaded", function() {
22
// Select all <li> elements with the class "toctree-l1"
33
var toctreeItems = document.querySelectorAll('li.toctree-l1');
4+
45
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');
68
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+
});
1037
}
1138
});
1239
});

0 commit comments

Comments
 (0)