-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
295 lines (225 loc) · 9.8 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
//===============================LEFT SIDE BAR==============================
const menuItems =document.querySelectorAll('.menu-item')
//remove active class from all menu item
const changeActiveMenu = () => {
menuItems.forEach(item => {
item.classList.remove('active')
})
}
//add active class to the selected menu item
menuItems.forEach(item =>{
item.addEventListener('click', () => {
changeActiveMenu(); //this function is called to remove all existing active menu class before proceeding to listen to the click below and performing the function below
item.classList.add('active');
if(item.id != 'notificationss'){
document.querySelector('.notification-popup').style.display = 'none'
}
else{
document.querySelector('.notification-popup').style.display = 'block'; //displays the notification popup upon click of the notification menu item
document.querySelector('#notifications .notification-count').style.display = 'none' //removes the notification count once the notification menu item is clicked
}
})
})
//===========================================MESSAGES=========================================================
const MessagesNotif = document.querySelector('#messages-notifications') //selects the menu item with the id of messages-notification
const MessagesCount = document.querySelector('#messages-notifications .notification-count') //selecting themessage count of the menu item with the ID of messages-notifications
const message = document.querySelector('.messages') //selecting the message bar in the RIGHT MAIN
const individualMessage = document.querySelectorAll('.message') //selects the individual message on the RIGHT MAIN. i.e the div with the class of 'message'
const msgSearch = document.querySelector('#message-search')
//const sender = document.querySelectorAll('.message .message-body h5')
MessagesNotif.addEventListener('click', () => {
MessagesCount.style.display = 'none'
message.style.boxShadow = '0 0 1rem var(--color-primary)' //highlights the messages box in the RIGHT MAIN upon clicking the messages menu-item by adding box-shaow to the right MAIN messages
setTimeout(() => { message.style.boxShadow = 'none'}, 2000) //removes the box-shadow after 2 seconds
})
//============SEARCHES CHAT
const searchMessages = () => { //where searchMessages is the function used for the addEventListener below
const val = msgSearch.value.toLowerCase();
console.log(val)
individualMessage.forEach(chat => {
let name = chat.querySelector('h5').textContent.toLowerCase();//selets the name of the message sender written in h5 tag in html and change it to lowercase
console.log(name)
if(name.indexOf(val) != -1){ //i.e if there is a match
chat.style.display = 'flex'; //we used flex instead of block because that is the display styling of our 'message'in the css section
}
else{
chat.style.display = 'none';
}
})
}
//SEARCH CHAT
msgSearch.addEventListener('keyup', searchMessages) //the searchMessages Function is defined above
//==========================================THEME/DISPLAY CUSTOMIZATION=========================================================
const theme = document.querySelector('#theme');
const themeModal = document.querySelector('.customize-theme')
//OPEN THEME CUSTOMIZATION MODAL
const openThemeModal = () => {
themeModal.style.display = 'grid' //we used 'grid'instead of block because the initial display of 'customize-theme'is grid.
}
theme.addEventListener('click', openThemeModal); //the open themeModal function is above
//CLOSE THEME CUSTOMIZATION MODAL
const closeThemeModal = (e) => { //will close the theme customization whenever we click outside the card
if(e.target.classList.contains('customize-theme')){
themeModal.style.display = 'none'
}
}
themeModal.addEventListener('click', closeThemeModal)
//SELECTING AND CHANGING FONT SIZES UNDER THEME CUSTOMIZATION
const fontSizes = document.querySelectorAll('.choose-size span')
var root = document.querySelector(':root'); //select the root element
console.log(fontSizes)
//remove active class from span or font size selector
const removeSizeSeletor = () => {
fontSizes.forEach(size => {
size.classList.remove('active')
})
}
fontSizes.forEach(size => { //size is the element of the foreach loop
size.addEventListener('click', () => {
removeSizeSeletor() //remove the active class from font size selector
let fontSize;
size.classList.toggle('active') //toggles the active class for the selected font span
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 = '17.8px';
root.style.setProperty('----sticky-top-left', '-5rem')
root.style.setProperty('----sticky-top-right', '-25rem')
}
else{
fontSize = '22px';
root.style.setProperty('----sticky-top-left', '-10rem')
root.style.setProperty('----sticky-top-right', '-35rem')
}
//change font size of the root html element
document.querySelector('html').style.fontSize = fontSize;
console.log(fontSize)
})
})
//CHANGING PRIMARY COLORS UNDER THEME CUSTOMIZATION
const colorPalette = document.querySelectorAll('.choose-color span');
//remove active color class
const removeActiveColor = () => {
colorPalette.forEach(color => {
color.classList.remove('active')
})
}
colorPalette.forEach(color => {
color.addEventListener('click', () => {
removeActiveColor(); //calls the function removeActive color
color.classList.toggle('active') //toggles the active class for the loop
if(color.classList.contains('color-1')){
primaryHue = 252;
}
else if(color.classList.contains('color-2')){
primaryHue = 52;
}
else if(color.classList.contains('color-3')){
primaryHue = 352;
}
else if(color.classList.contains('color-4')){
primaryHue = 152;
}
else{
primaryHue = 202;
}
root.style.setProperty('--primary-color-hue', primaryHue)
})
})
//CHANGING THE BACKGROUND UNDER THEME CUSTOMIZATION
const Bg1 = document.querySelector('.bg-1');
const Bg2 = document.querySelector('.bg-2')
const Bg3 = document.querySelector('.bg-3')
//theme background values
let lightColorLightness;
let whiteColorLightness;
let darkColorLightness;
//change BG FUNCTION
const changeBG = () => {
root.style.setProperty('--light-color-lightness', lightColorLightness)
root.style.setProperty('--white-color-lightness', whiteColorLightness)
root.style.setProperty('--dark-color-lightness', darkColorLightness)
}
//for clicking BG1
Bg1.addEventListener('click', () => {
darkColorLightness = '95%'
whiteColorLightness = '20%'
lightColorLightness = '15%'
//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()
})
//for clicking BG2
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')
//call a function
changeBG();
})
//for clickingBG3
Bg3.addEventListener('click', () => {
darkColorLightness = '95%'
whiteColorLightness = '20%'
lightColorLightness = '0%'
//add active class
Bg3.classList.add('active')
//remove active class
Bg1.classList.remove('active')
Bg2.classList.remove('active')
//call a function
changeBG();
})
const menu = document.querySelector('.left')
console.log(menu)
const profile = document.querySelector('.profile-pics.one ')
console.log(profile)
const leftMenu = document.querySelector('.left .sidebar .m')
console.log(leftMenu)
//OPEN MENU PROFILE FOR SMALL DEVICES
const openMenu = () => {
if(menu.style.display === 'block'){
menu.style.display = 'none'
}
else{
menu.style.display = 'block';
}
}
profile.addEventListener('click', openMenu); //calls the openMenu function on clicking the profile
//CLOSE MENU PROFILE FOR SMALL DEVICES
// const closeMenu = (e) => {
// if(e.target === menu){
// menu.style.display = 'none'
// }
// }
// window.addEventListener('click', closeMenu)
//==============================================================================================
// const container = document.querySelector('.container')
// container.addEventListener('click', function(e){
// if(e.target === menu){
// menu.style.display = 'none'
// }
// })
//WHY IS THE FUNCTION ABOVE NOT WORKING