-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (43 loc) · 1.68 KB
/
script.js
File metadata and controls
53 lines (43 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Get references to sidebar and content elements
const sidebar = document.querySelector(".sidebar");
const content = document.querySelector(".content");
function toggleSidebarHide() {
// Hide the sidebar
sidebar.style.display = "none";
// Adjust content margin to remove the space occupied by the sidebar
content.style.marginLeft = "0";
}
function toggleSidebarShow() {
// Show the sidebar
sidebar.style.display = "block";
// Adjust content margin to accommodate the sidebar
content.style.marginLeft = "250px";
}
// Event listener to toggle sidebar visibility when sidebar button is clicked
document.getElementById("sidebarHide").addEventListener("click", toggleSidebarHide);
document.getElementById("sidebarShow").addEventListener("click", toggleSidebarShow);
document.addEventListener("DOMContentLoaded", function () {
// Get the content div
const contentDiv = document.querySelector(".content");
// Function to load topic content
function loadTopicContent(topicUrl) {
fetch(topicUrl)
.then((response) => response.text())
.then((data) => {
contentDiv.innerHTML = data;
})
.catch((error) => {
console.error("Error fetching topic content:", error);
});
}
// Get all the topic links in the sidebar
const topicLinks = document.querySelectorAll(".sidebar a");
// Attach click event listeners to each topic link
topicLinks.forEach((link) => {
link.addEventListener("click", function (event) {
event.preventDefault(); // Prevent default link behavior
const topicUrl = this.getAttribute("href"); // Get the href attribute of the clicked link
loadTopicContent(topicUrl); // Load topic content
});
});
});