Skip to content

Commit 81cdebe

Browse files
committed
Remember user selection for collapsed/uncollapsed content; remove the bullet from the list
1 parent 47d2821 commit 81cdebe

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

_static/css/custom2.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@
3131
.pytorch-left-menu li.toctree-l2.current a:link.reference.internal {
3232
color: #ee4c2c;
3333
}
34+
35+
.pytorch-left-menu li.toctree-l1.current > a:before {
36+
content: "";
37+
}

_static/js/custom.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,41 @@ document.addEventListener("DOMContentLoaded", function() {
1212
var expandSign = document.createElement('span');
1313
expandSign.style.cursor = 'pointer'; // Make it look clickable
1414

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
15+
// Use the link text as a unique key for localStorage
16+
var sectionKey = 'section_' + link.textContent.trim().replace(/\s+/g, '_');
17+
18+
// Retrieve the saved state from localStorage
19+
var isExpanded = localStorage.getItem(sectionKey);
20+
21+
// If no state is saved, default to expanded for "Learn the Basics" and collapsed for others
22+
if (isExpanded === null) {
23+
isExpanded = (link.textContent.trim() === 'Learn the Basics') ? 'true' : 'false';
24+
localStorage.setItem(sectionKey, isExpanded);
25+
}
26+
27+
if (isExpanded === 'true') {
28+
nestedList.style.display = 'block'; // Expand the section
1829
expandSign.textContent = '[-] '; // Show "[-]" since it's expanded
1930
} else {
20-
nestedList.style.display = 'none'; // Collapse other sections
31+
nestedList.style.display = 'none'; // Collapse the section
2132
expandSign.textContent = '[+] '; // Show "[+]" since it's collapsed
2233
}
2334

24-
// Insert the sign before the link
25-
link.parentNode.insertBefore(expandSign, link);
26-
2735
// Add a click event to toggle the nested list
2836
expandSign.addEventListener('click', function() {
2937
if (nestedList.style.display === 'none') {
3038
nestedList.style.display = 'block';
3139
expandSign.textContent = '[-] '; // Change to "[-]" when expanded
40+
localStorage.setItem(sectionKey, 'true'); // Save state
3241
} else {
3342
nestedList.style.display = 'none';
3443
expandSign.textContent = '[+] '; // Change back to "[+]" when collapsed
44+
localStorage.setItem(sectionKey, 'false'); // Save state
3545
}
3646
});
47+
48+
// Insert the sign before the link
49+
link.parentNode.insertBefore(expandSign, link);
3750
}
3851
});
3952
});

0 commit comments

Comments
 (0)