-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
57 lines (45 loc) · 1.49 KB
/
scripts.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
const columns = document.querySelectorAll(".column__cards")
const cards = document.querySelectorAll(".card")
let draggedCard;
const dragStart = (event) => {
draggedCard = event.target // salva o elemento que está sendo arrastado
event.dataTransfer.effectAllowed = "move"
}
const dragOver = (event) => {
event.preventDefault()
}
const dragEnter = ({ target }) => {
if (target.classList.contains("column__cards")) {
target.classList.add("column__highlight")
}
}
const dragLeave = ({ target }) => {
target.classList.remove("column__highlight")
}
const drop = ({ target }) => {
if (target.classList.contains("column__cards")){
target.classList.remove("column__highlight")
target.append(draggedCard)
}
}
const createCard = ({ target }) => {
if (!target.classList.contains("column__cards")) return
const card = document.createElement("section")
card.className = "card"
card.draggable = "true"
card.contentEditable = "true"
card.addEventListener("focusout", () =>{
card.contentEditable = "false"
if(!card.textContent) card.remove()
})
card.addEventListener("dragstart", dragStart)
target.append(card)
card.focus()
}
columns.forEach((column) => {
column.addEventListener("dragover", dragOver)
column.addEventListener("dragenter", dragEnter)
column.addEventListener("dragleave", dragLeave)
column.addEventListener("drop", drop)
column.addEventListener("dblclick", createCard)
})