-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
238 lines (167 loc) · 7.02 KB
/
Copy pathscript.js
File metadata and controls
238 lines (167 loc) · 7.02 KB
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
// Notification Menu Display
const notification = document.querySelector('.notification.menu');
const notificationMenu = document.querySelector('.notification.selection');
// Notification Close
const notificationClose = document.querySelector('.notification.message-close')
// Display None Notification
const displayNoNotification = document.querySelector('.notification.none')
//Notification Icon
const notificationIcon = document.querySelector('.notification.icon')
// Profile Menu Display
const profile = document.querySelector('.profile.main.info');
let profileMenu = document.querySelector('.profile.selection');
// Status
const statusSelection = document.querySelectorAll('input[type="radio"][name="status"]');
const statusIndicator = document.querySelector('.profile.main.info')
// Profile
const profileSelection = document.querySelectorAll('input[type="radio"][name="profiles"]');
const profileImage = document.querySelectorAll('.profile.image');
//Profile Click Setup
const profileImageSide = document.querySelector('.profile.image.side')
const profileText = document.querySelector('.profile.name')
// Search Input
const searchInput = document.querySelector('input#search');
const cancelSearch = document.querySelector('.search-cancel')
const searchResultDialog = document.querySelector('.search-dialog')
//Recents Addition
const inputAlertDescription = document.querySelector('#alert-description')
const alertLevelSelect = document.querySelector('#alert-level')
const addAlertsRecents = document.querySelector('.add-recents')
let timeout = false;
function removeNoneDisplay(e) {
if (e.currentTarget === profile) {
profileMenu.style.removeProperty('display');
document.addEventListener('click', (e) => {
if (!e.target.closest('.profile.selection') &&
!(e.target === profileImageSide || e.target === profileText || e.target === profile))
profileMenu.style.setProperty('display', 'none')
})
}
else {
notificationMenu.style.removeProperty('display');
document.addEventListener('click', (e) => {
if (!e.target.closest('.notification.selection') &&
!(e.target === notificationIcon || e.target === notification))
notificationMenu.style.setProperty('display', 'none')
})
}
}
function addNoneDisplay(e) {
e.target.style.setProperty('display', 'none');
}
function changeStatusIndicator(e) {
const status = e.target.id
if (status == 'online') {
statusIndicator.classList.add(status)
statusIndicator.classList.remove('offline')
statusIndicator.classList.remove('busy')
}
else if (status == 'offline') {
statusIndicator.classList.add(status)
statusIndicator.classList.remove('onlinr')
statusIndicator.classList.remove('busy')
} else {
statusIndicator.classList.add(status)
statusIndicator.classList.remove('offline')
statusIndicator.classList.remove('online')
}
}
function changeProfileImage(e) {
const imgLocation = e.target.nextSibling.firstElementChild.getAttribute('src');
profileImage.forEach(elem => elem.setAttribute('src', imgLocation))
statusIndicator.classList.add('online')
statusIndicator.classList.remove('offline')
statusIndicator.classList.remove('busy')
document.querySelector('input#online').checked = true;
}
function removeNotification(e) {
e.target.parentElement.remove()
displayNoNotification.style.removeProperty('display')
notification.classList.remove('notify')
}
//TODO - Re-check to add event listener on element
function removeElementOnInputEvent() {
clearTimeout(timeout);
let inputRecentCheck = document.querySelectorAll('input.recent.check');
(inputRecentCheck).forEach(checkbox => checkbox.addEventListener('input', (e) => {
// console.log('Ran on Input Checkbox')
timeout = setTimeout(() => {
e.target.parentElement.remove()
alertList.forEach((alert, index) => {
if (alert.sort == e.target.dataset.sort)
alertList.splice(index, 1)
})
if (alertList.length == 0) {
console.log('noted')
document.querySelector('.recent.none').style.removeProperty('display');
}
}, 500)
}));
}
profile.addEventListener('click', removeNoneDisplay);
notification.addEventListener('click', removeNoneDisplay);
profileMenu.addEventListener('mouseleave', addNoneDisplay);
notificationMenu.addEventListener('mouseleave', addNoneDisplay);
Array.from(statusSelection).forEach(status => status.addEventListener('change', changeStatusIndicator));
Array.from(profileSelection).forEach(profile => profile.addEventListener('change', changeProfileImage));
notificationClose.addEventListener('click', removeNotification)
searchInput.addEventListener('input', (e) => {
const searchResultNone = document.querySelector('.results.body > .result.none')
let searchItem = e.target.value;
let searchResult = [];
if (searchItem.length > 0) {
e.target.nextElementSibling.classList.add('show');
for (let alert of alertList) {
// console.log(alert.description)
if (alert.description.toLowerCase().includes(searchItem.toLowerCase()) || alert.level.includes(searchItem.toLowerCase())) {
searchResult.push(alert)
}
}
} else {
e.target.nextElementSibling.classList.remove('show');
}
// console.log(alertList)
if (searchResult.length === 0) {
searchResultNone.style.removeProperty('display')
} else {
searchResultNone.style.setProperty('display', 'none')
}
renderSearchResult(searchResult)
});
const searchDialogBody = document.querySelector('a.result.find');
searchInput.addEventListener('focus', () => {
searchResultDialog.style.removeProperty('display')
// console.log('focused Search')
})
searchInput.addEventListener('blur', () => {
searchResultDialog.style.setProperty('display', 'none')
// console.log('focused out Search')
})
cancelSearch.addEventListener('click', () => {
searchInput.value = '';
cancelSearch.classList.remove('show')
})
alertLevelSelect.addEventListener('change', () => {
alertLevelSelect.className = `${alertLevelSelect.value}-select`
})
addAlertsRecents.addEventListener('click', () => {
if (inputAlertDescription.value.length === 0) return false
let sort = alertList.length
// Account for missing in-between sorts too
let alertListSort = []
for (let alert of alertList) {
alertListSort.push(parseInt(alert.sort))
}
while (alertListSort.includes(sort)) sort++
let alertObj = {
'sort': `${sort}`,
'description': `${inputAlertDescription.value}`,
'level': `${alertLevelSelect.value}`
}
inputAlertDescription.value = '';
alertList.push(alertObj);
createRecentList(alertObj);
// rendering elements again, removes events, thus adding again.
removeElementOnInputEvent();
});
removeElementOnInputEvent();