-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnav.js
116 lines (98 loc) · 3.15 KB
/
nav.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
function rotateArrow() {
var clickedEleArr = document.querySelectorAll('.rotatearrow')
clickedEleArr.forEach(function (clickedEle) {
clickedEle.addEventListener('click', function () {
var rotatedEle = clickedEle.querySelector('.arrow')
if (rotatedEle.classList.contains('rotate')) {
rotatedEle.classList.remove('rotate')
} else {
rotatedEle.classList.add('rotate')
}
})
})
}
function toggleSidebar() {
var body = document.body
var sidebar = body.querySelector('.sidebar')
var toggleSidebar = body.querySelector('#toggle-sidebar')
toggleSidebar.addEventListener('click', function () {
if (body.classList.contains('sidebar-isopened')) {
body.classList.remove('sidebar-isopened')
sidebar.classList.remove('opened')
} else {
body.classList.add('sidebar-isopened')
sidebar.classList.add('opened')
}
})
}
function detectClickOutside() {
var body = document.body
var sidebar = document.querySelector('.sidebar')
var toggleSidebar = body.querySelector('#toggle-sidebar')
window.addEventListener('click', function (e) {
if (
!sidebar.contains(e.target) &&
!toggleSidebar.contains(e.target) &&
body.classList.contains('sidebar-isopened')
) {
body.classList.remove('sidebar-isopened')
sidebar.classList.remove('opened')
}
})
}
function styleScrollbar() {
var sidebar = document.querySelector('.sidebar')
document.addEventListener('DOMContentLoaded', function () {
OverlayScrollbars(sidebar, {
className: 'os-theme-light'
})
})
}
function hideNavItems() {
var showSearchbox = document.querySelector('#show-searchbox')
var navStart = document.querySelector('.nav-start')
var navEnd = document.querySelector('.nav-end')
var navForm = document.querySelector('.nav-form')
var hideSearchbox = document.querySelector('#hide-searchbox')
showSearchbox.addEventListener('click', function () {
navStart.classList.add('d-none')
navEnd.classList.add('d-none')
navForm.classList.remove('d-none')
hideSearchbox.classList.remove('d-none')
})
}
function showNavItems() {
var navStart = document.querySelector('.nav-start')
var navEnd = document.querySelector('.nav-end')
var navForm = document.querySelector('.nav-form')
var hideSearchbox = document.querySelector('#hide-searchbox')
hideSearchbox.addEventListener('click', function () {
navStart.classList.remove('d-none')
navEnd.classList.remove('d-none')
navForm.classList.add('d-none')
hideSearchbox.classList.add('d-none')
})
}
const targets = document.querySelectorAll("img.card-img-top, img.avatar");
const lazyLoad = target => {
const io = new IntersectionObserver((entries, observer) => {
console.log(entries)
entries.forEach(entry => {
console.log('😍');
if (entry.isIntersecting) {
const img = entry.target;
const src = img.getAttribute('data-lazy');
img.setAttribute('src', src);
observer.disconnect();
}
});
});
io.observe(target)
};
targets.forEach(lazyLoad);
rotateArrow()
toggleSidebar()
detectClickOutside()
styleScrollbar()
hideNavItems()
showNavItems()