-
Notifications
You must be signed in to change notification settings - Fork 0
/
js.js
56 lines (48 loc) · 1.7 KB
/
js.js
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
const sideLinks = document.querySelectorAll('.sidebar .side-menu li a:not(.logout)');
sideLinks.forEach(item => {
const li = item.parentElement;
item.addEventListener('click', () => {
sideLinks.forEach(i => {
i.parentElement.classList.remove('active');
})
li.classList.add('active');
})
});
const menuBar = document.querySelector('.content nav .bx.bx-menu');
const sideBar = document.querySelector('.sidebar');
menuBar.addEventListener('click', () => {
sideBar.classList.toggle('close');
});
const searchBtn = document.querySelector('.content nav form .form-input button');
const searchBtnIcon = document.querySelector('.content nav form .form-input button .bx');
const searchForm = document.querySelector('.content nav form');
searchBtn.addEventListener('click', function (e) {
if (window.innerWidth < 576) {
e.preventDefault;
searchForm.classList.toggle('show');
if (searchForm.classList.contains('show')) {
searchBtnIcon.classList.replace('bx-search', 'bx-x');
} else {
searchBtnIcon.classList.replace('bx-x', 'bx-search');
}
}
});
window.addEventListener('resize', () => {
if (window.innerWidth < 768) {
sideBar.classList.add('close');
} else {
sideBar.classList.remove('close');
}
if (window.innerWidth > 576) {
searchBtnIcon.classList.replace('bx-x', 'bx-search');
searchForm.classList.remove('show');
}
});
const toggler = document.getElementById('theme-toggle');
toggler.addEventListener('change', function () {
if (this.checked) {
document.body.classList.add('dark');
} else {
document.body.classList.remove('dark');
}
});