forked from weixiyen/jquery-filedrop
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Example.html
executable file
·114 lines (97 loc) · 2.55 KB
/
Example.html
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
body {
background-color: #000;
color: #fff;
font-family: sans-serif;
}
.dropUpload .dropArea {
background-color: rgba(255,255,255, .3);
height: 120px;
margin: 10px 0;
width: 200px;
}
.dropUpload .messages {
font-family: monospace;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.dropUpload.js"></script>
</head>
<body>
<form action="ReceiveFile.php" method="post">
<div class="dropUpload">
<input type="text" name="customVariable1" value="Just a custom variable that are attached to the file on at drop-time">
<div class="dropArea">
<span>Drop Files Here</span>
</div>
<div class="queue">
<div class="items">
</div>
</div>
<pre class="messages">
</pre>
</div>
</form>
<script type="text/javascript">
var queueItemTemplate = '<div class="item"><div class="fileName">-</div><div class="progressBar"><div class="progress"></div></div></div>';
var dropUpload = $('.dropUpload');
var dropArea = dropUpload.find('.dropArea');
var queue = dropUpload.find('.queue');
var messages = dropUpload.find('.messages');
var form = dropUpload.parent('form');
dropArea.dropUpload(
{
'url': form.attr('action'),
'fileMeta': function()
{
var meta = {};
$.each(form.serializeArray(), function(i) {
meta[this.name] = this.value;
});
return meta; // Attach form data to each dropped file
},
'fileParamName': 'file',
'fileSizeMax': null,
'onDragEnter': function()
{
dropArea.addClass('isHovering');
},
'onDragLeave': function()
{
dropArea.removeClass('isHovering');
},
'onDropSuccess': function()
{
messages.html(''); // Empties message area at drop
dropArea.removeClass('isHovering');
},
'onProgressUpdated': function(File, progress)
{
File.queueItem.find('.progress').css('width', (progress * 100) + '%');
},
'onFileCompleted': function(File)
{
File.queueItem.remove(); // Removed DOM queue item on completion
},
'onFileQueued': function(File) // Created DOM queue item and attaches it to the File object
{
var qi = $(queueItemTemplate);
qi.find('.fileName').html(File.name);
qi.appendTo(queue);
File.queueItem = qi;
},
'onFileSucceeded': function(File, response)
{
messages.text(response);
},
'onQueueCompleted': function()
{
alert("All done");
}
});
</script>
</body>
</html>