MCPcopy Create free account
hub / github.com/codemistic/Web-Development / item

Class item

To-Do List/Task Schedule List/main.js:14–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class item{
15 constructor(name){
16 this.createItem(name);
17 }
18 createItem(name){
19 var itemBox = document.createElement('div');
20 itemBox.classList.add('item');
21
22 var input = document.createElement('input');
23 input.type = "text";
24 input.disabled = true;
25 input.value = name;
26 input.classList.add('item_input');
27
28 var edit = document.createElement('button');
29 edit.classList.add('edit');
30 edit.innerHTML = '<i class="fas fa-edit"></i>';
31 edit.addEventListener('click', () => this.edit(input, name));
32
33 var remove = document.createElement('button');
34 remove.classList.add('remove');
35 remove.innerHTML = '<i class="fas fa-trash"></i>';
36 remove.addEventListener('click', () => this.remove(itemBox, name));
37
38 container.appendChild(itemBox);
39
40 itemBox.appendChild(input);
41 itemBox.appendChild(edit);
42 itemBox.appendChild(remove);
43
44 }
45
46 edit(input, name){
47 if(input.disabled == true){
48 input.disabled = !input.disabled;
49 }
50 else{
51 input.disabled = !input.disabled;
52 let indexof = todos.indexOf(name);
53 todos[indexof] = input.value;
54 window.localStorage.setItem("todos", JSON.stringify(todos));
55 }
56 }
57
58 remove(itemBox, name){
59 itemBox.parentNode.removeChild(itemBox);
60 let index = todos.indexOf(name);
61 todos.splice(index, 1);
62 window.localStorage.setItem("todos", JSON.stringify(todos));
63 }
64}
65
66add.addEventListener('click', check);
67window.addEventListener('keydown', (e) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected