-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
76 lines (60 loc) · 2.51 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
// Get elements from DOM
const task1 = document.getElementsByClassName('task1');
const task2 = document.getElementsByClassName('task2');
const task3 = document.getElementsByClassName('task3');
const inputField = document.getElementsByClassName('input-element');
const sendbutton = document.getElementsByClassName('sendbutton');
const taskArea = document.getElementsByClassName('taskarea');
const cross = document.getElementsByClassName('cross');
const checkmark = document.getElementsByClassName('checkmark');
const hiddenClone = document.getElementById('hiddenClone');
// cross EventListeners
cross[0].addEventListener('click', removeCrossFunction);
cross[1].addEventListener('click', removeCrossFunction);
cross[2].addEventListener('click', removeCrossFunction);
// check EventListeners
function addCheckFunction(e) {
checkmark[0].parentElement.parentElement.innerHTML = "Done";
}
checkmark[0].addEventListener('click', addCheckFunction);
checkmark[1].addEventListener('click', addCheckFunction);
checkmark[2].addEventListener('click', addCheckFunction);
// submit Event Listeners
function submitInputField(e) {
if (inputField[0].value !== "") {
let clone = hiddenClone.cloneNode(true);
// clone.innerHTML = inputField[0].value;
clone.innerHTML = `<div class="task1" draggable="true">
<div class="icons-task1">
<img src="./images/checkmark_icon.png" width="25px" alt="" class="checkmark">
<img src="./images/cross_icon.png" width="25px" alt="" class="cross">
</div>
<div class="title-task1">
<h2>Task 1</h2>
<img src="./images/draganddrop.png" alt="icon">
</div>
</div>`
taskArea[0].appendChild(clone);
inputField[0].value='';
clone.styles.display = "flex";
}
}
sendbutton[0].addEventListener('click', submitInputField);
inputField[0].addEventListener('keypress', (e) => {
if (e.key === "Enter") {
submitInputField();
}
});
// Drag and drop function
function addDragClass(e) {
e.classList.add("dragging");
}
function removeDragClass(e) {
e.classList.remove("dragging");
}
task1[0].addEventListener('dragstart', addDragClass(task1[0]));;
task2[0].addEventListener('dragstart', addDragClass(task2[0]));
task3[0].addEventListener('dragstart', addDragClass(task3[0]));
/* task1[0].addEventListener('dragstart', removeDragClass(task1[0]));;
task2[0].addEventListener('dragstart', removeDragClass(task2[0]));
task3[0].addEventListener('dragstart', removeDragClass(task3[0])); */