-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
48 lines (40 loc) · 1.27 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
function onchangeText(event) {
const button = document.querySelector('button');
button.disabled = !event.value;
}
function deleteTask(task) {
task.remove();
}
function createTask() {
const tasks = document.querySelector('main');
const input = document.getElementById('task');
const description = input.value;
const date = new Date();
const time = date.getHours() + ':' + date.getMinutes();
tasks.insertAdjacentHTML('beforeend',
`<div class="row" id="${description}" draggable="true" ondragstart="drag(event)">
<div class="description">
<h3>${description}</h3>
<span>Hoje, ${time}</span>
</div>
<div class="action" onclick="deleteTask(${description})">
<span class="material-symbols-outlined">delete</span>
</div>
</div>`);
input.value = '';
}
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
function onDragStart(event) {
event.dataTransfer.setData('text/plain', event.target.id);
event.currentTarget.style.backgroundColor = 'yellow';
}