-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (56 loc) · 1.85 KB
/
Copy pathscript.js
File metadata and controls
68 lines (56 loc) · 1.85 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
let contador = 0;
let input = document.getElementById("inputTarefa");
let btnAdd = document.getElementById("btn-add");
let main = document.getElementById("areaLista");
function addTarefa() {
//PEGAR O VALOR DIGITADO NO INPUT
let valorInput = input.value;
//SE NÃO FOR VAZIO, NEM NULO, NEM INDEFINIDO
if (valorInput !== "" && valorInput !== null && valorInput !== undefined) {
++contador;
let novoItem = `<div id="${contador}" class="item">
<div onclick="marcarTarefa(${contador})" class="item-icone">
<i id="icone_${contador}" class="mdi mdi-circle-outline"></i>
</div>
<div onclick="marcarTarefa(${contador})" class="item-nome">
${valorInput}
</div>
<div class="item-botao">
<button onclick="deletar(${contador})" class="delete"><i class="mdi mdi-delete"></i> Deletar</button>
</div>
</div>`;
//ADICIONAR NOVO ITEM NO MAIN
main.innerHTML += novoItem;
//ZERAR OS CAMPINHOS
input.value = "";
input.focus();
}
}
function deletar(id) {
var tarefa = document.getElementById(id);
tarefa.remove();
}
function marcarTarefa(id) {
var item = document.getElementById(id);
var classe = item.getAttribute("class");
console.log(classe);
if (classe == "item") {
item.classList.add("clicado");
var icone = document.getElementById("icone_" + id);
icone.classList.remove("mdi-circle-outline");
icone.classList.add("mdi-check-circle");
item.parentNode.appendChild(item);
} else {
item.classList.remove("clicado");
var icone = document.getElementById("icone_" + id);
icone.classList.remove("mdi-check-circle");
icone.classList.add("mdi-circle-outline");
}
}
input.addEventListener("keyup", function (event) {
//SE TECLOU ENTER (13)
if (event.keyCode === 13) {
event.preventDefault();
btnAdd.click();
}
});