This repository has been archived by the owner on May 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
/
example.html
80 lines (72 loc) · 3.37 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
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script src="jquery.html5_upload.js" type="text/javascript"></script>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<style>
#drop_area.file_hover {
background:red;
}
</style>
</head>
<body>
<input type="file" multiple="multiple" id="upload_field" />
<div id="drop_area" style="margin:20px 0; width:300px; padding:20px; border:1px dashed black;">or drop file(s) here</div>
<div id="progress_report">
<div id="progress_report_name"></div>
<div id="progress_report_status" style="font-style: italic;"></div>
<div id="progress_report_bar_container" style="width: 90%; height: 5px;">
<div id="progress_report_bar" style="background-color: blue; width: 0; height: 100%;"></div>
</div>
</div>
<script type="text/javascript">
$(function() {
var $input = $("#upload_field").html5_upload({
url: function(number) {
return prompt(number + " url", "/");
},
sendBoundary: window.FormData || $.browser.mozilla,
onStart: function(event, total) {
return true;
return confirm("You are trying to upload " + total + " files. Are you sure?");
},
onProgress: function(event, progress, name, number, total) {
console.log(progress, number);
},
setName: function(text) {
$("#progress_report_name").text(text);
},
setStatus: function(text) {
$("#progress_report_status").text(text);
},
setProgress: function(val) {
$("#progress_report_bar").css('width', Math.ceil(val*100)+"%");
},
onFinishOne: function(event, response, name, number, total) {
//alert(response);
},
onError: function(event, name, error) {
alert('error while uploading file ' + name);
}
});
// Example of how to use this with a html5 drop event
// this is absolutely necessary -- see http://weblog.bocoup.com/using-datatransfer-with-jquery-events/
$.event.props.push('dataTransfer');
var $drop = $('#drop_area');
$drop.on( 'dragover dragenter', function(e){
$drop.addClass('file_hover');
return false;
}).on( 'dragleave dragexit', function(e){
$drop.removeClass('file_hover');
return false;
}).on( 'drop', function(e){
if(e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files.length) {
$input.trigger('html5_upload.startFromDrop', e );
}
return false;
})
});
</script>
</body>
</html>