-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrag.js
94 lines (71 loc) · 2.2 KB
/
drag.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var DragUpload={};
function $(id){
return document.getElementById(id);
}
function init(){
$("div1").addEventListener("drop",drop,false);
$("div1").addEventListener("dragenter",dragenter,false);
$("div1").addEventListener("dragleave",dragleave,false);
$("div1").addEventListener("dragover",dragover,false);
/*$("physical").addEventListener("drop",drop,false);
$("physical").addEventListener("dragenter",dragenter,false);
$("physical").addEventListener("dragleave",dragleave,false);
$("physical").addEventListener("dragover",dragover,false);*/
//$("physicalnormData").onchange = function(){preview(this,event);};
}
function dragenter(e){
e.preventDefault();
e.stopPropagation();
// if (e.target.id == "second" || e.target.id == "physical"){
// $(e.target.id).style.opacity=1;
// }
}
function dragover(e)
{
e.preventDefault();
e.stopPropagation();
// if (e.target.id == "second" || e.target.id == "physical"){
// $(e.target.id).style.opacity=1;
// }
}
function dragleave(e){
e.preventDefault();
e.stopPropagation();
// if (e.target.id == "second" || e.target.id == "physical"){
// $(e.target.id).style.opacity=.4;
// }
}
function drop(e){
if (e.target.id == "div1" ){
DragUpload.target = {id:e.target.id};
e.preventDefault();
e.stopPropagation();
var files = e.dataTransfer.files;
var xhr = new XMLHttpRequest();
var fd = new FormData();
xhr.open("POST","upload.php");
xhr.onload=function(){
var temp = DragUpload.target.id+"Progress";
$(temp).style.opacity=0;
};
xhr.upload.onprogress=function(e){
if (e.lengthComputable){
var progress = (e.loaded/e.total)*100;
if (progress == 100)
progress = 99.9;
var temp = DragUpload.target.id+"Progress";
$(temp).style.height=progress*(360/100)+"px"; // depend on the height of the progress height
}
};
for (var i in files){
if (files[i].type =="image/jpeg"){
var fr = new FileReader();
fr.onload=openfile;
fr.readAsDataURL(files[i]);
fd.append("ff[]",files[i]);
}
}
xhr.send(fd);
}
}
window.addEventListener("DOMContentLoaded",init,false);