-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (42 loc) · 1.41 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
const updates = document.querySelectorAll(".ref");
const count = document.querySelector('.count');
const readAll = document.querySelector('.read-all')
const board = document.querySelector('main');
const message = document.querySelector('.message');
updates.forEach(element => {
element.setAttribute('id', 'active');
});
showCount();
readAll.addEventListener('click', reset);
board.addEventListener('click', read);
function showCount() {
const unread = document.querySelectorAll('#active');
count.innerText = unread.length;
}
function reset() {
if (readAll.textContent.includes('Mark all as read')) {
updates.forEach(element => {
element.removeAttribute('id', 'active');
})
message.style.display = 'inherit';
readAll.innerText = 'Mark all as unread';
showCount();
} else {
updates.forEach(element => {
element.setAttribute('id', 'active');
});
message.style.display = 'none';
readAll.innerText = 'Mark all as read';
showCount();
}
}
function read(e) {
if (e.target.id === 'active' && e.target.dataset.update === 'message') {
e.target.removeAttribute('id', 'active');
message.style.display = 'inherit';
showCount();
} else if (e.target.id === 'active' || e.target.dataset.update !== 'message') {
e.target.removeAttribute('id', 'active');
showCount();
}
}