resumablejs-rails 1.0 → 1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/resumablejs-rails/version.rb +1 -1
- data/vendor/assets/javascripts/resumable.js +153 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bff07b24aa9de454899e5e82e8badee9e9d0c955
|
4
|
+
data.tar.gz: 71402b518edf6ee1a23843a6998a43f4abf46196
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5c525555bedc63a1d782b49161221028a54b8a7db326511e654403f132a47bb7cfc36e109e9d47e92703764da82df50787bc7f3aebfeb3254b9adacc7f2231f
|
7
|
+
data.tar.gz: 5ba6fcc5c4ba9514a046d487a61c457bfba0750afc5cdcedb81e1f82ddfa28d1b4732dc9212f27cba094ef3235ef5833e6b8ab775473d4545002e39b2f902ba0
|
@@ -50,7 +50,7 @@
|
|
50
50
|
generateUniqueIdentifier:null,
|
51
51
|
maxChunkRetries:undefined,
|
52
52
|
chunkRetryInterval:undefined,
|
53
|
-
permanentErrors:[404, 415, 500, 501],
|
53
|
+
permanentErrors:[400, 404, 415, 500, 501],
|
54
54
|
maxFiles:undefined,
|
55
55
|
withCredentials:false,
|
56
56
|
xhrTimeout:0,
|
@@ -185,13 +185,146 @@
|
|
185
185
|
|
186
186
|
var onDrop = function(event){
|
187
187
|
$h.stopEvent(event);
|
188
|
-
|
188
|
+
|
189
|
+
//handle dropped things as items if we can (this lets us deal with folders nicer in some cases)
|
190
|
+
if (event.dataTransfer && event.dataTransfer.items) {
|
191
|
+
loadFiles(event.dataTransfer.items, event);
|
192
|
+
}
|
193
|
+
//else handle them as files
|
194
|
+
else if (event.dataTransfer && event.dataTransfer.files) {
|
195
|
+
loadFiles(event.dataTransfer.files, event);
|
196
|
+
}
|
189
197
|
};
|
190
198
|
var onDragOver = function(e) {
|
191
199
|
e.preventDefault();
|
192
200
|
};
|
193
201
|
|
194
202
|
// INTERNAL METHODS (both handy and responsible for the heavy load)
|
203
|
+
/**
|
204
|
+
* @summary This function loops over the files passed in from a drag and drop operation and gets them ready for appendFilesFromFileList
|
205
|
+
* It attempts to use FileSystem API calls to extract files and subfolders if the dropped items include folders
|
206
|
+
* That capability is only currently available in Chrome, but if it isn't available it will just pass the items along to
|
207
|
+
* appendFilesFromFileList (via enqueueFileAddition to help with asynchronous processing.)
|
208
|
+
* @param files {Array} - the File or Entry objects to be processed depending on your browser support
|
209
|
+
* @param event {Object} - the drop event object
|
210
|
+
* @param [queue] {Object} - an object to keep track of our progress processing the dropped items
|
211
|
+
* @param [path] {String} - the relative path from the originally selected folder to the current files if extracting files from subfolders
|
212
|
+
*/
|
213
|
+
var loadFiles = function (files, event, queue, path){
|
214
|
+
//initialize the queue object if it doesn't exist
|
215
|
+
if (!queue) {
|
216
|
+
queue = {
|
217
|
+
total: 0,
|
218
|
+
files: [],
|
219
|
+
event: event
|
220
|
+
};
|
221
|
+
}
|
222
|
+
|
223
|
+
//update the total number of things we plan to process
|
224
|
+
updateQueueTotal(files.length, queue);
|
225
|
+
|
226
|
+
//loop over all the passed in objects checking if they are files or folders
|
227
|
+
for (var i = 0; i < files.length; i++) {
|
228
|
+
var file = files[i];
|
229
|
+
var entry, reader;
|
230
|
+
|
231
|
+
if (file.isFile || file.isDirectory) {
|
232
|
+
//this is an object we can handle below with no extra work needed up front
|
233
|
+
entry = file;
|
234
|
+
}
|
235
|
+
else if (file.getAsEntry) {
|
236
|
+
//get the file as an entry object if we can using the proposed HTML5 api (unlikely to get implemented by anyone)
|
237
|
+
entry = file.getAsEntry();
|
238
|
+
}
|
239
|
+
else if (file.webkitGetAsEntry) {
|
240
|
+
//get the file as an entry object if we can using the Chrome specific webkit implementation
|
241
|
+
entry = file.webkitGetAsEntry();
|
242
|
+
}
|
243
|
+
else if (typeof file.getAsFile === 'function') {
|
244
|
+
//if this is still a DataTransferItem object, get it as a file object
|
245
|
+
enqueueFileAddition(file.getAsFile(), queue, path);
|
246
|
+
//we just added this file object to the queue so we can go to the next object in the loop and skip the processing below
|
247
|
+
continue;
|
248
|
+
}
|
249
|
+
else if (File && file instanceof File) {
|
250
|
+
//this is already a file object so just queue it up and move on
|
251
|
+
enqueueFileAddition(file, queue, path);
|
252
|
+
//we just added this file object to the queue so we can go to the next object in the loop and skip the processing below
|
253
|
+
continue;
|
254
|
+
}
|
255
|
+
else {
|
256
|
+
//we can't do anything with this object, decrement the expected total and skip the processing below
|
257
|
+
updateQueueTotal(-1, queue);
|
258
|
+
continue;
|
259
|
+
}
|
260
|
+
|
261
|
+
if (!entry) {
|
262
|
+
//there isn't anything we can do with this so decrement the total expected
|
263
|
+
updateQueueTotal(-1, queue);
|
264
|
+
}
|
265
|
+
else if (entry.isFile) {
|
266
|
+
//this is handling to read an entry object representing a file, parsing the file object is asynchronous which is why we need the queue
|
267
|
+
//currently entry objects will only exist in this flow for Chrome
|
268
|
+
entry.file(function(file) {
|
269
|
+
enqueueFileAddition(file, queue, path);
|
270
|
+
}, function(err) {
|
271
|
+
console.warn(err);
|
272
|
+
});
|
273
|
+
}
|
274
|
+
else if (entry.isDirectory) {
|
275
|
+
//this is handling to read an entry object representing a folder, parsing the directory object is asynchronous which is why we need the queue
|
276
|
+
//currently entry objects will only exist in this flow for Chrome
|
277
|
+
reader = entry.createReader();
|
278
|
+
|
279
|
+
//wrap the callback in another function so we can store the path in a closure
|
280
|
+
var readDir = function(path){
|
281
|
+
return function(entries){
|
282
|
+
//process each thing in this directory recursively
|
283
|
+
loadFiles(entries, event, queue, path);
|
284
|
+
//this was a directory rather than a file so decrement the expected file count
|
285
|
+
updateQueueTotal(-1, queue);
|
286
|
+
}
|
287
|
+
};
|
288
|
+
|
289
|
+
reader.readEntries(readDir(entry.fullPath), function(err) {
|
290
|
+
console.warn(err);
|
291
|
+
});
|
292
|
+
}
|
293
|
+
}
|
294
|
+
};
|
295
|
+
|
296
|
+
/**
|
297
|
+
* @summary Adjust the total number of files we are expecting to process
|
298
|
+
* if decrementing and the new expected total is equal to the number processed, flush the queue
|
299
|
+
* @param addition {Number} - the number of additional files we expect to process (may be negative)
|
300
|
+
* @param queue {Object} - an object to keep track of our progress processing the dropped items
|
301
|
+
*/
|
302
|
+
var updateQueueTotal = function(addition, queue){
|
303
|
+
queue.total += addition;
|
304
|
+
|
305
|
+
// If all the files we expect have shown up, then flush the queue.
|
306
|
+
if (queue.files.length === queue.total) {
|
307
|
+
appendFilesFromFileList(queue.files, queue.event);
|
308
|
+
}
|
309
|
+
};
|
310
|
+
|
311
|
+
/**
|
312
|
+
* @summary Add a file to the queue of processed files, if it brings the total up to the expected total, flush the queue
|
313
|
+
* @param file {Object} - File object to be passed along to appendFilesFromFileList eventually
|
314
|
+
* @param queue {Object} - an object to keep track of our progress processing the dropped items
|
315
|
+
* @param [path] {String} - the file's relative path from the originally dropped folder if we are parsing folder content (Chrome only for now)
|
316
|
+
*/
|
317
|
+
var enqueueFileAddition = function(file, queue, path) {
|
318
|
+
//store the path to this file if it came in as part of a folder
|
319
|
+
if (path) file.relativePath = path + '/' + file.name;
|
320
|
+
queue.files.push(file);
|
321
|
+
|
322
|
+
// If all the files we expect have shown up, then flush the queue.
|
323
|
+
if (queue.files.length === queue.total) {
|
324
|
+
appendFilesFromFileList(queue.files, queue.event);
|
325
|
+
}
|
326
|
+
};
|
327
|
+
|
195
328
|
var appendFilesFromFileList = function(fileList, event){
|
196
329
|
// check for uploading too many files
|
197
330
|
var errorCount = 0;
|
@@ -207,13 +340,21 @@
|
|
207
340
|
}
|
208
341
|
var files = [];
|
209
342
|
$h.each(fileList, function(file){
|
210
|
-
var fileName = file.name
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
343
|
+
var fileName = file.name;
|
344
|
+
if(o.fileType.length > 0){
|
345
|
+
var fileTypeFound = false;
|
346
|
+
for(var index in o.fileType){
|
347
|
+
var extension = '.' + o.fileType[index];
|
348
|
+
if(fileName.indexOf(extension, fileName.length - extension.length) !== -1){
|
349
|
+
fileTypeFound = true;
|
350
|
+
break;
|
216
351
|
}
|
352
|
+
}
|
353
|
+
if (!fileTypeFound) {
|
354
|
+
o.fileTypeErrorCallback(file, errorCount++);
|
355
|
+
return false;
|
356
|
+
}
|
357
|
+
}
|
217
358
|
|
218
359
|
if (typeof(o.minFileSize)!=='undefined' && file.size<o.minFileSize) {
|
219
360
|
o.minFileSizeErrorCallback(file, errorCount++);
|
@@ -250,7 +391,7 @@
|
|
250
391
|
$.file = file;
|
251
392
|
$.fileName = file.fileName||file.name; // Some confusion in different versions of Firefox
|
252
393
|
$.size = file.size;
|
253
|
-
$.relativePath = file.webkitRelativePath || $.fileName;
|
394
|
+
$.relativePath = file.webkitRelativePath || file.relativePath || $.fileName;
|
254
395
|
$.uniqueIdentifier = $h.generateUniqueIdentifier(file);
|
255
396
|
$._pause = false;
|
256
397
|
$.container = '';
|
@@ -345,7 +486,7 @@
|
|
345
486
|
if(c.status()=='error') error = true;
|
346
487
|
ret += c.progress(true); // get chunk progress relative to entire file
|
347
488
|
});
|
348
|
-
ret = (error ? 1 : (ret>0.
|
489
|
+
ret = (error ? 1 : (ret>0.99999 ? 1 : ret));
|
349
490
|
ret = Math.max($._prevProgress, ret); // We don't want to lose percentages when an upload is paused
|
350
491
|
$._prevProgress = ret;
|
351
492
|
return(ret);
|
@@ -433,6 +574,7 @@
|
|
433
574
|
};
|
434
575
|
$.xhr.addEventListener('load', testHandler, false);
|
435
576
|
$.xhr.addEventListener('error', testHandler, false);
|
577
|
+
$.xhr.addEventListener('timeout', testHandler, false);
|
436
578
|
|
437
579
|
// Add data from the query options
|
438
580
|
var params = [];
|
@@ -518,6 +660,7 @@
|
|
518
660
|
};
|
519
661
|
$.xhr.addEventListener('load', doneHandler, false);
|
520
662
|
$.xhr.addEventListener('error', doneHandler, false);
|
663
|
+
$.xhr.addEventListener('timeout', doneHandler, false);
|
521
664
|
|
522
665
|
// Set up the basic query data from Resumable
|
523
666
|
var query = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resumablejs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- beanie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
version: '0'
|
62
62
|
requirements: []
|
63
63
|
rubyforge_project:
|
64
|
-
rubygems_version: 2.
|
64
|
+
rubygems_version: 2.4.5
|
65
65
|
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: resumable.js for the Rails Asset Pipeline
|