-
Notifications
You must be signed in to change notification settings - Fork 24
/
script.js
71 lines (55 loc) · 1.55 KB
/
script.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
/** help */
function log(message) {
console.log('> ' + message)
}
/** app */
const cards = document.querySelectorAll('.card')
const dropzones = document.querySelectorAll('.dropzone')
/** our cards */
cards.forEach(card => {
card.addEventListener('dragstart', dragstart)
card.addEventListener('drag', drag)
card.addEventListener('dragend', dragend)
})
function dragstart() {
// log('CARD: Start dragging ')
dropzones.forEach( dropzone => dropzone.classList.add('highlight'))
// this = card
this.classList.add('is-dragging')
}
function drag() {
// log('CARD: Is dragging ')
}
function dragend() {
// log('CARD: Stop drag! ')
dropzones.forEach( dropzone => dropzone.classList.remove('highlight'))
// this = card
this.classList.remove('is-dragging')
}
/** place where we will drop cards */
dropzones.forEach( dropzone => {
dropzone.addEventListener('dragenter', dragenter)
dropzone.addEventListener('dragover', dragover)
dropzone.addEventListener('dragleave', dragleave)
dropzone.addEventListener('drop', drop)
})
function dragenter() {
// log('DROPZONE: Enter in zone ')
}
function dragover() {
// this = dropzone
this.classList.add('over')
// get dragging card
const cardBeingDragged = document.querySelector('.is-dragging')
// this = dropzone
this.appendChild(cardBeingDragged)
}
function dragleave() {
// log('DROPZONE: Leave ')
// this = dropzone
this.classList.remove('over')
}
function drop() {
// log('DROPZONE: dropped ')
this.classList.remove('over')
}