Fixed sidebar navigation on second scroll
This commit is contained in:
@@ -8,6 +8,7 @@ export default defineConfig({
|
||||
// Example: Generate `page.html` instead of `page/index.html` during build.
|
||||
format: 'file'
|
||||
},
|
||||
compressHTML: false,
|
||||
markdown: {
|
||||
shikiConfig: {
|
||||
theme: 'dark-plus'
|
||||
|
||||
@@ -27,9 +27,14 @@ const Default = {
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const sidebarWrapper = document.querySelector(SELECTOR_SIDEBAR_WRAPPER)
|
||||
|
||||
// Disable OverlayScrollbars on mobile devices to prevent touch interference
|
||||
const isMobile = window.innerWidth <= 992
|
||||
|
||||
if (
|
||||
sidebarWrapper &&
|
||||
OverlayScrollbarsGlobal?.OverlayScrollbars !== undefined
|
||||
OverlayScrollbarsGlobal?.OverlayScrollbars !== undefined &&
|
||||
!isMobile
|
||||
) {
|
||||
OverlayScrollbarsGlobal.OverlayScrollbars(sidebarWrapper, {
|
||||
scrollbars: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* AdminLTE v4.0.0-rc3 (https://adminlte.io)
|
||||
* AdminLTE v4.0.0-rc4 (https://adminlte.io)
|
||||
* Copyright 2014-2025 Colorlib <https://colorlib.com>
|
||||
* Licensed under MIT (https://github.com/ColorlibHQ/AdminLTE/blob/master/LICENSE)
|
||||
*/
|
||||
@@ -641,8 +641,14 @@
|
||||
const sidebar = document.getElementsByClassName(sidebarExpand)[0];
|
||||
const sidebarContent = globalThis.getComputedStyle(sidebar, '::before').getPropertyValue('content');
|
||||
this._config = { ...this._config, sidebarBreakpoint: Number(sidebarContent.replace(/[^\d.-]/g, '')) };
|
||||
// FIXED: Don't auto-collapse on mobile if sidebar is currently open
|
||||
// This prevents resize events (triggered by scrolling) from closing the sidebar
|
||||
const isCurrentlyOpen = document.body.classList.contains(CLASS_NAME_SIDEBAR_OPEN);
|
||||
if (window.innerWidth <= this._config.sidebarBreakpoint) {
|
||||
this.collapse();
|
||||
// Only collapse if not currently open (prevents scroll-triggered closes)
|
||||
if (!isCurrentlyOpen) {
|
||||
this.collapse();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!document.body.classList.contains(CLASS_NAME_SIDEBAR_MINI)) {
|
||||
@@ -682,20 +688,22 @@
|
||||
const sidebarOverlay = document.createElement('div');
|
||||
sidebarOverlay.className = CLASS_NAME_SIDEBAR_OVERLAY;
|
||||
document.querySelector(SELECTOR_APP_WRAPPER)?.append(sidebarOverlay);
|
||||
let isTouchMoved = false;
|
||||
let overlayTouchMoved = false;
|
||||
// Handle touch events on overlay (area outside sidebar)
|
||||
sidebarOverlay.addEventListener('touchstart', () => {
|
||||
isTouchMoved = false;
|
||||
overlayTouchMoved = false;
|
||||
}, { passive: true });
|
||||
sidebarOverlay.addEventListener('touchmove', () => {
|
||||
isTouchMoved = true;
|
||||
overlayTouchMoved = true;
|
||||
}, { passive: true });
|
||||
sidebarOverlay.addEventListener('touchend', event => {
|
||||
if (!isTouchMoved) {
|
||||
if (!overlayTouchMoved) {
|
||||
event.preventDefault();
|
||||
const target = event.currentTarget;
|
||||
const data = new PushMenu(target, Defaults);
|
||||
data.collapse();
|
||||
}
|
||||
overlayTouchMoved = false;
|
||||
}, { passive: false });
|
||||
sidebarOverlay.addEventListener('click', event => {
|
||||
event.preventDefault();
|
||||
|
||||
File diff suppressed because one or more lines are too long
4
src/html/public/js/adminlte.min.js
vendored
4
src/html/public/js/adminlte.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -102,8 +102,15 @@ class PushMenu {
|
||||
const sidebarContent = globalThis.getComputedStyle(sidebar, '::before').getPropertyValue('content')
|
||||
this._config = { ...this._config, sidebarBreakpoint: Number(sidebarContent.replace(/[^\d.-]/g, '')) }
|
||||
|
||||
// FIXED: Don't auto-collapse on mobile if sidebar is currently open
|
||||
// This prevents resize events (triggered by scrolling) from closing the sidebar
|
||||
const isCurrentlyOpen = document.body.classList.contains(CLASS_NAME_SIDEBAR_OPEN)
|
||||
|
||||
if (window.innerWidth <= this._config.sidebarBreakpoint) {
|
||||
this.collapse()
|
||||
// Only collapse if not currently open (prevents scroll-triggered closes)
|
||||
if (!isCurrentlyOpen) {
|
||||
this.collapse()
|
||||
}
|
||||
} else {
|
||||
if (!document.body.classList.contains(CLASS_NAME_SIDEBAR_MINI)) {
|
||||
this.expand()
|
||||
@@ -150,24 +157,28 @@ onDOMContentLoaded(() => {
|
||||
sidebarOverlay.className = CLASS_NAME_SIDEBAR_OVERLAY
|
||||
document.querySelector(SELECTOR_APP_WRAPPER)?.append(sidebarOverlay)
|
||||
|
||||
let isTouchMoved = false
|
||||
let overlayTouchMoved = false
|
||||
|
||||
// Handle touch events on overlay (area outside sidebar)
|
||||
sidebarOverlay.addEventListener('touchstart', () => {
|
||||
isTouchMoved = false
|
||||
overlayTouchMoved = false
|
||||
}, { passive: true })
|
||||
|
||||
sidebarOverlay.addEventListener('touchmove', () => {
|
||||
isTouchMoved = true
|
||||
overlayTouchMoved = true
|
||||
}, { passive: true })
|
||||
|
||||
sidebarOverlay.addEventListener('touchend', event => {
|
||||
if (!isTouchMoved) {
|
||||
if (!overlayTouchMoved) {
|
||||
event.preventDefault()
|
||||
const target = event.currentTarget as HTMLElement
|
||||
const data = new PushMenu(target, Defaults)
|
||||
data.collapse()
|
||||
}
|
||||
overlayTouchMoved = false
|
||||
}, { passive: false })
|
||||
|
||||
|
||||
sidebarOverlay.addEventListener('click', event => {
|
||||
event.preventDefault()
|
||||
const target = event.currentTarget as HTMLElement
|
||||
|
||||
Reference in New Issue
Block a user