Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/main/_static/js/custom.js
Views: 713
document.addEventListener("DOMContentLoaded", function() {1// Select all <li> elements with the class "toctree-l1"2var toctreeItems = document.querySelectorAll('li.toctree-l1');34toctreeItems.forEach(function(item) {5// Find the link within the item6var link = item.querySelector('a');7var nestedList = item.querySelector('ul');89if (link && nestedList) {10// Create a span element for the "[+]" or "[-]" sign11var expandSign = document.createElement('span');12expandSign.style.cursor = 'pointer'; // Make it look clickable1314// Use the link text as a unique key for localStorage15var sectionKey = 'section_' + link.textContent.trim().replace(/\s+/g, '_');1617// Retrieve the saved state from localStorage18var isExpanded = localStorage.getItem(sectionKey);1920// If no state is saved, default to expanded for "Learn the Basics" and collapsed for others21if (isExpanded === null) {22isExpanded = (link.textContent.trim() === 'Learn the Basics') ? 'true' : 'false';23localStorage.setItem(sectionKey, isExpanded);24}2526if (isExpanded === 'true') {27nestedList.style.display = 'block'; // Expand the section28expandSign.textContent = '[-] '; // Show "[-]" since it's expanded29} else {30nestedList.style.display = 'none'; // Collapse the section31expandSign.textContent = '[+] '; // Show "[+]" since it's collapsed32}3334// Add a click event to toggle the nested list35expandSign.addEventListener('click', function() {36if (nestedList.style.display === 'none') {37nestedList.style.display = 'block';38expandSign.textContent = '[-] '; // Change to "[-]" when expanded39localStorage.setItem(sectionKey, 'true'); // Save state40} else {41nestedList.style.display = 'none';42expandSign.textContent = '[+] '; // Change back to "[+]" when collapsed43localStorage.setItem(sectionKey, 'false'); // Save state44}45});4647// Insert the sign before the link48link.parentNode.insertBefore(expandSign, link);49}50});51});525354