-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
210 lines (179 loc) · 6.4 KB
/
script.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// SIDEBAR
const menuItems = document.querySelectorAll('.menu-item');
// MESSAGES
const messagesNotification = document.querySelector('#messages-notifications');
const messages = document.querySelector('.messages');
const message = document.querySelectorAll('.message');
const messageSearch = document.querySelector('#message-search');
// THEME
const theme = document.querySelector('#theme');
const themeModal = document.querySelector('.customize-theme');
const fontSize = document.querySelectorAll('.font-size span');
var root = document.querySelector(':root');
const colorPalette = document.querySelectorAll('.choose-color span');
const Bg1 = document.querySelector('.bg-1');
const Bg2 = document.querySelector('.bg-2');
const Bg3 = document.querySelector('.bg-3');
// ======================>> SIDEBAR
// remove active class from all menu items
const changeActiveItem = () => {
menuItems.forEach(item => {
item.classList.remove('active');
})
}
menuItems.forEach(item => {
item.addEventListener('click', () => {
changeActiveItem();
item.classList.add('active');
if (item.id != 'notifications') {
document.querySelector('.notification-popup').style.display = 'none';
} else {
document.querySelector('.notification-popup').style.display = 'block';
document.querySelector('#notifications .notification-count').style.display = 'none';
}
})
})
// ======================>> MESSAGES
// search Message
const searchMessage = () => {
const val = messageSearch.value.toLowerCase();
message.forEach(user => {
let name = user.querySelector('h5').textContent.toLocaleLowerCase();
if (name.indexOf(val) != -1) {
user.style.display = 'flex';
} else {
user.style.display = 'none';
}
})
}
// search chat
messageSearch.addEventListener('keyup', searchMessage);
// highlight messages card when messages menu item is clicked
messagesNotification.addEventListener('click', () => {
messages.style.boxShadow = '0 0 1rem var(--color-primary)';
messagesNotification.querySelector('.notification-count').style.display = 'none';
setTimeout(() => {
messages.style.boxShadow = 'none'
}, 2000);
})
// ======================>> THEME CUSTOMIZE
// open modal
const openThemeModal = () => {
themeModal.style.display = 'grid';
}
// open modal
theme.addEventListener('click', openThemeModal);
// close modal
const closeThemeModal = (e) => {
if (e.target.classList.contains('customize-theme')) {
themeModal.style.display = 'none';
}
}
// close modal
themeModal.addEventListener('click', closeThemeModal);
// ======================>> FONTS
const removeSizeSelector = () => {
fontSize.forEach(size => {
size.classList.remove('active');
})
}
fontSize.forEach(size => {
size.addEventListener('click', () => {
removeSizeSelector();
let fontSize;
size.classList.toggle('active');
if (size.classList.contains('font-size-1')) {
fontSize = '10px';
root.style.setProperty('--sticky-top-left', '5.4rem');
root.style.setProperty('--sticky-top-right', '5.4rem');
} else if (size.classList.contains('font-size-2')) {
fontSize = '13px';
root.style.setProperty('--sticky-top-left', '5.4rem');
root.style.setProperty('--sticky-top-right', '-7rem');
} else if (size.classList.contains('font-size-3')) {
fontSize = '16px';
root.style.setProperty('--sticky-top-left', '-2rem');
root.style.setProperty('--sticky-top-right', '-17rem');
} else if (size.classList.contains('font-size-4')) {
fontSize = '19px';
root.style.setProperty('--sticky-top-left', '-5rem');
root.style.setProperty('--sticky-top-right', '-25rem');
} else if (size.classList.contains('font-size-5')) {
fontSize = '22px';
root.style.setProperty('--sticky-top-left', '-12rem');
root.style.setProperty('--sticky-top-right', '-35rem');
}
// change the font size of the root html element
document.querySelector('html').style.fontSize = fontSize;
})
})
// ======================>> COLORS
// remove active class from colors
const changeActiveColorClass = () => {
colorPalette.forEach(colorPicker => {
colorPicker.classList.remove('active');
})
}
// change primary color
colorPalette.forEach(color => {
color.addEventListener('click', () => {
let primary;
// remove active class from colors
changeActiveColorClass();
if (color.classList.contains('color-1')) {
primaryHue = 252;
} else if (color.classList.contains('color-2')) {
primaryHue = 45;
} else if (color.classList.contains('color-3')) {
primaryHue = 352;
} else if (color.classList.contains('color-4')) {
primaryHue = 152;
} else if (color.classList.contains('color-5')) {
primaryHue = 202;
}
color.classList.add('active');
root.style.setProperty('--primary-color-hue', primaryHue);
})
})
// ======================>> BACKGROUND
let lightColorLightness;
let whiteColorLightness;
let darkColorLightness;
// change background color
const changeBG = () => {
root.style.setProperty('--light-color-lightness', lightColorLightness);
root.style.setProperty('--white-color-lightness', whiteColorLightness);
root.style.setProperty('--dark-color-lightness', darkColorLightness);
}
Bg1.addEventListener('click', () => {
// add active class
Bg1.classList.add('active');
// remove active class
Bg2.classList.remove('active');
Bg3.classList.remove('active');
// remove customized changes from local storage
window.location.reload();
});
Bg2.addEventListener('click', () => {
darkColorLightness = '95%';
whiteColorLightness = '20%';
lightColorLightness = '15%';
// add active class
Bg2.classList.add('active');
// remove active class
Bg1.classList.remove('active');
Bg3.classList.remove('active');
changeBG();
});
Bg3.addEventListener('click', () => {
darkColorLightness = '95%';
whiteColorLightness = '10%';
lightColorLightness = '0%';
// add active class
Bg3.classList.add('active');
// remove active class
Bg1.classList.remove('active');
Bg2.classList.remove('active');
changeBG();
})
// END