Compare commits
12 Commits
b96012f598
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ea8b3f6b6 | |||
| d52968e697 | |||
| bed7137e43 | |||
| 028e0b11c7 | |||
| 5bf43abab9 | |||
| f96ad4d14f | |||
| a4aff43091 | |||
| 1e20982e00 | |||
| ec7aaf44a9 | |||
| 00a5951654 | |||
| 8dba510a6c | |||
| e66ece71e3 |
@@ -200,6 +200,7 @@ class="absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg py-1 ring-1 ring
|
||||
<div class="flex h-[calc(100vh-4rem)]">
|
||||
<!-- Sidebar - Desktop -->
|
||||
<aside
|
||||
id="kb-sidebar"
|
||||
class="hidden lg:block bg-white border-r border-gray-200 overflow-y-auto relative"
|
||||
:style="'width: ' + sidebarWidth + 'px'"
|
||||
>
|
||||
@@ -258,6 +259,91 @@ class="fixed inset-y-0 left-0 top-16 w-64 bg-white border-r border-gray-200 over
|
||||
|
||||
<!-- Global Keyboard Shortcuts -->
|
||||
<script>
|
||||
// Preserve sidebar scroll position during navigation
|
||||
document.addEventListener('click', function(e) {
|
||||
const sidebar = document.getElementById('kb-sidebar');
|
||||
if (!sidebar) return;
|
||||
|
||||
const link = e.target.closest('a');
|
||||
if (link && sidebar.contains(link)) {
|
||||
const scrollPos = sidebar.scrollTop;
|
||||
sessionStorage.setItem('kb_sidebar_scroll', scrollPos);
|
||||
}
|
||||
}, true);
|
||||
|
||||
// Restore scroll position after page load
|
||||
function restoreSidebarScroll() {
|
||||
const sidebar = document.getElementById('kb-sidebar');
|
||||
if (!sidebar) return;
|
||||
|
||||
const savedPos = sessionStorage.getItem('kb_sidebar_scroll');
|
||||
if (savedPos !== null && savedPos !== '0') {
|
||||
sidebar.scrollTop = parseInt(savedPos, 10);
|
||||
}
|
||||
}
|
||||
|
||||
// Highlight current document in sidebar
|
||||
function highlightCurrentDocument() {
|
||||
const sidebar = document.getElementById('kb-sidebar');
|
||||
if (!sidebar) {
|
||||
console.log('Sidebar not found for highlighting');
|
||||
return;
|
||||
}
|
||||
|
||||
const currentPath = window.location.pathname;
|
||||
const links = sidebar.querySelectorAll('a');
|
||||
|
||||
console.log('Current path:', currentPath);
|
||||
console.log('Found links in sidebar:', links.length);
|
||||
|
||||
links.forEach(link => {
|
||||
const href = link.getAttribute('href');
|
||||
|
||||
// Remove previous highlighting
|
||||
link.classList.remove('bg-indigo-50', 'text-indigo-700', 'font-semibold');
|
||||
link.classList.add('text-gray-700');
|
||||
|
||||
const icon = link.querySelector('svg');
|
||||
if (icon) {
|
||||
icon.classList.remove('text-indigo-600');
|
||||
icon.classList.add('text-gray-400', 'group-hover:text-gray-600');
|
||||
}
|
||||
|
||||
// Check if this is the current page
|
||||
if (href === currentPath || href === window.location.href ||
|
||||
(href && currentPath && href.endsWith(currentPath))) {
|
||||
console.log('Matched link:', href, 'with current path:', currentPath);
|
||||
link.classList.add('bg-indigo-50', 'text-indigo-700', 'font-semibold');
|
||||
link.classList.remove('text-gray-700');
|
||||
|
||||
if (icon) {
|
||||
icon.classList.remove('text-gray-400', 'group-hover:text-gray-600');
|
||||
icon.classList.add('text-indigo-600');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Restore on page load
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
restoreSidebarScroll();
|
||||
highlightCurrentDocument();
|
||||
});
|
||||
} else {
|
||||
restoreSidebarScroll();
|
||||
highlightCurrentDocument();
|
||||
}
|
||||
|
||||
// Also restore on window load (for safety)
|
||||
window.addEventListener('load', () => {
|
||||
restoreSidebarScroll();
|
||||
highlightCurrentDocument();
|
||||
});
|
||||
|
||||
// Update highlight after Alpine navigation
|
||||
document.addEventListener('alpine:navigated', highlightCurrentDocument);
|
||||
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user