| |
| document.addEventListener('DOMContentLoaded', function() { |
| const sidebar = document.querySelector('.wy-nav-side'); |
| const content = document.querySelector('.wy-nav-content-wrap'); |
| |
| if (!sidebar || !content) return; |
| |
| |
| const resizeHandle = document.createElement('div'); |
| resizeHandle.className = 'resize-handle'; |
| sidebar.appendChild(resizeHandle); |
| |
| let isResizing = false; |
| let startX = 0; |
| let startWidth = 0; |
| |
| |
| const getInitialWidth = () => { |
| return 300; |
| }; |
| |
| |
| const saveWidth = (width) => { |
| localStorage.setItem('sidebar-width', width); |
| }; |
| |
| |
| const loadWidth = () => { |
| const savedWidth = localStorage.getItem('sidebar-width'); |
| if (savedWidth) { |
| const width = parseInt(savedWidth, 10); |
| if (width >= 200 && width <= 600) { |
| return width; |
| } |
| } |
| return getInitialWidth(); |
| }; |
| |
| |
| const applyWidth = (width) => { |
| |
| sidebar.style.width = width + 'px'; |
| |
| |
| content.style.setProperty('margin-left', width + 'px', 'important'); |
| |
| |
| const contentInner = document.querySelector('.wy-nav-content'); |
| if (contentInner) { |
| contentInner.style.setProperty('margin-left', '0px', 'important'); |
| } |
| |
| |
| sidebar.offsetHeight; |
| content.offsetHeight; |
| |
| |
| window.dispatchEvent(new Event('resize')); |
| }; |
| |
| |
| const initialWidth = loadWidth(); |
| applyWidth(initialWidth); |
| |
| |
| resizeHandle.addEventListener('mousedown', (e) => { |
| isResizing = true; |
| startX = e.clientX; |
| startWidth = parseInt(window.getComputedStyle(sidebar).width, 10); |
| |
| sidebar.classList.add('resizing'); |
| document.body.style.cursor = 'col-resize'; |
| document.body.style.userSelect = 'none'; |
| |
| |
| const overlay = document.createElement('div'); |
| overlay.style.cssText = ` |
| position: fixed; |
| top: 0; |
| left: 0; |
| width: 100%; |
| height: 100%; |
| z-index: 9999; |
| cursor: col-resize; |
| `; |
| overlay.id = 'resize-overlay'; |
| document.body.appendChild(overlay); |
| |
| e.preventDefault(); |
| }); |
| |
| |
| document.addEventListener('mousemove', (e) => { |
| if (!isResizing) return; |
| |
| const width = startWidth + e.clientX - startX; |
| const clampedWidth = Math.max(200, Math.min(600, width)); |
| applyWidth(clampedWidth); |
| }); |
| |
| |
| document.addEventListener('mouseup', () => { |
| if (!isResizing) return; |
| |
| isResizing = false; |
| sidebar.classList.remove('resizing'); |
| document.body.style.cursor = ''; |
| document.body.style.userSelect = ''; |
| |
| |
| const overlay = document.getElementById('resize-overlay'); |
| if (overlay) { |
| overlay.remove(); |
| } |
| |
| |
| const currentWidth = parseInt(window.getComputedStyle(sidebar).width, 10); |
| saveWidth(currentWidth); |
| }); |
| |
| |
| |
| |
| |
| resizeHandle.addEventListener('dblclick', () => { |
| const defaultWidth = 300; |
| applyWidth(defaultWidth); |
| saveWidth(defaultWidth); |
| }); |
| }); |
|
|
| |
| document.addEventListener('DOMContentLoaded', function() { |
| let navigationFixed = false; |
| |
| function setupNavigationFix() { |
| if (navigationFixed) return; |
| |
| |
| const sidebarLinks = document.querySelectorAll('.wy-menu-vertical a'); |
| |
| |
| if (sidebarLinks.length === 0) return; |
| |
| console.log('Setting up navigation fix...'); |
| |
| sidebarLinks.forEach(function(link) { |
| const href = link.getAttribute('href'); |
| |
| |
| const newLink = link.cloneNode(true); |
| |
| |
| newLink.addEventListener('click', function(e) { |
| console.log('Link clicked:', href); |
| |
| |
| if (href && href.startsWith('#') && href !== '#') { |
| e.preventDefault(); |
| e.stopPropagation(); |
| |
| const targetId = href.substring(1); |
| const targetElement = document.getElementById(targetId); |
| |
| if (targetElement) { |
| |
| const headerHeight = 60; |
| const elementPosition = targetElement.getBoundingClientRect().top; |
| const offsetPosition = elementPosition + window.pageYOffset - headerHeight; |
| |
| window.scrollTo({ |
| top: offsetPosition, |
| behavior: 'smooth' |
| }); |
| |
| |
| if (history.pushState) { |
| history.pushState(null, null, '#' + targetId); |
| } else { |
| location.hash = '#' + targetId; |
| } |
| } |
| } |
| |
| else if (href && !href.startsWith('#') && !href.startsWith('javascript:')) { |
| console.log('Navigating to external link:', href); |
| window.location.href = href; |
| } |
| }); |
| |
| |
| link.parentNode.replaceChild(newLink, link); |
| }); |
| |
| navigationFixed = true; |
| |
| |
| if (window.location.hash) { |
| |
| requestAnimationFrame(() => { |
| const targetId = window.location.hash.substring(1); |
| const targetElement = document.getElementById(targetId); |
| if (targetElement) { |
| const headerHeight = 60; |
| const elementPosition = targetElement.getBoundingClientRect().top; |
| const offsetPosition = elementPosition + window.pageYOffset - headerHeight; |
| |
| window.scrollTo({ |
| top: offsetPosition, |
| behavior: 'smooth' |
| }); |
| } |
| }); |
| } |
| } |
| |
| |
| setupNavigationFix(); |
| |
| |
| if (!navigationFixed) { |
| const observer = new MutationObserver(function(mutations) { |
| mutations.forEach(function(mutation) { |
| if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { |
| |
| const sidebarLinks = document.querySelectorAll('.wy-menu-vertical a'); |
| if (sidebarLinks.length > 0) { |
| setupNavigationFix(); |
| if (navigationFixed) { |
| observer.disconnect(); |
| } |
| } |
| } |
| }); |
| }); |
| |
| |
| observer.observe(document.body, { |
| childList: true, |
| subtree: true |
| }); |
| |
| |
| setTimeout(function() { |
| if (!navigationFixed) { |
| setupNavigationFix(); |
| } |
| observer.disconnect(); |
| }, 5000); |
| } |
| }); |