-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.js
More file actions
48 lines (42 loc) · 1.61 KB
/
transform.js
File metadata and controls
48 lines (42 loc) · 1.61 KB
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
var draggingId;
/* keep open while over */
function allowDrop(ev) { ev.preventDefault(); }
/* prep for drag */
function drag(ev) {
ev.dataTransfer.setData("Text",ev.target.id);
draggingId = ev.target.id;
ev.target.classList.add("tilt");
}
/* tidy up as dropped */
// Skip default action
// Close drop zone
// Find parent to have node inserted
function drop(ev) {
ev.preventDefault();
var dropOn=ev.target;
dropOn.classList.remove("dodge");
if (dropOn.classList.contains("drop")) {
var data =ev.dataTransfer.getData("Text");
document.getElementById(data).classList.remove("tilt");
dropOn.appendChild( document.getElementById(data));
return; }
while (dropOn.parentNode!=null && !dropOn.parentNode.classList.contains("drop"))
{ dropOn = dropOn.parentNode }
if (dropOn == null) {return; }
// Move it in DOM
var data =ev.dataTransfer.getData("Text");
document.getElementById(data).classList.remove("tilt");
if (dropOn.nextSibling!=null)
{ dropOn.parentNode.insertBefore(document.getElementById(data),dropOn.nextSibling);}
else
{ dropOn.parentNode.appendChild( document.getElementById(data)) }
}
function dragEnd(event) { document.getElementById(data).classList.remove("tilt"); }
/* Make space for drop (and tidy up) */
function dodgeDrop(ev) {
console.log("dropddge ");
dodgeIt(ev.target);}
function dodgeIt(target) {
if (target.id==draggingId) {return; }
target.classList.toggle("dodge");
}