-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.js
36 lines (33 loc) · 1020 Bytes
/
todo.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
class TodoApp {
constructor(rootApp, todoTasks) {
this.rootApp = rootApp;
this.todoTasks = todoTasks;
this.todoStatus = this.todoTasks.map((x) => x = false);
}
todoHandler() {
if(Object.prototype.toString.call(this.todoTasks) === '[object Array]') {
this.todoTasks.forEach((el, id) => {
const label = document.createElement('label');
const radio = document.createElement('input');
const brTag = document.createElement('br');
label.innerText = el;
label.className = 'task-name';
radio.setAttribute('type', 'radio');
radio.value = id;
if(radio)
radio.onchange = () => {this.markTaskComplete(id)};
this.rootApp.appendChild(radio);
this.rootApp.appendChild(label);
this.rootApp.appendChild(brTag);
});
} else {
throw new Error('Tasks should be of type Array');
}
}
markTaskComplete(id) {
this.todoStatus[id] = true;
if(this.todoStatus[id]) {
document.getElementsByClassName('task-name')[id].style.textDecoration = 'line-through';
}
}
}