-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
97 lines (74 loc) · 2.44 KB
/
main.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
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
const newText = document.querySelector(".input");
const list = document.querySelector(".list");
function todo() {
if(!newText.value) {
alert("input masih kosong woi!!");
return;
}
let newTodo = `<li class="listItem">
<div class="text">
<p contentEditable="false" class="textContent" onclick="toggle(this)"> ${newText.value} </p>
</div>
<div class="containerButton">
<button onclick="editText(this)" class="editButton" type="button">✏️</button>
<button onclick="submit(this)" class="submitButton">✅</button>
<button onclick="removeItem(this)" class="removeButton" type="button">🗑️</button>
</div>
</li>`;
list.insertAdjacentHTML('afterbegin', newTodo)
var elem = document.querySelector(".listItem");
elem.style.display = "flex";
setTimeout(function() {
elem.style.opacity = 1;
elem.style.transform = "translateX(0)";
}, 10);
newText.value="";
}
const textMain = document.querySelector(".textContent")
var x = 1;
function toggle(el)
{
x++
if(x == 3) {
x=0
el.classList.add("done");
} else {
el.classList.remove("done");
}
console.log(x)
}
function removeItem(el)
{
const containerButton = document.querySelector(".containerButton");
el.parentElement.parentElement.style="";
el.parentElement.parentElement.classList.add("ilang")
setTimeout(function() {
el.parentElement.parentElement.remove();
}, 1000);
}
function editText(el) {
let elem = el.parentElement.parentElement.firstElementChild.firstElementChild;
let confirm = el.parentElement.firstElementChild.nextElementSibling;
const submitBtn = document.querySelector(".submitButton");
const textContent = document.querySelector(".textContent");
x=1;
elem.classList.remove('done');
elem.style="border:1px solid #643cff"
if(!elem.textContent) {
elem.innerHTML="-";
}
el.style.display="none";
confirm.style.display="block";
elem.setAttribute("contentEditable", true);
}
function submit(el) {
let elem = el.parentElement.parentElement.firstElementChild.firstElementChild;
let editBtn = el.parentElement.firstElementChild;
const submitBtn = document.querySelector(".submitButton");
const textContent = document.querySelector(".textContent");
x=1;
elem.style="border:none"
el.style="display:none";
editBtn.style="display:block";
elem.setAttribute("contentEditable", false);
}