-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajaxUploader.uppit.js
73 lines (59 loc) · 1.87 KB
/
ajaxUploader.uppit.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(function (uppit, document) {
"use strict";
if (!uppit instanceof Object) {
throw new Error('Uppit object not found for ajaxUploader plugin');
}
uppit.plugins.ajaxUploader = (function () {
var upload,
handleFileDrop,
element,
triggerDone,
init,
handleElementSet;
upload = function (file) {
var handleOnload,
xhr,
fd;
fd = new FormData();
xhr = new XMLHttpRequest();
triggerDone = function (file) {
var event = document.createEvent('Event');
event.initEvent('upload.done', true, true);
event.file = file;
event.xhr = xhr;
element.dispatchEvent(event);
};
handleOnload = (function () {
return function (event) {
triggerDone(file);
};
}());
xhr.addEventListener('load', handleOnload);
xhr.upload.onprogress = function (event) {console.log(event);};
xhr.open(
'POST',
'upload.php',
true
);
fd.append('file', file);
xhr.send(fd);
};
handleFileDrop = (function () {
return function (event) {
event.stopPropagation();
upload(event.file);
};
}());
init = function () {
element.addEventListener('filedrop', handleFileDrop);
};
handleElementSet = (function () {
return function (event) {
element = event.elements.element;
init();
};
}());
document.addEventListener('elementSet', handleElementSet);
return {};
}());
})(uppit, window.document);