fix: sidebar không hoạt động khi click nút menu trên mobile
Lỗi: sidebar.js dùng DOMContentLoaded nhưng script được load động sau khi sự kiện này đã kích hoạt → initSidebar() không bao giờ chạy → nút menu không có event listener → click không phản hồi. Sửa: gọi initSidebar() trực tiếp thay vì bọc trong DOMContentLoaded.
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
// views/components/sidebar/sidebar.js
|
// views/components/sidebar/sidebar.js
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
// NOTE: This script is always loaded dynamically by sidebarLoader.js AFTER
|
||||||
initSidebar();
|
// the sidebar HTML has already been injected into #sidebar-container.
|
||||||
});
|
// DOMContentLoaded has already fired at this point, so we must call
|
||||||
|
// initSidebar() directly — NOT inside a DOMContentLoaded listener.
|
||||||
|
|
||||||
function initSidebar() {
|
function initSidebar() {
|
||||||
const floatingMenuBtn = document.getElementById("floatingMenuBtn");
|
const floatingMenuBtn = document.getElementById("floatingMenuBtn");
|
||||||
@@ -67,3 +68,6 @@ function initSidebar() {
|
|||||||
lastScrollY = window.scrollY;
|
lastScrollY = window.scrollY;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call directly — sidebar HTML is already in DOM when this script executes
|
||||||
|
initSidebar();
|
||||||
|
|||||||
Reference in New Issue
Block a user