-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
50 lines (36 loc) · 976 Bytes
/
script.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
$(document).ready(function() {
jQuery.event.props.push('dataTransfer');
$(document).on('dragenter', function(e) {
e.preventDefault();
$('#dropbox').addClass('drag');
});
$(document).on('dragleave', function(e) {
e.preventDefault();
});
$(document).on('drop', function(e) {
e.preventDefault();
var files = e.dataTransfer.files;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var file_content = null;
var reader = new FileReader();
var load_times = 0;
reader.onload = (function(current) {
return function(e) {
$('#temp').append('<input type="hidden" name="photo[' + current.name + ']" value="' + e.target.result + '" />');
load_times++;
};
})(file);
reader.onloadend = function() {
if (load_times == files.length) {
$('#form').submit();
$('#temp').html('');
}
}
reader.readAsDataURL(file);
}
});
$('#file').on('change', function() {
$('#form').submit();
});
});