User:Knightmare/common.js

From ARMCO
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
    // Create a function to enable the collapse/expand functionality
    function addCollapseExpand() {
        // Add a toggle button for each nested list
        var subLists = toc.querySelectorAll('ul');

        subLists.forEach(function(subList) {
            // Create a button to toggle the sublist
            var toggleButton = document.createElement('button');
            toggleButton.textContent = '▸';  // Right arrow for collapsed state
            toggleButton.classList.add('toc-toggle');
            subList.parentElement.insertBefore(toggleButton, subList);

            // Set up event listener to handle the click (toggle state)
            toggleButton.addEventListener('click', function() {
                if (subList.style.display === 'none') {
                    subList.style.display = 'block';  // Expand the list
                    toggleButton.textContent = '▸'; // Change button to right arrow
                } else {
                    subList.style.display = 'none';  // Collapse the list
                    toggleButton.textContent = '▶'; // Change button to down arrow
                }
            });
        });
    }

    // Run the collapse/expand functionality
    addCollapseExpand();
})();