-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrag-and-drop.js
More file actions
59 lines (46 loc) · 1.56 KB
/
drag-and-drop.js
File metadata and controls
59 lines (46 loc) · 1.56 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
49
50
51
52
53
54
55
56
57
58
59
/*
filedrag.js - HTML5 File Drag & Drop demonstration
Featured on SitePoint.com
Developed by Craig Buckler (@craigbuckler) of OptimalWorks.net
Extended by Clinton Pahl
*/
$(document).ready(function() {
var html = '<div class="filedrag"> \
<span><span></span></span> \
<span class="status info">Drop File or Click Here</span> \
</div> ';
$.fn.dragAndDrop = function() {
var dragAndDrop = this;
var input = $(this);
input.wrap(html);
var container = $(this).closest('.filedrag');
$(input).on('change', function(e) {
files = this.files;
dragAndDrop.dropFile = files[0];
parseFile(dragAndDrop.dropFile);
});
$(container).on('dragenter dragover', function (e) {
$(this).addClass("hover");
});
$(container).on('dragleave', function (e) {
$(this).removeClass("hover");
});
$(container).on('drop', function (e) {
$(this).removeClass("hover");
});
// output file information
function parseFile(file) {
output(
"<p>File: <strong>" + file.name +
"</strong> Type: <strong>" + file.type +
"</strong> Size: <strong>" + file.size +
"</strong> bytes</p>"
);
}
// output information
function output(msg) {
container.find('.status').removeClass("info").addClass("info-file").html(msg);
}
return this;
}
});