-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (71 loc) · 2.65 KB
/
Copy pathscript.js
File metadata and controls
89 lines (71 loc) · 2.65 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const allSideMenu = document.querySelectorAll('#sidebar .side-menu.top li a');
allSideMenu.forEach(item=> {
const li = item.parentElement;
item.addEventListener('click', function () {
allSideMenu.forEach(i=> {
i.parentElement.classList.remove('active');
})
li.classList.add('active');
})
});
// TOGGLE SIDEBAR
const menuBar = document.querySelector('#content nav .bx.bx-menu');
const sidebar = document.getElementById('sidebar');
menuBar.addEventListener('click', function () {
sidebar.classList.toggle('hide');
})
const searchButton = document.querySelector('#content nav form .form-input button');
const searchButtonIcon = document.querySelector('#content nav form .form-input button .bx');
const searchForm = document.querySelector('#content nav form');
searchButton.addEventListener('click', function (e) {
if(window.innerWidth < 576) {
searchForm.classList.toggle('show');
if(searchForm.classList.contains('show')) {
searchButtonIcon.classList.replace('bx-search', 'bx-x');
} else {
searchButtonIcon.classList.replace('bx-x', 'bx-search');
}
}
})
if(window.innerWidth < 768) {
sidebar.classList.add('hide');
} else if(window.innerWidth > 576) {
searchButtonIcon.classList.replace('bx-x', 'bx-search');
searchForm.classList.remove('show');
}
window.addEventListener('resize', function () {
if(this.innerWidth > 576) {
searchButtonIcon.classList.replace('bx-x', 'bx-search');
searchForm.classList.remove('show');
}
})
const switchMode = document.getElementById('switch-mode');
// Apply the saved mode on page load
document.addEventListener('DOMContentLoaded', () => {
if (localStorage.getItem('darkMode') === 'enabled') {
document.body.classList.add('dark');
switchMode.checked = true; // Set the toggle to checked
}
});
// Save the preference when the switch is toggled
switchMode.addEventListener('change', function () {
if (this.checked) {
document.body.classList.add('dark');
localStorage.setItem('darkMode', 'enabled'); // Save the state
} else {
document.body.classList.remove('dark');
localStorage.setItem('darkMode', 'disabled'); // Save the state
}
});
const navLinks = document.querySelectorAll('.side-menu a');
navLinks.forEach(link => {
link.addEventListener('click', function (e) {
// Remove active class from all links
navLinks.forEach(nav => nav.parentElement.classList.remove('active'));
// Add active class to the clicked link's parent <li>
this.parentElement.classList.add('active');
// Load the content dynamically (optional)
const file = this.getAttribute('href');
loadContent(file);
});
});