forked from MinhQuan/PresentCorpo
Refactor: Extract sidebar into a reusable component
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
// views/components/sidebar/sidebarLoader.js
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const sidebarContainer = document.getElementById("sidebar-container");
|
||||
if (!sidebarContainer) return;
|
||||
|
||||
// Load HTML
|
||||
fetch("/components/sidebar/sidebar.html")
|
||||
.then((response) => response.text())
|
||||
.then((data) => {
|
||||
sidebarContainer.innerHTML = data;
|
||||
|
||||
// Load CSS
|
||||
const link = document.createElement("link");
|
||||
link.rel = "stylesheet";
|
||||
link.href = "/components/sidebar/sidebar.css";
|
||||
document.head.appendChild(link);
|
||||
|
||||
// Load JS
|
||||
const script = document.createElement("script");
|
||||
script.src = "/components/sidebar/sidebar.js";
|
||||
document.body.appendChild(script);
|
||||
})
|
||||
.catch((error) => console.error("Error loading sidebar:", error));
|
||||
});
|
||||
Reference in New Issue
Block a user