This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdemo-jquery.htm
86 lines (74 loc) · 1.98 KB
/
demo-jquery.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
81
82
83
84
85
86
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/adorn/adorn.css"/>
<script src="/adorn/adorn.js"></script>
<title>Drop Files into Browser</title>
<style type="text/css">
#silverlightControlHost {
height: 100%;
text-align:center;
}
#holder{
border:1px solid lightgray;
height:100px;
font-size:20px;
color:gray;
text-align:center;
padding:20px;
}
#holder ul{
width:100%;
text-align:left;
}
#holder li img{
height:20px;
}
</style>
</head>
<body>
<h1>Drag and drop file demo with jQuery Event binding</h1>
<div id="holder">
Drop files from desktop here
</div>
<h2>Source</h2>
<p>Include jQuery and shim</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" class="pre"></script>
<script src="dropfile.js" class="pre"></script>
<p>Add DOM created event to add events and cancel some defaults</p>
<script class="pre">
$(document).ready(function () {
/**
* Add drop functionality to our holder,
* This is standard HTML5 File API
*/
var ignoreDrag = function(e) {
var event = typeof e.originalEvent != 'undefined' ? e.originalEvent : e;
if (event.stopPropagation) {
event.stopPropagation();
}
if (event.preventDefault) {
event.preventDefault();
}
};
$("#holder").bind('dragover', ignoreDrag).bind('dragenter', ignoreDrag).bind('drop', function(e){
var holder= this;
e = (e&&e.originalEvent?e.originalEvent:window.event) || e;
ignoreDrag(e);
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>
</body>
</html>