forked from MrSwitch/dropfile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.htm
80 lines (70 loc) · 1.88 KB
/
demo.htm
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
<!DOCTYPE html>
<html>
<head>
<title>dropfile.js - Drop Files into Browser</title>
<style>
body{
max-width:800px;
margin:0 auto;
font-family:"Sans-Serif";
}
#holder{
border:5px dashed gray;
height:100px;
border-radius:20px;
width:50%;
margin:auto;
font-size:20px;
color:Gray;
text-align:center;
overflow:hidden;
}
#holder ul{
width:100%;
text-align:left;
}
#holder li img{
height:20px;
}
</style>
<script>
window.onload = function () {
/**
* Add drop functionality to our holder,
* This is standard HTML5 File API
*/
var holder = document.getElementById('holder');
holder.ondragover = function () { return false; };
holder.ondragenter = function () { return false; };
holder.ondrop = function (e) {
e = e || window.event;
var files = (e.files || e.dataTransfer.files);
var s = "";
for (var i = 0; i < files.length; i++) {
(function (i) {
var reader = new FileReader();
reader.onload = function (event) {
holder.innerHTML = "<li><img src='" + event.target.result + "' /> " + (files[i].name) + "</li>" + holder.innerHTML;
};
reader.readAsDataURL(files[i]);
})(i);
}
return false;
};
}
</script>
</head>
<body>
<h1>Drag and drop file demo</h1>
<div id="holder">
Drop files from desktop here
</div >
<!-- Include our drop file fix -->
<script src="dropfile.js"></script>
<script>
if( !window.dropfile ){
document.getElementById("holder").innerHTML = "Ouch this browser doesn't support this fix";
}
</script>
</body>
</html>