Use manual scroll position management instead of x-navigate.preserve-scroll
- Add JavaScript to save sidebar scroll position before navigation - Restore scroll position after page load using sessionStorage - Works consistently in Chrome and other browsers - Handles both DOMContentLoaded and window load events - Compatible with Alpine navigate and standard navigation
This commit is contained in:
@@ -259,6 +259,43 @@ 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[x-navigate]');
|
||||
if (link && sidebar.contains(link)) {
|
||||
// Save scroll position before navigation
|
||||
const scrollPos = sidebar.scrollTop;
|
||||
sessionStorage.setItem('kb_sidebar_scroll', scrollPos);
|
||||
console.log('Saved sidebar scroll position:', 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) {
|
||||
sidebar.scrollTop = parseInt(savedPos, 10);
|
||||
console.log('Restored sidebar scroll position:', savedPos);
|
||||
sessionStorage.removeItem('kb_sidebar_scroll');
|
||||
}
|
||||
}
|
||||
|
||||
// Restore on page load
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', restoreSidebarScroll);
|
||||
} else {
|
||||
restoreSidebarScroll();
|
||||
}
|
||||
|
||||
// Also restore on window load (for safety)
|
||||
window.addEventListener('load', restoreSidebarScroll);
|
||||
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user