fine_uploader 3.1.1 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +1 -3
- data/Vendorfile +16 -5
- data/lib/fine_uploader/version.rb +1 -1
- data/vendor/assets/javascripts/fine_uploader/ajax.requester.js +184 -0
- data/vendor/assets/javascripts/fine_uploader/button.js +62 -58
- data/vendor/assets/javascripts/fine_uploader/deletefile.ajax.requester.js +44 -0
- data/vendor/assets/javascripts/fine_uploader/dnd.js +2 -0
- data/vendor/assets/javascripts/fine_uploader/handler.base.js +164 -92
- data/vendor/assets/javascripts/fine_uploader/handler.form.js +220 -133
- data/vendor/assets/javascripts/fine_uploader/handler.xhr.js +594 -132
- data/vendor/assets/javascripts/fine_uploader/header.js +3 -4
- data/vendor/assets/javascripts/fine_uploader/iframe.xss.response.js +6 -0
- data/vendor/assets/javascripts/fine_uploader/jquery-plugin.js +13 -4
- data/vendor/assets/javascripts/fine_uploader/paste.js +49 -0
- data/vendor/assets/javascripts/fine_uploader/promise.js +45 -0
- data/vendor/assets/javascripts/fine_uploader/uploader.basic.js +547 -175
- data/vendor/assets/javascripts/fine_uploader/uploader.js +197 -42
- data/vendor/assets/javascripts/fine_uploader/util.js +117 -12
- data/vendor/assets/javascripts/fine_uploader/window.receive.message.js +32 -0
- data/vendor/assets/javascripts/fine_uploader.js +17 -0
- data/vendor/assets/stylesheets/fine_uploader.css.scss +6 -7
- metadata +9 -2
@@ -1,115 +1,187 @@
|
|
1
1
|
/**
|
2
2
|
* Class for uploading files, uploading itself is handled by child classes
|
3
3
|
*/
|
4
|
-
qq
|
4
|
+
/*globals qq*/
|
5
|
+
qq.UploadHandler = function(o) {
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
var queue = [],
|
9
|
+
options, log, dequeue, handlerImpl;
|
10
|
+
|
5
11
|
// Default options, can be overridden by the user
|
6
|
-
|
12
|
+
options = {
|
7
13
|
debug: false,
|
8
|
-
|
14
|
+
forceMultipart: true,
|
9
15
|
paramsInBody: false,
|
10
|
-
|
11
|
-
|
16
|
+
paramsStore: {},
|
17
|
+
endpointStore: {},
|
18
|
+
cors: {
|
19
|
+
expected: false,
|
20
|
+
sendCredentials: false
|
21
|
+
},
|
22
|
+
maxConnections: 3, // maximum number of concurrent uploads
|
23
|
+
uuidParamName: 'qquuid',
|
24
|
+
totalFileSizeParamName: 'qqtotalfilesize',
|
25
|
+
chunking: {
|
26
|
+
enabled: false,
|
27
|
+
partSize: 2000000, //bytes
|
28
|
+
paramNames: {
|
29
|
+
partIndex: 'qqpartindex',
|
30
|
+
partByteOffset: 'qqpartbyteoffset',
|
31
|
+
chunkSize: 'qqchunksize',
|
32
|
+
totalParts: 'qqtotalparts',
|
33
|
+
filename: 'qqfilename'
|
34
|
+
}
|
35
|
+
},
|
36
|
+
resume: {
|
37
|
+
enabled: false,
|
38
|
+
id: null,
|
39
|
+
cookiesExpireIn: 7, //days
|
40
|
+
paramNames: {
|
41
|
+
resuming: "qqresume"
|
42
|
+
}
|
43
|
+
},
|
44
|
+
blobs: {
|
45
|
+
paramNames: {
|
46
|
+
name: 'qqblobname'
|
47
|
+
}
|
48
|
+
},
|
12
49
|
log: function(str, level) {},
|
13
50
|
onProgress: function(id, fileName, loaded, total){},
|
14
51
|
onComplete: function(id, fileName, response, xhr){},
|
15
52
|
onCancel: function(id, fileName){},
|
16
|
-
onUpload: function(id, fileName
|
17
|
-
|
53
|
+
onUpload: function(id, fileName){},
|
54
|
+
onUploadChunk: function(id, fileName, chunkData){},
|
55
|
+
onAutoRetry: function(id, fileName, response, xhr){},
|
56
|
+
onResume: function(id, fileName, chunkData){}
|
18
57
|
|
19
58
|
};
|
20
|
-
qq.extend(
|
59
|
+
qq.extend(options, o);
|
21
60
|
|
22
|
-
|
61
|
+
log = options.log;
|
23
62
|
|
24
|
-
this.log = this._options.log;
|
25
|
-
};
|
26
|
-
qq.UploadHandlerAbstract.prototype = {
|
27
63
|
/**
|
28
|
-
*
|
29
|
-
* @returns id
|
30
|
-
**/
|
31
|
-
add: function(file){},
|
32
|
-
/**
|
33
|
-
* Sends the file identified by id
|
64
|
+
* Removes element from queue, starts upload of next
|
34
65
|
*/
|
35
|
-
|
36
|
-
var
|
66
|
+
dequeue = function(id) {
|
67
|
+
var i = qq.indexOf(queue, id),
|
68
|
+
max = options.maxConnections,
|
69
|
+
nextId;
|
37
70
|
|
38
|
-
// if too many active uploads, wait...
|
39
|
-
if (len <= this._options.maxConnections){
|
40
|
-
this._upload(id);
|
41
|
-
}
|
42
|
-
},
|
43
|
-
retry: function(id) {
|
44
|
-
var i = qq.indexOf(this._queue, id);
|
45
71
|
if (i >= 0) {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Cancels file upload by id
|
54
|
-
*/
|
55
|
-
cancel: function(id){
|
56
|
-
this.log('Cancelling ' + id);
|
57
|
-
this._options.paramsStore.remove(id);
|
58
|
-
this._cancel(id);
|
59
|
-
this._dequeue(id);
|
60
|
-
},
|
61
|
-
/**
|
62
|
-
* Cancells all uploads
|
63
|
-
*/
|
64
|
-
cancelAll: function(){
|
65
|
-
for (var i=0; i<this._queue.length; i++){
|
66
|
-
this._cancel(this._queue[i]);
|
72
|
+
queue.splice(i, 1);
|
73
|
+
|
74
|
+
if (queue.length >= max && i < max){
|
75
|
+
nextId = queue[max-1];
|
76
|
+
handlerImpl.upload(nextId);
|
77
|
+
}
|
67
78
|
}
|
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
|
-
_upload: function(id){},
|
93
|
-
/**
|
94
|
-
* Actual cancel method
|
95
|
-
*/
|
96
|
-
_cancel: function(id){},
|
97
|
-
/**
|
98
|
-
* Removes element from queue, starts upload of next
|
99
|
-
*/
|
100
|
-
_dequeue: function(id){
|
101
|
-
var i = qq.indexOf(this._queue, id);
|
102
|
-
this._queue.splice(i, 1);
|
79
|
+
};
|
80
|
+
|
81
|
+
if (qq.isXhrUploadSupported()) {
|
82
|
+
handlerImpl = new qq.UploadHandlerXhr(options, dequeue, log);
|
83
|
+
}
|
84
|
+
else {
|
85
|
+
handlerImpl = new qq.UploadHandlerForm(options, dequeue, log);
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
return {
|
90
|
+
/**
|
91
|
+
* Adds file or file input to the queue
|
92
|
+
* @returns id
|
93
|
+
**/
|
94
|
+
add: function(file){
|
95
|
+
return handlerImpl.add(file);
|
96
|
+
},
|
97
|
+
/**
|
98
|
+
* Sends the file identified by id
|
99
|
+
*/
|
100
|
+
upload: function(id){
|
101
|
+
var len = queue.push(id);
|
103
102
|
|
104
|
-
|
103
|
+
// if too many active uploads, wait...
|
104
|
+
if (len <= options.maxConnections){
|
105
|
+
return handlerImpl.upload(id);
|
106
|
+
}
|
107
|
+
},
|
108
|
+
retry: function(id) {
|
109
|
+
var i = qq.indexOf(queue, id);
|
110
|
+
if (i >= 0) {
|
111
|
+
return handlerImpl.upload(id, true);
|
112
|
+
}
|
113
|
+
else {
|
114
|
+
return this.upload(id);
|
115
|
+
}
|
116
|
+
},
|
117
|
+
/**
|
118
|
+
* Cancels file upload by id
|
119
|
+
*/
|
120
|
+
cancel: function(id) {
|
121
|
+
log('Cancelling ' + id);
|
122
|
+
options.paramsStore.remove(id);
|
123
|
+
handlerImpl.cancel(id);
|
124
|
+
dequeue(id);
|
125
|
+
},
|
126
|
+
/**
|
127
|
+
* Cancels all queued or in-progress uploads
|
128
|
+
*/
|
129
|
+
cancelAll: function() {
|
130
|
+
var self = this,
|
131
|
+
queueCopy = [];
|
105
132
|
|
106
|
-
|
107
|
-
|
108
|
-
|
133
|
+
qq.extend(queueCopy, queue);
|
134
|
+
qq.each(queueCopy, function(idx, fileId) {
|
135
|
+
self.cancel(fileId);
|
136
|
+
});
|
137
|
+
|
138
|
+
queue = [];
|
139
|
+
},
|
140
|
+
/**
|
141
|
+
* Returns name of the file identified by id
|
142
|
+
*/
|
143
|
+
getName: function(id){
|
144
|
+
return handlerImpl.getName(id);
|
145
|
+
},
|
146
|
+
/**
|
147
|
+
* Returns size of the file identified by id
|
148
|
+
*/
|
149
|
+
getSize: function(id){
|
150
|
+
if (handlerImpl.getSize) {
|
151
|
+
return handlerImpl.getSize(id);
|
152
|
+
}
|
153
|
+
},
|
154
|
+
getFile: function(id) {
|
155
|
+
if (handlerImpl.getFile) {
|
156
|
+
return handlerImpl.getFile(id);
|
157
|
+
}
|
158
|
+
},
|
159
|
+
/**
|
160
|
+
* Returns id of files being uploaded or
|
161
|
+
* waiting for their turn
|
162
|
+
*/
|
163
|
+
getQueue: function(){
|
164
|
+
return queue;
|
165
|
+
},
|
166
|
+
reset: function() {
|
167
|
+
log('Resetting upload handler');
|
168
|
+
queue = [];
|
169
|
+
handlerImpl.reset();
|
170
|
+
},
|
171
|
+
getUuid: function(id) {
|
172
|
+
return handlerImpl.getUuid(id);
|
173
|
+
},
|
174
|
+
/**
|
175
|
+
* Determine if the file exists.
|
176
|
+
*/
|
177
|
+
isValid: function(id) {
|
178
|
+
return handlerImpl.isValid(id);
|
179
|
+
},
|
180
|
+
getResumableFilesData: function() {
|
181
|
+
if (handlerImpl.getResumableFilesData) {
|
182
|
+
return handlerImpl.getResumableFilesData();
|
183
|
+
}
|
184
|
+
return [];
|
109
185
|
}
|
110
|
-
}
|
111
|
-
/**
|
112
|
-
* Determine if the file exists.
|
113
|
-
*/
|
114
|
-
isValid: function(id) {}
|
186
|
+
};
|
115
187
|
};
|