-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
210 lines (188 loc) · 7.22 KB
/
index.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
//SIDBAR
const menuItems = document.querySelectorAll('.menu-item');
//MESSAGES
const messagesNotification = document.querySelector('#messages-notifications');
const messages = document.querySelector('.messages');
const message = messages.querySelectorAll('.message');
const messageSearch = document.querySelector('#message-search');
//THEME
const theme = document.querySelector('#theme');
const themeModel = document.querySelector('.customize-theme')
const fontSizes = document.querySelectorAll('.choose-size span');
const 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('.notifications-popup').style.display='none';
}else{
document.querySelector('.notifications-popup').style.display='block';
document.querySelector('#notifications .notification-count').style.display='none';
}
})
})
//======MESSAGES ============\
//searches chats
/*
let name = document.querySelectorAll('.frind').textContent.toLowerCase();
console.log(name[0]);
*/
const searchMessage = () => {
const val = messageSearch.value.toLowerCase();
console.log(val);
message.forEach( chat => {
let name = chat.querySelector('h5').textContent.toLowerCase();
//let name= [chat.frind.innerHTML.toLowerCase()];
console.log(name)
if(name.indexOf(val)!=-1){
chat.style.display='flex';
}else{
chat.style.display = 'none'
}
})
}
//search chat
messageSearch.addEventListener('keyup' , searchMessage);
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 CUSTOMIZATION
//opens model
const openThemeModel = () => {
themeModel.style.display='grid';
}
//closes model
const closeThemeModel = (e) => {
if(e.target.classList.contains('customize-theme')){
themeModel.style.display = 'none';
}
}
//close model
themeModel.addEventListener('click' , closeThemeModel);
//open model
theme.addEventListener('click' ,openThemeModel);
//==========FONT SIZES===================
//remove active class from spans
const removeSizeSelector = () => {
fontSizes.forEach( size => {
size.classList.remove('active');
})
}
fontSizes.forEach( size => {
size.addEventListener('click' , () =>{
removeSizeSelector();
let fontSize;
size.classList.toggle('active');
if(size.classList.contains('font-size-1')){
fontSize = '10px';
root.style.setProperty('--sticy-top-left' , '5.4rem');
root.style.setProperty('--sticy-top-right' , '5.4rem');
}else if(size.classList.contains('font-size-2')){
fontSize = '13px';
root.style.setProperty('--sticy-top-left' , '5.4rem');
root.style.setProperty('--sticy-top-right' , '-7rem');
}else if(size.classList.contains('font-size-3')){
fontSize = '15px';
root.style.setProperty('--sticy-top-left' , '-2rem');
root.style.setProperty('--sticy-top-right' , '-17rem');
}else if(size.classList.contains('font-size-4')){
fontSize = '17px';
root.style.setProperty('--sticy-top-left' , '-5rem');
root.style.setProperty('--sticy-top-right' , '-25rem');
}
else if(size.classList.contains('font-size-5')){
fontSize = '19px';
root.style.setProperty('--sticy-top-left' , '-12rem');
root.style.setProperty('--sticy-top-right' , '-35rem');
}
//change font size of the root html element
document.querySelector('html').style.fontSize= fontSize;
})
})
//remove active class from colors
const changeActiveClassColor = () => {
colorPalette.forEach( colorPicker => {
colorPicker.classList.remove('active');
})
}
//change primary colors
colorPalette.forEach(color => {
color.addEventListener('click' , () =>{
let primaryHue;
changeActiveClassColor();
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 if(color.classList.contains('color-5')){
primaryHue = 202;
}
color.classList.add('active');
root.style.setProperty('--primary-color-hue' ,primaryHue);
})
})
//THEME BACKGROUND VALUES
let lightColorLightness;
let whiteColorLightness;
let darkColorLightness;
//CHANGES 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);
}
//change background colors
Bg1.addEventListener('click' , () => {
//add active class
Bg1.classList.add('active');
//remove active class from the others
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 from the others
Bg1.classList.remove('active');
Bg3.classList.remove('active');
//remove customized changes from local storage
changeBG();
});
Bg3.addEventListener('click' , () => {
darkColorLightness = '95%';
whiteColorLightness = '10%';
lightColorLightness = '0%';
//add active class
Bg3.classList.add('active');
//remove active class from the others
Bg1.classList.remove('active');
Bg2.classList.remove('active');
//remove customized changes from local storage
changeBG();
});