dropzonejs-rails4 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/assets/images/dropzonejs/spritemap.png +0 -0
- data/app/assets/images/dropzonejs/spritemap@2x.png +0 -0
- data/app/assets/javascripts/dropzonejs/dropzone-amd-module.js +1514 -0
- data/app/assets/javascripts/dropzonejs/dropzone.js +1721 -0
- data/app/assets/stylesheets/dropzonejs/basic.css.scss +154 -0
- data/app/assets/stylesheets/dropzonejs/dropzone.css.scss +410 -0
- data/dropzonejs-rails4.gemspec +24 -0
- data/lib/dropzonejs/rails4.rb +8 -0
- data/lib/dropzonejs/rails4/engine.rb +6 -0
- data/lib/dropzonejs/rails4/version.rb +6 -0
- metadata +100 -0
@@ -0,0 +1,1721 @@
|
|
1
|
+
;(function(){
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Require the given path.
|
5
|
+
*
|
6
|
+
* @param {String} path
|
7
|
+
* @return {Object} exports
|
8
|
+
* @api public
|
9
|
+
*/
|
10
|
+
|
11
|
+
function require(path, parent, orig) {
|
12
|
+
var resolved = require.resolve(path);
|
13
|
+
|
14
|
+
// lookup failed
|
15
|
+
if (null == resolved) {
|
16
|
+
orig = orig || path;
|
17
|
+
parent = parent || 'root';
|
18
|
+
var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
|
19
|
+
err.path = orig;
|
20
|
+
err.parent = parent;
|
21
|
+
err.require = true;
|
22
|
+
throw err;
|
23
|
+
}
|
24
|
+
|
25
|
+
var module = require.modules[resolved];
|
26
|
+
|
27
|
+
// perform real require()
|
28
|
+
// by invoking the module's
|
29
|
+
// registered function
|
30
|
+
if (!module.exports) {
|
31
|
+
module.exports = {};
|
32
|
+
module.client = module.component = true;
|
33
|
+
module.call(this, module.exports, require.relative(resolved), module);
|
34
|
+
}
|
35
|
+
|
36
|
+
return module.exports;
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Registered modules.
|
41
|
+
*/
|
42
|
+
|
43
|
+
require.modules = {};
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Registered aliases.
|
47
|
+
*/
|
48
|
+
|
49
|
+
require.aliases = {};
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Resolve `path`.
|
53
|
+
*
|
54
|
+
* Lookup:
|
55
|
+
*
|
56
|
+
* - PATH/index.js
|
57
|
+
* - PATH.js
|
58
|
+
* - PATH
|
59
|
+
*
|
60
|
+
* @param {String} path
|
61
|
+
* @return {String} path or null
|
62
|
+
* @api private
|
63
|
+
*/
|
64
|
+
|
65
|
+
require.resolve = function(path) {
|
66
|
+
if (path.charAt(0) === '/') path = path.slice(1);
|
67
|
+
|
68
|
+
var paths = [
|
69
|
+
path,
|
70
|
+
path + '.js',
|
71
|
+
path + '.json',
|
72
|
+
path + '/index.js',
|
73
|
+
path + '/index.json'
|
74
|
+
];
|
75
|
+
|
76
|
+
for (var i = 0; i < paths.length; i++) {
|
77
|
+
var path = paths[i];
|
78
|
+
if (require.modules.hasOwnProperty(path)) return path;
|
79
|
+
if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
|
80
|
+
}
|
81
|
+
};
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Normalize `path` relative to the current path.
|
85
|
+
*
|
86
|
+
* @param {String} curr
|
87
|
+
* @param {String} path
|
88
|
+
* @return {String}
|
89
|
+
* @api private
|
90
|
+
*/
|
91
|
+
|
92
|
+
require.normalize = function(curr, path) {
|
93
|
+
var segs = [];
|
94
|
+
|
95
|
+
if ('.' != path.charAt(0)) return path;
|
96
|
+
|
97
|
+
curr = curr.split('/');
|
98
|
+
path = path.split('/');
|
99
|
+
|
100
|
+
for (var i = 0; i < path.length; ++i) {
|
101
|
+
if ('..' == path[i]) {
|
102
|
+
curr.pop();
|
103
|
+
} else if ('.' != path[i] && '' != path[i]) {
|
104
|
+
segs.push(path[i]);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
return curr.concat(segs).join('/');
|
109
|
+
};
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Register module at `path` with callback `definition`.
|
113
|
+
*
|
114
|
+
* @param {String} path
|
115
|
+
* @param {Function} definition
|
116
|
+
* @api private
|
117
|
+
*/
|
118
|
+
|
119
|
+
require.register = function(path, definition) {
|
120
|
+
require.modules[path] = definition;
|
121
|
+
};
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Alias a module definition.
|
125
|
+
*
|
126
|
+
* @param {String} from
|
127
|
+
* @param {String} to
|
128
|
+
* @api private
|
129
|
+
*/
|
130
|
+
|
131
|
+
require.alias = function(from, to) {
|
132
|
+
if (!require.modules.hasOwnProperty(from)) {
|
133
|
+
throw new Error('Failed to alias "' + from + '", it does not exist');
|
134
|
+
}
|
135
|
+
require.aliases[to] = from;
|
136
|
+
};
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Return a require function relative to the `parent` path.
|
140
|
+
*
|
141
|
+
* @param {String} parent
|
142
|
+
* @return {Function}
|
143
|
+
* @api private
|
144
|
+
*/
|
145
|
+
|
146
|
+
require.relative = function(parent) {
|
147
|
+
var p = require.normalize(parent, '..');
|
148
|
+
|
149
|
+
/**
|
150
|
+
* lastIndexOf helper.
|
151
|
+
*/
|
152
|
+
|
153
|
+
function lastIndexOf(arr, obj) {
|
154
|
+
var i = arr.length;
|
155
|
+
while (i--) {
|
156
|
+
if (arr[i] === obj) return i;
|
157
|
+
}
|
158
|
+
return -1;
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
* The relative require() itself.
|
163
|
+
*/
|
164
|
+
|
165
|
+
function localRequire(path) {
|
166
|
+
var resolved = localRequire.resolve(path);
|
167
|
+
return require(resolved, parent, path);
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Resolve relative to the parent.
|
172
|
+
*/
|
173
|
+
|
174
|
+
localRequire.resolve = function(path) {
|
175
|
+
var c = path.charAt(0);
|
176
|
+
if ('/' == c) return path.slice(1);
|
177
|
+
if ('.' == c) return require.normalize(p, path);
|
178
|
+
|
179
|
+
// resolve deps by returning
|
180
|
+
// the dep in the nearest "deps"
|
181
|
+
// directory
|
182
|
+
var segs = parent.split('/');
|
183
|
+
var i = lastIndexOf(segs, 'deps') + 1;
|
184
|
+
if (!i) i = 0;
|
185
|
+
path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
|
186
|
+
return path;
|
187
|
+
};
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Check if module is defined at `path`.
|
191
|
+
*/
|
192
|
+
|
193
|
+
localRequire.exists = function(path) {
|
194
|
+
return require.modules.hasOwnProperty(localRequire.resolve(path));
|
195
|
+
};
|
196
|
+
|
197
|
+
return localRequire;
|
198
|
+
};
|
199
|
+
require.register("component-emitter/index.js", function(exports, require, module){
|
200
|
+
|
201
|
+
/**
|
202
|
+
* Expose `Emitter`.
|
203
|
+
*/
|
204
|
+
|
205
|
+
module.exports = Emitter;
|
206
|
+
|
207
|
+
/**
|
208
|
+
* Initialize a new `Emitter`.
|
209
|
+
*
|
210
|
+
* @api public
|
211
|
+
*/
|
212
|
+
|
213
|
+
function Emitter(obj) {
|
214
|
+
if (obj) return mixin(obj);
|
215
|
+
};
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Mixin the emitter properties.
|
219
|
+
*
|
220
|
+
* @param {Object} obj
|
221
|
+
* @return {Object}
|
222
|
+
* @api private
|
223
|
+
*/
|
224
|
+
|
225
|
+
function mixin(obj) {
|
226
|
+
for (var key in Emitter.prototype) {
|
227
|
+
obj[key] = Emitter.prototype[key];
|
228
|
+
}
|
229
|
+
return obj;
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Listen on the given `event` with `fn`.
|
234
|
+
*
|
235
|
+
* @param {String} event
|
236
|
+
* @param {Function} fn
|
237
|
+
* @return {Emitter}
|
238
|
+
* @api public
|
239
|
+
*/
|
240
|
+
|
241
|
+
Emitter.prototype.on = function(event, fn){
|
242
|
+
this._callbacks = this._callbacks || {};
|
243
|
+
(this._callbacks[event] = this._callbacks[event] || [])
|
244
|
+
.push(fn);
|
245
|
+
return this;
|
246
|
+
};
|
247
|
+
|
248
|
+
/**
|
249
|
+
* Adds an `event` listener that will be invoked a single
|
250
|
+
* time then automatically removed.
|
251
|
+
*
|
252
|
+
* @param {String} event
|
253
|
+
* @param {Function} fn
|
254
|
+
* @return {Emitter}
|
255
|
+
* @api public
|
256
|
+
*/
|
257
|
+
|
258
|
+
Emitter.prototype.once = function(event, fn){
|
259
|
+
var self = this;
|
260
|
+
this._callbacks = this._callbacks || {};
|
261
|
+
|
262
|
+
function on() {
|
263
|
+
self.off(event, on);
|
264
|
+
fn.apply(this, arguments);
|
265
|
+
}
|
266
|
+
|
267
|
+
fn._off = on;
|
268
|
+
this.on(event, on);
|
269
|
+
return this;
|
270
|
+
};
|
271
|
+
|
272
|
+
/**
|
273
|
+
* Remove the given callback for `event` or all
|
274
|
+
* registered callbacks.
|
275
|
+
*
|
276
|
+
* @param {String} event
|
277
|
+
* @param {Function} fn
|
278
|
+
* @return {Emitter}
|
279
|
+
* @api public
|
280
|
+
*/
|
281
|
+
|
282
|
+
Emitter.prototype.off =
|
283
|
+
Emitter.prototype.removeListener =
|
284
|
+
Emitter.prototype.removeAllListeners = function(event, fn){
|
285
|
+
this._callbacks = this._callbacks || {};
|
286
|
+
var callbacks = this._callbacks[event];
|
287
|
+
if (!callbacks) return this;
|
288
|
+
|
289
|
+
// remove all handlers
|
290
|
+
if (1 == arguments.length) {
|
291
|
+
delete this._callbacks[event];
|
292
|
+
return this;
|
293
|
+
}
|
294
|
+
|
295
|
+
// remove specific handler
|
296
|
+
var i = callbacks.indexOf(fn._off || fn);
|
297
|
+
if (~i) callbacks.splice(i, 1);
|
298
|
+
return this;
|
299
|
+
};
|
300
|
+
|
301
|
+
/**
|
302
|
+
* Emit `event` with the given args.
|
303
|
+
*
|
304
|
+
* @param {String} event
|
305
|
+
* @param {Mixed} ...
|
306
|
+
* @return {Emitter}
|
307
|
+
*/
|
308
|
+
|
309
|
+
Emitter.prototype.emit = function(event){
|
310
|
+
this._callbacks = this._callbacks || {};
|
311
|
+
var args = [].slice.call(arguments, 1)
|
312
|
+
, callbacks = this._callbacks[event];
|
313
|
+
|
314
|
+
if (callbacks) {
|
315
|
+
callbacks = callbacks.slice(0);
|
316
|
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
317
|
+
callbacks[i].apply(this, args);
|
318
|
+
}
|
319
|
+
}
|
320
|
+
|
321
|
+
return this;
|
322
|
+
};
|
323
|
+
|
324
|
+
/**
|
325
|
+
* Return array of callbacks for `event`.
|
326
|
+
*
|
327
|
+
* @param {String} event
|
328
|
+
* @return {Array}
|
329
|
+
* @api public
|
330
|
+
*/
|
331
|
+
|
332
|
+
Emitter.prototype.listeners = function(event){
|
333
|
+
this._callbacks = this._callbacks || {};
|
334
|
+
return this._callbacks[event] || [];
|
335
|
+
};
|
336
|
+
|
337
|
+
/**
|
338
|
+
* Check if this emitter has `event` handlers.
|
339
|
+
*
|
340
|
+
* @param {String} event
|
341
|
+
* @return {Boolean}
|
342
|
+
* @api public
|
343
|
+
*/
|
344
|
+
|
345
|
+
Emitter.prototype.hasListeners = function(event){
|
346
|
+
return !! this.listeners(event).length;
|
347
|
+
};
|
348
|
+
|
349
|
+
});
|
350
|
+
require.register("dropzone/index.js", function(exports, require, module){
|
351
|
+
|
352
|
+
|
353
|
+
/**
|
354
|
+
* Exposing dropzone
|
355
|
+
*/
|
356
|
+
module.exports = require("./lib/dropzone.js");
|
357
|
+
|
358
|
+
});
|
359
|
+
require.register("dropzone/lib/dropzone.js", function(exports, require, module){
|
360
|
+
/*
|
361
|
+
#
|
362
|
+
# More info at [www.dropzonejs.com](http://www.dropzonejs.com)
|
363
|
+
#
|
364
|
+
# Copyright (c) 2012, Matias Meno
|
365
|
+
#
|
366
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
367
|
+
# of this software and associated documentation files (the "Software"), to deal
|
368
|
+
# in the Software without restriction, including without limitation the rights
|
369
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
370
|
+
# copies of the Software, and to permit persons to whom the Software is
|
371
|
+
# furnished to do so, subject to the following conditions:
|
372
|
+
#
|
373
|
+
# The above copyright notice and this permission notice shall be included in
|
374
|
+
# all copies or substantial portions of the Software.
|
375
|
+
#
|
376
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
377
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
378
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
379
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
380
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
381
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
382
|
+
# THE SOFTWARE.
|
383
|
+
#
|
384
|
+
*/
|
385
|
+
|
386
|
+
|
387
|
+
(function() {
|
388
|
+
var Dropzone, Em, camelize, contentLoaded, noop, without,
|
389
|
+
__hasProp = {}.hasOwnProperty,
|
390
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
391
|
+
__slice = [].slice;
|
392
|
+
|
393
|
+
Em = typeof Emitter !== "undefined" && Emitter !== null ? Emitter : require("emitter");
|
394
|
+
|
395
|
+
noop = function() {};
|
396
|
+
|
397
|
+
Dropzone = (function(_super) {
|
398
|
+
var extend;
|
399
|
+
|
400
|
+
__extends(Dropzone, _super);
|
401
|
+
|
402
|
+
/*
|
403
|
+
This is a list of all available events you can register on a dropzone object.
|
404
|
+
|
405
|
+
You can register an event handler like this:
|
406
|
+
|
407
|
+
dropzone.on("dragEnter", function() { });
|
408
|
+
*/
|
409
|
+
|
410
|
+
|
411
|
+
Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "selectedfiles", "addedfile", "removedfile", "thumbnail", "error", "processing", "processingmultiple", "uploadprogress", "totaluploadprogress", "sending", "sendingmultiple", "success", "successmultiple", "canceled", "canceledmultiple", "complete", "completemultiple", "reset"];
|
412
|
+
|
413
|
+
Dropzone.prototype.defaultOptions = {
|
414
|
+
url: null,
|
415
|
+
method: "post",
|
416
|
+
withCredentials: false,
|
417
|
+
parallelUploads: 2,
|
418
|
+
uploadMultiple: false,
|
419
|
+
maxFilesize: 256,
|
420
|
+
paramName: "file",
|
421
|
+
createImageThumbnails: true,
|
422
|
+
maxThumbnailFilesize: 10,
|
423
|
+
thumbnailWidth: 100,
|
424
|
+
thumbnailHeight: 100,
|
425
|
+
params: {},
|
426
|
+
clickable: true,
|
427
|
+
ignoreHiddenFiles: true,
|
428
|
+
acceptedFiles: null,
|
429
|
+
acceptedMimeTypes: null,
|
430
|
+
autoProcessQueue: true,
|
431
|
+
addRemoveLinks: false,
|
432
|
+
previewsContainer: null,
|
433
|
+
dictDefaultMessage: "Drop files here to upload",
|
434
|
+
dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
|
435
|
+
dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
|
436
|
+
dictFileTooBig: "File is too big ({{filesize}}MB). Max filesize: {{maxFilesize}}MB.",
|
437
|
+
dictInvalidFileType: "You can't upload files of this type.",
|
438
|
+
dictResponseError: "Server responded with {{statusCode}} code.",
|
439
|
+
dictCancelUpload: "Cancel upload",
|
440
|
+
dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
|
441
|
+
dictRemoveFile: "Remove file",
|
442
|
+
accept: function(file, done) {
|
443
|
+
return done();
|
444
|
+
},
|
445
|
+
init: function() {
|
446
|
+
return noop;
|
447
|
+
},
|
448
|
+
forceFallback: false,
|
449
|
+
fallback: function() {
|
450
|
+
var child, messageElement, span, _i, _len, _ref;
|
451
|
+
this.element.className = "" + this.element.className + " dz-browser-not-supported";
|
452
|
+
_ref = this.element.getElementsByTagName("div");
|
453
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
454
|
+
child = _ref[_i];
|
455
|
+
if (/(^| )dz-message($| )/.test(child.className)) {
|
456
|
+
messageElement = child;
|
457
|
+
child.className = "dz-message";
|
458
|
+
continue;
|
459
|
+
}
|
460
|
+
}
|
461
|
+
if (!messageElement) {
|
462
|
+
messageElement = Dropzone.createElement("<div class=\"dz-message\"><span></span></div>");
|
463
|
+
this.element.appendChild(messageElement);
|
464
|
+
}
|
465
|
+
span = messageElement.getElementsByTagName("span")[0];
|
466
|
+
if (span) {
|
467
|
+
span.textContent = this.options.dictFallbackMessage;
|
468
|
+
}
|
469
|
+
return this.element.appendChild(this.getFallbackForm());
|
470
|
+
},
|
471
|
+
resize: function(file) {
|
472
|
+
var info, srcRatio, trgRatio;
|
473
|
+
info = {
|
474
|
+
srcX: 0,
|
475
|
+
srcY: 0,
|
476
|
+
srcWidth: file.width,
|
477
|
+
srcHeight: file.height
|
478
|
+
};
|
479
|
+
srcRatio = file.width / file.height;
|
480
|
+
trgRatio = this.options.thumbnailWidth / this.options.thumbnailHeight;
|
481
|
+
if (file.height < this.options.thumbnailHeight || file.width < this.options.thumbnailWidth) {
|
482
|
+
info.trgHeight = info.srcHeight;
|
483
|
+
info.trgWidth = info.srcWidth;
|
484
|
+
} else {
|
485
|
+
if (srcRatio > trgRatio) {
|
486
|
+
info.srcHeight = file.height;
|
487
|
+
info.srcWidth = info.srcHeight * trgRatio;
|
488
|
+
} else {
|
489
|
+
info.srcWidth = file.width;
|
490
|
+
info.srcHeight = info.srcWidth / trgRatio;
|
491
|
+
}
|
492
|
+
}
|
493
|
+
info.srcX = (file.width - info.srcWidth) / 2;
|
494
|
+
info.srcY = (file.height - info.srcHeight) / 2;
|
495
|
+
return info;
|
496
|
+
},
|
497
|
+
/*
|
498
|
+
Those functions register themselves to the events on init and handle all
|
499
|
+
the user interface specific stuff. Overwriting them won't break the upload
|
500
|
+
but can break the way it's displayed.
|
501
|
+
You can overwrite them if you don't like the default behavior. If you just
|
502
|
+
want to add an additional event handler, register it on the dropzone object
|
503
|
+
and don't overwrite those options.
|
504
|
+
*/
|
505
|
+
|
506
|
+
drop: function(e) {
|
507
|
+
return this.element.classList.remove("dz-drag-hover");
|
508
|
+
},
|
509
|
+
dragstart: noop,
|
510
|
+
dragend: function(e) {
|
511
|
+
return this.element.classList.remove("dz-drag-hover");
|
512
|
+
},
|
513
|
+
dragenter: function(e) {
|
514
|
+
return this.element.classList.add("dz-drag-hover");
|
515
|
+
},
|
516
|
+
dragover: function(e) {
|
517
|
+
return this.element.classList.add("dz-drag-hover");
|
518
|
+
},
|
519
|
+
dragleave: function(e) {
|
520
|
+
return this.element.classList.remove("dz-drag-hover");
|
521
|
+
},
|
522
|
+
selectedfiles: function(files) {
|
523
|
+
if (this.element === this.previewsContainer) {
|
524
|
+
return this.element.classList.add("dz-started");
|
525
|
+
}
|
526
|
+
},
|
527
|
+
reset: function() {
|
528
|
+
return this.element.classList.remove("dz-started");
|
529
|
+
},
|
530
|
+
addedfile: function(file) {
|
531
|
+
var _this = this;
|
532
|
+
file.previewElement = Dropzone.createElement(this.options.previewTemplate);
|
533
|
+
file.previewTemplate = file.previewElement;
|
534
|
+
this.previewsContainer.appendChild(file.previewElement);
|
535
|
+
file.previewElement.querySelector("[data-dz-name]").textContent = file.name;
|
536
|
+
file.previewElement.querySelector("[data-dz-size]").innerHTML = this.filesize(file.size);
|
537
|
+
if (this.options.addRemoveLinks) {
|
538
|
+
file._removeLink = Dropzone.createElement("<a class=\"dz-remove\" href=\"javascript:undefined;\">" + this.options.dictRemoveFile + "</a>");
|
539
|
+
file._removeLink.addEventListener("click", function(e) {
|
540
|
+
e.preventDefault();
|
541
|
+
e.stopPropagation();
|
542
|
+
if (file.status === Dropzone.UPLOADING) {
|
543
|
+
if (window.confirm(_this.options.dictCancelUploadConfirmation)) {
|
544
|
+
return _this.removeFile(file);
|
545
|
+
}
|
546
|
+
} else {
|
547
|
+
return _this.removeFile(file);
|
548
|
+
}
|
549
|
+
});
|
550
|
+
return file.previewElement.appendChild(file._removeLink);
|
551
|
+
}
|
552
|
+
},
|
553
|
+
removedfile: function(file) {
|
554
|
+
var _ref;
|
555
|
+
return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
|
556
|
+
},
|
557
|
+
thumbnail: function(file, dataUrl) {
|
558
|
+
var thumbnailElement;
|
559
|
+
file.previewElement.classList.remove("dz-file-preview");
|
560
|
+
file.previewElement.classList.add("dz-image-preview");
|
561
|
+
thumbnailElement = file.previewElement.querySelector("[data-dz-thumbnail]");
|
562
|
+
thumbnailElement.alt = file.name;
|
563
|
+
return thumbnailElement.src = dataUrl;
|
564
|
+
},
|
565
|
+
error: function(file, message) {
|
566
|
+
file.previewElement.classList.add("dz-error");
|
567
|
+
return file.previewElement.querySelector("[data-dz-errormessage]").textContent = message;
|
568
|
+
},
|
569
|
+
processing: function(file) {
|
570
|
+
file.previewElement.classList.add("dz-processing");
|
571
|
+
if (file._removeLink) {
|
572
|
+
return file._removeLink.textContent = this.options.dictCancelUpload;
|
573
|
+
}
|
574
|
+
},
|
575
|
+
processingmultiple: noop,
|
576
|
+
uploadprogress: function(file, progress, bytesSent) {
|
577
|
+
return file.previewElement.querySelector("[data-dz-uploadprogress]").style.width = "" + progress + "%";
|
578
|
+
},
|
579
|
+
totaluploadprogress: noop,
|
580
|
+
sending: noop,
|
581
|
+
sendingmultiple: noop,
|
582
|
+
success: function(file) {
|
583
|
+
return file.previewElement.classList.add("dz-success");
|
584
|
+
},
|
585
|
+
successmultiple: noop,
|
586
|
+
canceled: function(file) {
|
587
|
+
return this.emit("error", file, "Upload canceled.");
|
588
|
+
},
|
589
|
+
canceledmultiple: noop,
|
590
|
+
complete: function(file) {
|
591
|
+
if (file._removeLink) {
|
592
|
+
return file._removeLink.textContent = this.options.dictRemoveFile;
|
593
|
+
}
|
594
|
+
},
|
595
|
+
completemultiple: noop,
|
596
|
+
previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n <div class=\"dz-details\">\n <div class=\"dz-filename\"><span data-dz-name></span></div>\n <div class=\"dz-size\" data-dz-size></div>\n <img data-dz-thumbnail />\n </div>\n <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress></span></div>\n <div class=\"dz-success-mark\"><span>✔</span></div>\n <div class=\"dz-error-mark\"><span>✘</span></div>\n <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>"
|
597
|
+
};
|
598
|
+
|
599
|
+
extend = function() {
|
600
|
+
var key, object, objects, target, val, _i, _len;
|
601
|
+
target = arguments[0], objects = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
602
|
+
for (_i = 0, _len = objects.length; _i < _len; _i++) {
|
603
|
+
object = objects[_i];
|
604
|
+
for (key in object) {
|
605
|
+
val = object[key];
|
606
|
+
target[key] = val;
|
607
|
+
}
|
608
|
+
}
|
609
|
+
return target;
|
610
|
+
};
|
611
|
+
|
612
|
+
function Dropzone(element, options) {
|
613
|
+
var elementOptions, fallback, _ref;
|
614
|
+
this.element = element;
|
615
|
+
this.version = Dropzone.version;
|
616
|
+
this.defaultOptions.previewTemplate = this.defaultOptions.previewTemplate.replace(/\n*/g, "");
|
617
|
+
this.clickableElements = [];
|
618
|
+
this.listeners = [];
|
619
|
+
this.files = [];
|
620
|
+
if (typeof this.element === "string") {
|
621
|
+
this.element = document.querySelector(this.element);
|
622
|
+
}
|
623
|
+
if (!(this.element && (this.element.nodeType != null))) {
|
624
|
+
throw new Error("Invalid dropzone element.");
|
625
|
+
}
|
626
|
+
if (this.element.dropzone) {
|
627
|
+
throw new Error("Dropzone already attached.");
|
628
|
+
}
|
629
|
+
Dropzone.instances.push(this);
|
630
|
+
element.dropzone = this;
|
631
|
+
elementOptions = (_ref = Dropzone.optionsForElement(this.element)) != null ? _ref : {};
|
632
|
+
this.options = extend({}, this.defaultOptions, elementOptions, options != null ? options : {});
|
633
|
+
if (this.options.url == null) {
|
634
|
+
this.options.url = this.element.action;
|
635
|
+
}
|
636
|
+
if (!this.options.url) {
|
637
|
+
throw new Error("No URL provided.");
|
638
|
+
}
|
639
|
+
if (this.options.acceptedFiles && this.options.acceptedMimeTypes) {
|
640
|
+
throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");
|
641
|
+
}
|
642
|
+
if (this.options.acceptedMimeTypes) {
|
643
|
+
this.options.acceptedFiles = this.options.acceptedMimeTypes;
|
644
|
+
delete this.options.acceptedMimeTypes;
|
645
|
+
}
|
646
|
+
this.options.method = this.options.method.toUpperCase();
|
647
|
+
if (this.options.forceFallback || !Dropzone.isBrowserSupported()) {
|
648
|
+
return this.options.fallback.call(this);
|
649
|
+
}
|
650
|
+
if ((fallback = this.getExistingFallback()) && fallback.parentNode) {
|
651
|
+
fallback.parentNode.removeChild(fallback);
|
652
|
+
}
|
653
|
+
if (this.options.previewsContainer) {
|
654
|
+
this.previewsContainer = Dropzone.getElement(this.options.previewsContainer, "previewsContainer");
|
655
|
+
} else {
|
656
|
+
this.previewsContainer = this.element;
|
657
|
+
}
|
658
|
+
if (this.options.clickable) {
|
659
|
+
if (this.options.clickable === true) {
|
660
|
+
this.clickableElements = [this.element];
|
661
|
+
} else {
|
662
|
+
this.clickableElements = Dropzone.getElements(this.options.clickable, "clickable");
|
663
|
+
}
|
664
|
+
}
|
665
|
+
this.init();
|
666
|
+
}
|
667
|
+
|
668
|
+
Dropzone.prototype.getAcceptedFiles = function() {
|
669
|
+
var file, _i, _len, _ref, _results;
|
670
|
+
_ref = this.files;
|
671
|
+
_results = [];
|
672
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
673
|
+
file = _ref[_i];
|
674
|
+
if (file.accepted) {
|
675
|
+
_results.push(file);
|
676
|
+
}
|
677
|
+
}
|
678
|
+
return _results;
|
679
|
+
};
|
680
|
+
|
681
|
+
Dropzone.prototype.getRejectedFiles = function() {
|
682
|
+
var file, _i, _len, _ref, _results;
|
683
|
+
_ref = this.files;
|
684
|
+
_results = [];
|
685
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
686
|
+
file = _ref[_i];
|
687
|
+
if (!file.accepted) {
|
688
|
+
_results.push(file);
|
689
|
+
}
|
690
|
+
}
|
691
|
+
return _results;
|
692
|
+
};
|
693
|
+
|
694
|
+
Dropzone.prototype.getQueuedFiles = function() {
|
695
|
+
var file, _i, _len, _ref, _results;
|
696
|
+
_ref = this.files;
|
697
|
+
_results = [];
|
698
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
699
|
+
file = _ref[_i];
|
700
|
+
if (file.status === Dropzone.QUEUED) {
|
701
|
+
_results.push(file);
|
702
|
+
}
|
703
|
+
}
|
704
|
+
return _results;
|
705
|
+
};
|
706
|
+
|
707
|
+
Dropzone.prototype.getUploadingFiles = function() {
|
708
|
+
var file, _i, _len, _ref, _results;
|
709
|
+
_ref = this.files;
|
710
|
+
_results = [];
|
711
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
712
|
+
file = _ref[_i];
|
713
|
+
if (file.status === Dropzone.UPLOADING) {
|
714
|
+
_results.push(file);
|
715
|
+
}
|
716
|
+
}
|
717
|
+
return _results;
|
718
|
+
};
|
719
|
+
|
720
|
+
Dropzone.prototype.init = function() {
|
721
|
+
var eventName, noPropagation, setupHiddenFileInput, _i, _len, _ref, _ref1,
|
722
|
+
_this = this;
|
723
|
+
if (this.element.tagName === "form") {
|
724
|
+
this.element.setAttribute("enctype", "multipart/form-data");
|
725
|
+
}
|
726
|
+
if (this.element.classList.contains("dropzone") && !this.element.querySelector(".dz-message")) {
|
727
|
+
this.element.appendChild(Dropzone.createElement("<div class=\"dz-default dz-message\"><span>" + this.options.dictDefaultMessage + "</span></div>"));
|
728
|
+
}
|
729
|
+
if (this.clickableElements.length) {
|
730
|
+
setupHiddenFileInput = function() {
|
731
|
+
if (_this.hiddenFileInput) {
|
732
|
+
document.body.removeChild(_this.hiddenFileInput);
|
733
|
+
}
|
734
|
+
_this.hiddenFileInput = document.createElement("input");
|
735
|
+
_this.hiddenFileInput.setAttribute("type", "file");
|
736
|
+
if (_this.options.uploadMultiple) {
|
737
|
+
_this.hiddenFileInput.setAttribute("multiple", "multiple");
|
738
|
+
}
|
739
|
+
if (_this.options.acceptedFiles != null) {
|
740
|
+
_this.hiddenFileInput.setAttribute("accept", _this.options.acceptedFiles);
|
741
|
+
}
|
742
|
+
_this.hiddenFileInput.style.visibility = "hidden";
|
743
|
+
_this.hiddenFileInput.style.position = "absolute";
|
744
|
+
_this.hiddenFileInput.style.top = "0";
|
745
|
+
_this.hiddenFileInput.style.left = "0";
|
746
|
+
_this.hiddenFileInput.style.height = "0";
|
747
|
+
_this.hiddenFileInput.style.width = "0";
|
748
|
+
document.body.appendChild(_this.hiddenFileInput);
|
749
|
+
return _this.hiddenFileInput.addEventListener("change", function() {
|
750
|
+
var files;
|
751
|
+
files = _this.hiddenFileInput.files;
|
752
|
+
if (files.length) {
|
753
|
+
_this.emit("selectedfiles", files);
|
754
|
+
_this.handleFiles(files);
|
755
|
+
}
|
756
|
+
return setupHiddenFileInput();
|
757
|
+
});
|
758
|
+
};
|
759
|
+
setupHiddenFileInput();
|
760
|
+
}
|
761
|
+
this.URL = (_ref = window.URL) != null ? _ref : window.webkitURL;
|
762
|
+
_ref1 = this.events;
|
763
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
764
|
+
eventName = _ref1[_i];
|
765
|
+
this.on(eventName, this.options[eventName]);
|
766
|
+
}
|
767
|
+
this.on("uploadprogress", function() {
|
768
|
+
return _this.updateTotalUploadProgress();
|
769
|
+
});
|
770
|
+
this.on("removedfile", function() {
|
771
|
+
return _this.updateTotalUploadProgress();
|
772
|
+
});
|
773
|
+
this.on("canceled", function(file) {
|
774
|
+
return _this.emit("complete", file);
|
775
|
+
});
|
776
|
+
noPropagation = function(e) {
|
777
|
+
e.stopPropagation();
|
778
|
+
if (e.preventDefault) {
|
779
|
+
return e.preventDefault();
|
780
|
+
} else {
|
781
|
+
return e.returnValue = false;
|
782
|
+
}
|
783
|
+
};
|
784
|
+
this.listeners = [
|
785
|
+
{
|
786
|
+
element: this.element,
|
787
|
+
events: {
|
788
|
+
"dragstart": function(e) {
|
789
|
+
return _this.emit("dragstart", e);
|
790
|
+
},
|
791
|
+
"dragenter": function(e) {
|
792
|
+
noPropagation(e);
|
793
|
+
return _this.emit("dragenter", e);
|
794
|
+
},
|
795
|
+
"dragover": function(e) {
|
796
|
+
noPropagation(e);
|
797
|
+
return _this.emit("dragover", e);
|
798
|
+
},
|
799
|
+
"dragleave": function(e) {
|
800
|
+
return _this.emit("dragleave", e);
|
801
|
+
},
|
802
|
+
"drop": function(e) {
|
803
|
+
noPropagation(e);
|
804
|
+
_this.drop(e);
|
805
|
+
return _this.emit("drop", e);
|
806
|
+
},
|
807
|
+
"dragend": function(e) {
|
808
|
+
return _this.emit("dragend", e);
|
809
|
+
}
|
810
|
+
}
|
811
|
+
}
|
812
|
+
];
|
813
|
+
this.clickableElements.forEach(function(clickableElement) {
|
814
|
+
return _this.listeners.push({
|
815
|
+
element: clickableElement,
|
816
|
+
events: {
|
817
|
+
"click": function(evt) {
|
818
|
+
if ((clickableElement !== _this.element) || (evt.target === _this.element || Dropzone.elementInside(evt.target, _this.element.querySelector(".dz-message")))) {
|
819
|
+
return _this.hiddenFileInput.click();
|
820
|
+
}
|
821
|
+
}
|
822
|
+
}
|
823
|
+
});
|
824
|
+
});
|
825
|
+
this.enable();
|
826
|
+
return this.options.init.call(this);
|
827
|
+
};
|
828
|
+
|
829
|
+
Dropzone.prototype.destroy = function() {
|
830
|
+
var _ref;
|
831
|
+
this.disable();
|
832
|
+
this.removeAllFiles(true);
|
833
|
+
if ((_ref = this.hiddenFileInput) != null ? _ref.parentNode : void 0) {
|
834
|
+
this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput);
|
835
|
+
this.hiddenFileInput = null;
|
836
|
+
}
|
837
|
+
return delete this.element.dropzone;
|
838
|
+
};
|
839
|
+
|
840
|
+
Dropzone.prototype.updateTotalUploadProgress = function() {
|
841
|
+
var acceptedFiles, file, totalBytes, totalBytesSent, totalUploadProgress, _i, _len, _ref;
|
842
|
+
totalBytesSent = 0;
|
843
|
+
totalBytes = 0;
|
844
|
+
acceptedFiles = this.getAcceptedFiles();
|
845
|
+
if (acceptedFiles.length) {
|
846
|
+
_ref = this.getAcceptedFiles();
|
847
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
848
|
+
file = _ref[_i];
|
849
|
+
totalBytesSent += file.upload.bytesSent;
|
850
|
+
totalBytes += file.upload.total;
|
851
|
+
}
|
852
|
+
totalUploadProgress = 100 * totalBytesSent / totalBytes;
|
853
|
+
} else {
|
854
|
+
totalUploadProgress = 100;
|
855
|
+
}
|
856
|
+
return this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent);
|
857
|
+
};
|
858
|
+
|
859
|
+
Dropzone.prototype.getFallbackForm = function() {
|
860
|
+
var existingFallback, fields, fieldsString, form;
|
861
|
+
if (existingFallback = this.getExistingFallback()) {
|
862
|
+
return existingFallback;
|
863
|
+
}
|
864
|
+
fieldsString = "<div class=\"dz-fallback\">";
|
865
|
+
if (this.options.dictFallbackText) {
|
866
|
+
fieldsString += "<p>" + this.options.dictFallbackText + "</p>";
|
867
|
+
}
|
868
|
+
fieldsString += "<input type=\"file\" name=\"" + this.options.paramName + (this.options.uploadMultiple ? "[]" : "") + "\" " + (this.options.uploadMultiple ? 'multiple="multiple"' : void 0) + " /><button type=\"submit\">Upload!</button></div>";
|
869
|
+
fields = Dropzone.createElement(fieldsString);
|
870
|
+
if (this.element.tagName !== "FORM") {
|
871
|
+
form = Dropzone.createElement("<form action=\"" + this.options.url + "\" enctype=\"multipart/form-data\" method=\"" + this.options.method + "\"></form>");
|
872
|
+
form.appendChild(fields);
|
873
|
+
} else {
|
874
|
+
this.element.setAttribute("enctype", "multipart/form-data");
|
875
|
+
this.element.setAttribute("method", this.options.method);
|
876
|
+
}
|
877
|
+
return form != null ? form : fields;
|
878
|
+
};
|
879
|
+
|
880
|
+
Dropzone.prototype.getExistingFallback = function() {
|
881
|
+
var fallback, getFallback, tagName, _i, _len, _ref;
|
882
|
+
getFallback = function(elements) {
|
883
|
+
var el, _i, _len;
|
884
|
+
for (_i = 0, _len = elements.length; _i < _len; _i++) {
|
885
|
+
el = elements[_i];
|
886
|
+
if (/(^| )fallback($| )/.test(el.className)) {
|
887
|
+
return el;
|
888
|
+
}
|
889
|
+
}
|
890
|
+
};
|
891
|
+
_ref = ["div", "form"];
|
892
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
893
|
+
tagName = _ref[_i];
|
894
|
+
if (fallback = getFallback(this.element.getElementsByTagName(tagName))) {
|
895
|
+
return fallback;
|
896
|
+
}
|
897
|
+
}
|
898
|
+
};
|
899
|
+
|
900
|
+
Dropzone.prototype.setupEventListeners = function() {
|
901
|
+
var elementListeners, event, listener, _i, _len, _ref, _results;
|
902
|
+
_ref = this.listeners;
|
903
|
+
_results = [];
|
904
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
905
|
+
elementListeners = _ref[_i];
|
906
|
+
_results.push((function() {
|
907
|
+
var _ref1, _results1;
|
908
|
+
_ref1 = elementListeners.events;
|
909
|
+
_results1 = [];
|
910
|
+
for (event in _ref1) {
|
911
|
+
listener = _ref1[event];
|
912
|
+
_results1.push(elementListeners.element.addEventListener(event, listener, false));
|
913
|
+
}
|
914
|
+
return _results1;
|
915
|
+
})());
|
916
|
+
}
|
917
|
+
return _results;
|
918
|
+
};
|
919
|
+
|
920
|
+
Dropzone.prototype.removeEventListeners = function() {
|
921
|
+
var elementListeners, event, listener, _i, _len, _ref, _results;
|
922
|
+
_ref = this.listeners;
|
923
|
+
_results = [];
|
924
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
925
|
+
elementListeners = _ref[_i];
|
926
|
+
_results.push((function() {
|
927
|
+
var _ref1, _results1;
|
928
|
+
_ref1 = elementListeners.events;
|
929
|
+
_results1 = [];
|
930
|
+
for (event in _ref1) {
|
931
|
+
listener = _ref1[event];
|
932
|
+
_results1.push(elementListeners.element.removeEventListener(event, listener, false));
|
933
|
+
}
|
934
|
+
return _results1;
|
935
|
+
})());
|
936
|
+
}
|
937
|
+
return _results;
|
938
|
+
};
|
939
|
+
|
940
|
+
Dropzone.prototype.disable = function() {
|
941
|
+
var file, _i, _len, _ref, _results;
|
942
|
+
this.clickableElements.forEach(function(element) {
|
943
|
+
return element.classList.remove("dz-clickable");
|
944
|
+
});
|
945
|
+
this.removeEventListeners();
|
946
|
+
_ref = this.files;
|
947
|
+
_results = [];
|
948
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
949
|
+
file = _ref[_i];
|
950
|
+
_results.push(this.cancelUpload(file));
|
951
|
+
}
|
952
|
+
return _results;
|
953
|
+
};
|
954
|
+
|
955
|
+
Dropzone.prototype.enable = function() {
|
956
|
+
this.clickableElements.forEach(function(element) {
|
957
|
+
return element.classList.add("dz-clickable");
|
958
|
+
});
|
959
|
+
return this.setupEventListeners();
|
960
|
+
};
|
961
|
+
|
962
|
+
Dropzone.prototype.filesize = function(size) {
|
963
|
+
var string;
|
964
|
+
if (size >= 100000000000) {
|
965
|
+
size = size / 100000000000;
|
966
|
+
string = "TB";
|
967
|
+
} else if (size >= 100000000) {
|
968
|
+
size = size / 100000000;
|
969
|
+
string = "GB";
|
970
|
+
} else if (size >= 100000) {
|
971
|
+
size = size / 100000;
|
972
|
+
string = "MB";
|
973
|
+
} else if (size >= 100) {
|
974
|
+
size = size / 100;
|
975
|
+
string = "KB";
|
976
|
+
} else {
|
977
|
+
size = size * 10;
|
978
|
+
string = "b";
|
979
|
+
}
|
980
|
+
return "<strong>" + (Math.round(size) / 10) + "</strong> " + string;
|
981
|
+
};
|
982
|
+
|
983
|
+
Dropzone.prototype.drop = function(e) {
|
984
|
+
var files, items;
|
985
|
+
if (!e.dataTransfer) {
|
986
|
+
return;
|
987
|
+
}
|
988
|
+
files = e.dataTransfer.files;
|
989
|
+
this.emit("selectedfiles", files);
|
990
|
+
if (files.length) {
|
991
|
+
items = e.dataTransfer.items;
|
992
|
+
if (items && items.length && ((items[0].webkitGetAsEntry != null) || (items[0].getAsEntry != null))) {
|
993
|
+
this.handleItems(items);
|
994
|
+
} else {
|
995
|
+
this.handleFiles(files);
|
996
|
+
}
|
997
|
+
}
|
998
|
+
};
|
999
|
+
|
1000
|
+
Dropzone.prototype.handleFiles = function(files) {
|
1001
|
+
var file, _i, _len, _results;
|
1002
|
+
_results = [];
|
1003
|
+
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
1004
|
+
file = files[_i];
|
1005
|
+
_results.push(this.addFile(file));
|
1006
|
+
}
|
1007
|
+
return _results;
|
1008
|
+
};
|
1009
|
+
|
1010
|
+
Dropzone.prototype.handleItems = function(items) {
|
1011
|
+
var entry, item, _i, _len;
|
1012
|
+
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
1013
|
+
item = items[_i];
|
1014
|
+
if (item.webkitGetAsEntry != null) {
|
1015
|
+
entry = item.webkitGetAsEntry();
|
1016
|
+
if (entry.isFile) {
|
1017
|
+
this.addFile(item.getAsFile());
|
1018
|
+
} else if (entry.isDirectory) {
|
1019
|
+
this.addDirectory(entry, entry.name);
|
1020
|
+
}
|
1021
|
+
} else {
|
1022
|
+
this.addFile(item.getAsFile());
|
1023
|
+
}
|
1024
|
+
}
|
1025
|
+
};
|
1026
|
+
|
1027
|
+
Dropzone.prototype.accept = function(file, done) {
|
1028
|
+
if (file.size > this.options.maxFilesize * 1024 * 1024) {
|
1029
|
+
return done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize));
|
1030
|
+
} else if (!Dropzone.isValidFile(file, this.options.acceptedFiles)) {
|
1031
|
+
return done(this.options.dictInvalidFileType);
|
1032
|
+
} else {
|
1033
|
+
return this.options.accept.call(this, file, done);
|
1034
|
+
}
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
Dropzone.prototype.addFile = function(file) {
|
1038
|
+
var _this = this;
|
1039
|
+
file.upload = {
|
1040
|
+
progress: 0,
|
1041
|
+
total: file.size,
|
1042
|
+
bytesSent: 0
|
1043
|
+
};
|
1044
|
+
this.files.push(file);
|
1045
|
+
file.status = Dropzone.ADDED;
|
1046
|
+
this.emit("addedfile", file);
|
1047
|
+
if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) {
|
1048
|
+
this.createThumbnail(file);
|
1049
|
+
}
|
1050
|
+
return this.accept(file, function(error) {
|
1051
|
+
if (error) {
|
1052
|
+
file.accepted = false;
|
1053
|
+
return _this._errorProcessing([file], error);
|
1054
|
+
} else {
|
1055
|
+
file.accepted = true;
|
1056
|
+
return _this.enqueueFile(file);
|
1057
|
+
}
|
1058
|
+
});
|
1059
|
+
};
|
1060
|
+
|
1061
|
+
Dropzone.prototype.enqueueFiles = function(files) {
|
1062
|
+
var file, _i, _len;
|
1063
|
+
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
1064
|
+
file = files[_i];
|
1065
|
+
this.enqueueFile(file);
|
1066
|
+
}
|
1067
|
+
return null;
|
1068
|
+
};
|
1069
|
+
|
1070
|
+
Dropzone.prototype.enqueueFile = function(file) {
|
1071
|
+
var _this = this;
|
1072
|
+
if (file.status === Dropzone.ADDED) {
|
1073
|
+
file.status = Dropzone.QUEUED;
|
1074
|
+
if (this.options.autoProcessQueue) {
|
1075
|
+
return setTimeout((function() {
|
1076
|
+
return _this.processQueue();
|
1077
|
+
}), 1);
|
1078
|
+
}
|
1079
|
+
} else {
|
1080
|
+
throw new Error("This file can't be queued because it has already been processed or was rejected.");
|
1081
|
+
}
|
1082
|
+
};
|
1083
|
+
|
1084
|
+
Dropzone.prototype.addDirectory = function(entry, path) {
|
1085
|
+
var dirReader, entriesReader,
|
1086
|
+
_this = this;
|
1087
|
+
dirReader = entry.createReader();
|
1088
|
+
entriesReader = function(entries) {
|
1089
|
+
var _i, _len;
|
1090
|
+
for (_i = 0, _len = entries.length; _i < _len; _i++) {
|
1091
|
+
entry = entries[_i];
|
1092
|
+
if (entry.isFile) {
|
1093
|
+
entry.file(function(file) {
|
1094
|
+
if (_this.options.ignoreHiddenFiles && file.name.substring(0, 1) === '.') {
|
1095
|
+
return;
|
1096
|
+
}
|
1097
|
+
file.fullPath = "" + path + "/" + file.name;
|
1098
|
+
return _this.addFile(file);
|
1099
|
+
});
|
1100
|
+
} else if (entry.isDirectory) {
|
1101
|
+
_this.addDirectory(entry, "" + path + "/" + entry.name);
|
1102
|
+
}
|
1103
|
+
}
|
1104
|
+
};
|
1105
|
+
return dirReader.readEntries(entriesReader, function(error) {
|
1106
|
+
return typeof console !== "undefined" && console !== null ? typeof console.log === "function" ? console.log(error) : void 0 : void 0;
|
1107
|
+
});
|
1108
|
+
};
|
1109
|
+
|
1110
|
+
Dropzone.prototype.removeFile = function(file) {
|
1111
|
+
if (file.status === Dropzone.UPLOADING) {
|
1112
|
+
this.cancelUpload(file);
|
1113
|
+
}
|
1114
|
+
this.files = without(this.files, file);
|
1115
|
+
this.emit("removedfile", file);
|
1116
|
+
if (this.files.length === 0) {
|
1117
|
+
return this.emit("reset");
|
1118
|
+
}
|
1119
|
+
};
|
1120
|
+
|
1121
|
+
Dropzone.prototype.removeAllFiles = function(cancelIfNecessary) {
|
1122
|
+
var file, _i, _len, _ref;
|
1123
|
+
if (cancelIfNecessary == null) {
|
1124
|
+
cancelIfNecessary = false;
|
1125
|
+
}
|
1126
|
+
_ref = this.files.slice();
|
1127
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1128
|
+
file = _ref[_i];
|
1129
|
+
if (file.status !== Dropzone.UPLOADING || cancelIfNecessary) {
|
1130
|
+
this.removeFile(file);
|
1131
|
+
}
|
1132
|
+
}
|
1133
|
+
return null;
|
1134
|
+
};
|
1135
|
+
|
1136
|
+
Dropzone.prototype.createThumbnail = function(file) {
|
1137
|
+
var fileReader,
|
1138
|
+
_this = this;
|
1139
|
+
fileReader = new FileReader;
|
1140
|
+
fileReader.onload = function() {
|
1141
|
+
var img;
|
1142
|
+
img = new Image;
|
1143
|
+
img.onload = function() {
|
1144
|
+
var canvas, ctx, resizeInfo, thumbnail, _ref, _ref1, _ref2, _ref3;
|
1145
|
+
file.width = img.width;
|
1146
|
+
file.height = img.height;
|
1147
|
+
resizeInfo = _this.options.resize.call(_this, file);
|
1148
|
+
if (resizeInfo.trgWidth == null) {
|
1149
|
+
resizeInfo.trgWidth = _this.options.thumbnailWidth;
|
1150
|
+
}
|
1151
|
+
if (resizeInfo.trgHeight == null) {
|
1152
|
+
resizeInfo.trgHeight = _this.options.thumbnailHeight;
|
1153
|
+
}
|
1154
|
+
canvas = document.createElement("canvas");
|
1155
|
+
ctx = canvas.getContext("2d");
|
1156
|
+
canvas.width = resizeInfo.trgWidth;
|
1157
|
+
canvas.height = resizeInfo.trgHeight;
|
1158
|
+
ctx.drawImage(img, (_ref = resizeInfo.srcX) != null ? _ref : 0, (_ref1 = resizeInfo.srcY) != null ? _ref1 : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, (_ref2 = resizeInfo.trgX) != null ? _ref2 : 0, (_ref3 = resizeInfo.trgY) != null ? _ref3 : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
|
1159
|
+
thumbnail = canvas.toDataURL("image/png");
|
1160
|
+
return _this.emit("thumbnail", file, thumbnail);
|
1161
|
+
};
|
1162
|
+
return img.src = fileReader.result;
|
1163
|
+
};
|
1164
|
+
return fileReader.readAsDataURL(file);
|
1165
|
+
};
|
1166
|
+
|
1167
|
+
Dropzone.prototype.processQueue = function() {
|
1168
|
+
var i, parallelUploads, processingLength, queuedFiles;
|
1169
|
+
parallelUploads = this.options.parallelUploads;
|
1170
|
+
processingLength = this.getUploadingFiles().length;
|
1171
|
+
i = processingLength;
|
1172
|
+
queuedFiles = this.getQueuedFiles();
|
1173
|
+
if (!(queuedFiles.length > 0)) {
|
1174
|
+
return;
|
1175
|
+
}
|
1176
|
+
if (this.options.uploadMultiple) {
|
1177
|
+
return this.processFiles(queuedFiles.slice(0, parallelUploads));
|
1178
|
+
} else {
|
1179
|
+
while (i < parallelUploads) {
|
1180
|
+
if (!queuedFiles.length) {
|
1181
|
+
return;
|
1182
|
+
}
|
1183
|
+
this.processFile(queuedFiles.shift());
|
1184
|
+
i++;
|
1185
|
+
}
|
1186
|
+
}
|
1187
|
+
};
|
1188
|
+
|
1189
|
+
Dropzone.prototype.processFile = function(file) {
|
1190
|
+
return this.processFiles([file]);
|
1191
|
+
};
|
1192
|
+
|
1193
|
+
Dropzone.prototype.processFiles = function(files) {
|
1194
|
+
var file, _i, _len;
|
1195
|
+
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
1196
|
+
file = files[_i];
|
1197
|
+
file.processing = true;
|
1198
|
+
file.status = Dropzone.UPLOADING;
|
1199
|
+
this.emit("processing", file);
|
1200
|
+
}
|
1201
|
+
if (this.options.uploadMultiple) {
|
1202
|
+
this.emit("processingmultiple", files);
|
1203
|
+
}
|
1204
|
+
return this.uploadFiles(files);
|
1205
|
+
};
|
1206
|
+
|
1207
|
+
Dropzone.prototype._getFilesWithXhr = function(xhr) {
|
1208
|
+
var file, files;
|
1209
|
+
return files = (function() {
|
1210
|
+
var _i, _len, _ref, _results;
|
1211
|
+
_ref = this.files;
|
1212
|
+
_results = [];
|
1213
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1214
|
+
file = _ref[_i];
|
1215
|
+
if (file.xhr === xhr) {
|
1216
|
+
_results.push(file);
|
1217
|
+
}
|
1218
|
+
}
|
1219
|
+
return _results;
|
1220
|
+
}).call(this);
|
1221
|
+
};
|
1222
|
+
|
1223
|
+
Dropzone.prototype.cancelUpload = function(file) {
|
1224
|
+
var groupedFile, groupedFiles, _i, _j, _len, _len1, _ref;
|
1225
|
+
if (file.status === Dropzone.UPLOADING) {
|
1226
|
+
groupedFiles = this._getFilesWithXhr(file.xhr);
|
1227
|
+
for (_i = 0, _len = groupedFiles.length; _i < _len; _i++) {
|
1228
|
+
groupedFile = groupedFiles[_i];
|
1229
|
+
groupedFile.status = Dropzone.CANCELED;
|
1230
|
+
}
|
1231
|
+
file.xhr.abort();
|
1232
|
+
for (_j = 0, _len1 = groupedFiles.length; _j < _len1; _j++) {
|
1233
|
+
groupedFile = groupedFiles[_j];
|
1234
|
+
this.emit("canceled", groupedFile);
|
1235
|
+
}
|
1236
|
+
if (this.options.uploadMultiple) {
|
1237
|
+
this.emit("canceledmultiple", groupedFiles);
|
1238
|
+
}
|
1239
|
+
} else if ((_ref = file.status) === Dropzone.ADDED || _ref === Dropzone.QUEUED) {
|
1240
|
+
file.status = Dropzone.CANCELED;
|
1241
|
+
this.emit("canceled", file);
|
1242
|
+
if (this.options.uploadMultiple) {
|
1243
|
+
this.emit("canceledmultiple", [file]);
|
1244
|
+
}
|
1245
|
+
}
|
1246
|
+
if (this.options.autoProcessQueue) {
|
1247
|
+
return this.processQueue();
|
1248
|
+
}
|
1249
|
+
};
|
1250
|
+
|
1251
|
+
Dropzone.prototype.uploadFile = function(file) {
|
1252
|
+
return this.uploadFiles([file]);
|
1253
|
+
};
|
1254
|
+
|
1255
|
+
Dropzone.prototype.uploadFiles = function(files) {
|
1256
|
+
var file, formData, handleError, header, headers, input, inputName, inputType, key, name, progressObj, response, updateProgress, value, xhr, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3,
|
1257
|
+
_this = this;
|
1258
|
+
xhr = new XMLHttpRequest();
|
1259
|
+
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
1260
|
+
file = files[_i];
|
1261
|
+
file.xhr = xhr;
|
1262
|
+
}
|
1263
|
+
xhr.open(this.options.method, this.options.url, true);
|
1264
|
+
xhr.withCredentials = !!this.options.withCredentials;
|
1265
|
+
response = null;
|
1266
|
+
handleError = function() {
|
1267
|
+
var _j, _len1, _results;
|
1268
|
+
_results = [];
|
1269
|
+
for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
|
1270
|
+
file = files[_j];
|
1271
|
+
_results.push(_this._errorProcessing(files, response || _this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr));
|
1272
|
+
}
|
1273
|
+
return _results;
|
1274
|
+
};
|
1275
|
+
updateProgress = function(e) {
|
1276
|
+
var allFilesFinished, progress, _j, _k, _l, _len1, _len2, _len3, _results;
|
1277
|
+
if (e != null) {
|
1278
|
+
progress = 100 * e.loaded / e.total;
|
1279
|
+
for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
|
1280
|
+
file = files[_j];
|
1281
|
+
file.upload = {
|
1282
|
+
progress: progress,
|
1283
|
+
total: e.total,
|
1284
|
+
bytesSent: e.loaded
|
1285
|
+
};
|
1286
|
+
}
|
1287
|
+
} else {
|
1288
|
+
allFilesFinished = true;
|
1289
|
+
progress = 100;
|
1290
|
+
for (_k = 0, _len2 = files.length; _k < _len2; _k++) {
|
1291
|
+
file = files[_k];
|
1292
|
+
if (!(file.upload.progress === 100 && file.upload.bytesSent === file.upload.total)) {
|
1293
|
+
allFilesFinished = false;
|
1294
|
+
}
|
1295
|
+
file.upload.progress = progress;
|
1296
|
+
file.upload.bytesSent = file.upload.total;
|
1297
|
+
}
|
1298
|
+
if (allFilesFinished) {
|
1299
|
+
return;
|
1300
|
+
}
|
1301
|
+
}
|
1302
|
+
_results = [];
|
1303
|
+
for (_l = 0, _len3 = files.length; _l < _len3; _l++) {
|
1304
|
+
file = files[_l];
|
1305
|
+
_results.push(_this.emit("uploadprogress", file, progress, file.upload.bytesSent));
|
1306
|
+
}
|
1307
|
+
return _results;
|
1308
|
+
};
|
1309
|
+
xhr.onload = function(e) {
|
1310
|
+
var _ref;
|
1311
|
+
if (files[0].status === Dropzone.CANCELED) {
|
1312
|
+
return;
|
1313
|
+
}
|
1314
|
+
if (xhr.readyState !== 4) {
|
1315
|
+
return;
|
1316
|
+
}
|
1317
|
+
response = xhr.responseText;
|
1318
|
+
if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
|
1319
|
+
try {
|
1320
|
+
response = JSON.parse(response);
|
1321
|
+
} catch (_error) {
|
1322
|
+
e = _error;
|
1323
|
+
response = "Invalid JSON response from server.";
|
1324
|
+
}
|
1325
|
+
}
|
1326
|
+
updateProgress();
|
1327
|
+
if (!((200 <= (_ref = xhr.status) && _ref < 300))) {
|
1328
|
+
return handleError();
|
1329
|
+
} else {
|
1330
|
+
return _this._finished(files, response, e);
|
1331
|
+
}
|
1332
|
+
};
|
1333
|
+
xhr.onerror = function() {
|
1334
|
+
if (files[0].status === Dropzone.CANCELED) {
|
1335
|
+
return;
|
1336
|
+
}
|
1337
|
+
return handleError();
|
1338
|
+
};
|
1339
|
+
progressObj = (_ref = xhr.upload) != null ? _ref : xhr;
|
1340
|
+
progressObj.onprogress = updateProgress;
|
1341
|
+
headers = {
|
1342
|
+
"Accept": "application/json",
|
1343
|
+
"Cache-Control": "no-cache",
|
1344
|
+
"X-Requested-With": "XMLHttpRequest"
|
1345
|
+
};
|
1346
|
+
if (this.options.headers) {
|
1347
|
+
extend(headers, this.options.headers);
|
1348
|
+
}
|
1349
|
+
for (header in headers) {
|
1350
|
+
name = headers[header];
|
1351
|
+
xhr.setRequestHeader(header, name);
|
1352
|
+
}
|
1353
|
+
formData = new FormData();
|
1354
|
+
if (this.options.params) {
|
1355
|
+
_ref1 = this.options.params;
|
1356
|
+
for (key in _ref1) {
|
1357
|
+
value = _ref1[key];
|
1358
|
+
formData.append(key, value);
|
1359
|
+
}
|
1360
|
+
}
|
1361
|
+
for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
|
1362
|
+
file = files[_j];
|
1363
|
+
this.emit("sending", file, xhr, formData);
|
1364
|
+
}
|
1365
|
+
if (this.options.uploadMultiple) {
|
1366
|
+
this.emit("sendingmultiple", files, xhr, formData);
|
1367
|
+
}
|
1368
|
+
if (this.element.tagName === "FORM") {
|
1369
|
+
_ref2 = this.element.querySelectorAll("input, textarea, select, button");
|
1370
|
+
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
|
1371
|
+
input = _ref2[_k];
|
1372
|
+
inputName = input.getAttribute("name");
|
1373
|
+
inputType = input.getAttribute("type");
|
1374
|
+
if (!inputType || ((_ref3 = inputType.toLowerCase()) !== "checkbox" && _ref3 !== "radio") || input.checked) {
|
1375
|
+
formData.append(inputName, input.value);
|
1376
|
+
}
|
1377
|
+
}
|
1378
|
+
}
|
1379
|
+
for (_l = 0, _len3 = files.length; _l < _len3; _l++) {
|
1380
|
+
file = files[_l];
|
1381
|
+
formData.append("" + this.options.paramName + (this.options.uploadMultiple ? "[]" : ""), file, file.name);
|
1382
|
+
}
|
1383
|
+
return xhr.send(formData);
|
1384
|
+
};
|
1385
|
+
|
1386
|
+
Dropzone.prototype._finished = function(files, responseText, e) {
|
1387
|
+
var file, _i, _len;
|
1388
|
+
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
1389
|
+
file = files[_i];
|
1390
|
+
file.status = Dropzone.SUCCESS;
|
1391
|
+
this.emit("success", file, responseText, e);
|
1392
|
+
this.emit("complete", file);
|
1393
|
+
}
|
1394
|
+
if (this.options.uploadMultiple) {
|
1395
|
+
this.emit("successmultiple", files, responseText, e);
|
1396
|
+
this.emit("completemultiple", files);
|
1397
|
+
}
|
1398
|
+
if (this.options.autoProcessQueue) {
|
1399
|
+
return this.processQueue();
|
1400
|
+
}
|
1401
|
+
};
|
1402
|
+
|
1403
|
+
Dropzone.prototype._errorProcessing = function(files, message, xhr) {
|
1404
|
+
var file, _i, _len;
|
1405
|
+
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
1406
|
+
file = files[_i];
|
1407
|
+
file.status = Dropzone.ERROR;
|
1408
|
+
this.emit("error", file, message, xhr);
|
1409
|
+
this.emit("complete", file);
|
1410
|
+
}
|
1411
|
+
if (this.options.uploadMultiple) {
|
1412
|
+
this.emit("errormultiple", files, message, xhr);
|
1413
|
+
this.emit("completemultiple", files);
|
1414
|
+
}
|
1415
|
+
if (this.options.autoProcessQueue) {
|
1416
|
+
return this.processQueue();
|
1417
|
+
}
|
1418
|
+
};
|
1419
|
+
|
1420
|
+
return Dropzone;
|
1421
|
+
|
1422
|
+
})(Em);
|
1423
|
+
|
1424
|
+
Dropzone.version = "3.6.1";
|
1425
|
+
|
1426
|
+
Dropzone.options = {};
|
1427
|
+
|
1428
|
+
Dropzone.optionsForElement = function(element) {
|
1429
|
+
if (element.id) {
|
1430
|
+
return Dropzone.options[camelize(element.id)];
|
1431
|
+
} else {
|
1432
|
+
return void 0;
|
1433
|
+
}
|
1434
|
+
};
|
1435
|
+
|
1436
|
+
Dropzone.instances = [];
|
1437
|
+
|
1438
|
+
Dropzone.forElement = function(element) {
|
1439
|
+
if (typeof element === "string") {
|
1440
|
+
element = document.querySelector(element);
|
1441
|
+
}
|
1442
|
+
if ((element != null ? element.dropzone : void 0) == null) {
|
1443
|
+
throw new Error("No Dropzone found for given element. This is probably because you're trying to access it before Dropzone had the time to initialize. Use the `init` option to setup any additional observers on your Dropzone.");
|
1444
|
+
}
|
1445
|
+
return element.dropzone;
|
1446
|
+
};
|
1447
|
+
|
1448
|
+
Dropzone.autoDiscover = true;
|
1449
|
+
|
1450
|
+
Dropzone.discover = function() {
|
1451
|
+
var checkElements, dropzone, dropzones, _i, _len, _results;
|
1452
|
+
if (!Dropzone.autoDiscover) {
|
1453
|
+
return;
|
1454
|
+
}
|
1455
|
+
if (document.querySelectorAll) {
|
1456
|
+
dropzones = document.querySelectorAll(".dropzone");
|
1457
|
+
} else {
|
1458
|
+
dropzones = [];
|
1459
|
+
checkElements = function(elements) {
|
1460
|
+
var el, _i, _len, _results;
|
1461
|
+
_results = [];
|
1462
|
+
for (_i = 0, _len = elements.length; _i < _len; _i++) {
|
1463
|
+
el = elements[_i];
|
1464
|
+
if (/(^| )dropzone($| )/.test(el.className)) {
|
1465
|
+
_results.push(dropzones.push(el));
|
1466
|
+
} else {
|
1467
|
+
_results.push(void 0);
|
1468
|
+
}
|
1469
|
+
}
|
1470
|
+
return _results;
|
1471
|
+
};
|
1472
|
+
checkElements(document.getElementsByTagName("div"));
|
1473
|
+
checkElements(document.getElementsByTagName("form"));
|
1474
|
+
}
|
1475
|
+
_results = [];
|
1476
|
+
for (_i = 0, _len = dropzones.length; _i < _len; _i++) {
|
1477
|
+
dropzone = dropzones[_i];
|
1478
|
+
if (Dropzone.optionsForElement(dropzone) !== false) {
|
1479
|
+
_results.push(new Dropzone(dropzone));
|
1480
|
+
} else {
|
1481
|
+
_results.push(void 0);
|
1482
|
+
}
|
1483
|
+
}
|
1484
|
+
return _results;
|
1485
|
+
};
|
1486
|
+
|
1487
|
+
Dropzone.blacklistedBrowsers = [/opera.*Macintosh.*version\/12/i];
|
1488
|
+
|
1489
|
+
Dropzone.isBrowserSupported = function() {
|
1490
|
+
var capableBrowser, regex, _i, _len, _ref;
|
1491
|
+
capableBrowser = true;
|
1492
|
+
if (window.File && window.FileReader && window.FileList && window.Blob && window.FormData && document.querySelector) {
|
1493
|
+
if (!("classList" in document.createElement("a"))) {
|
1494
|
+
capableBrowser = false;
|
1495
|
+
} else {
|
1496
|
+
_ref = Dropzone.blacklistedBrowsers;
|
1497
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1498
|
+
regex = _ref[_i];
|
1499
|
+
if (regex.test(navigator.userAgent)) {
|
1500
|
+
capableBrowser = false;
|
1501
|
+
continue;
|
1502
|
+
}
|
1503
|
+
}
|
1504
|
+
}
|
1505
|
+
} else {
|
1506
|
+
capableBrowser = false;
|
1507
|
+
}
|
1508
|
+
return capableBrowser;
|
1509
|
+
};
|
1510
|
+
|
1511
|
+
without = function(list, rejectedItem) {
|
1512
|
+
var item, _i, _len, _results;
|
1513
|
+
_results = [];
|
1514
|
+
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
1515
|
+
item = list[_i];
|
1516
|
+
if (item !== rejectedItem) {
|
1517
|
+
_results.push(item);
|
1518
|
+
}
|
1519
|
+
}
|
1520
|
+
return _results;
|
1521
|
+
};
|
1522
|
+
|
1523
|
+
camelize = function(str) {
|
1524
|
+
return str.replace(/[\-_](\w)/g, function(match) {
|
1525
|
+
return match[1].toUpperCase();
|
1526
|
+
});
|
1527
|
+
};
|
1528
|
+
|
1529
|
+
Dropzone.createElement = function(string) {
|
1530
|
+
var div;
|
1531
|
+
div = document.createElement("div");
|
1532
|
+
div.innerHTML = string;
|
1533
|
+
return div.childNodes[0];
|
1534
|
+
};
|
1535
|
+
|
1536
|
+
Dropzone.elementInside = function(element, container) {
|
1537
|
+
if (element === container) {
|
1538
|
+
return true;
|
1539
|
+
}
|
1540
|
+
while (element = element.parentNode) {
|
1541
|
+
if (element === container) {
|
1542
|
+
return true;
|
1543
|
+
}
|
1544
|
+
}
|
1545
|
+
return false;
|
1546
|
+
};
|
1547
|
+
|
1548
|
+
Dropzone.getElement = function(el, name) {
|
1549
|
+
var element;
|
1550
|
+
if (typeof el === "string") {
|
1551
|
+
element = document.querySelector(el);
|
1552
|
+
} else if (el.nodeType != null) {
|
1553
|
+
element = el;
|
1554
|
+
}
|
1555
|
+
if (element == null) {
|
1556
|
+
throw new Error("Invalid `" + name + "` option provided. Please provide a CSS selector or a plain HTML element.");
|
1557
|
+
}
|
1558
|
+
return element;
|
1559
|
+
};
|
1560
|
+
|
1561
|
+
Dropzone.getElements = function(els, name) {
|
1562
|
+
var e, el, elements, _i, _j, _len, _len1, _ref;
|
1563
|
+
if (els instanceof Array) {
|
1564
|
+
elements = [];
|
1565
|
+
try {
|
1566
|
+
for (_i = 0, _len = els.length; _i < _len; _i++) {
|
1567
|
+
el = els[_i];
|
1568
|
+
elements.push(this.getElement(el, name));
|
1569
|
+
}
|
1570
|
+
} catch (_error) {
|
1571
|
+
e = _error;
|
1572
|
+
elements = null;
|
1573
|
+
}
|
1574
|
+
} else if (typeof els === "string") {
|
1575
|
+
elements = [];
|
1576
|
+
_ref = document.querySelectorAll(els);
|
1577
|
+
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
1578
|
+
el = _ref[_j];
|
1579
|
+
elements.push(el);
|
1580
|
+
}
|
1581
|
+
} else if (els.nodeType != null) {
|
1582
|
+
elements = [els];
|
1583
|
+
}
|
1584
|
+
if (!((elements != null) && elements.length)) {
|
1585
|
+
throw new Error("Invalid `" + name + "` option provided. Please provide a CSS selector, a plain HTML element or a list of those.");
|
1586
|
+
}
|
1587
|
+
return elements;
|
1588
|
+
};
|
1589
|
+
|
1590
|
+
Dropzone.isValidFile = function(file, acceptedFiles) {
|
1591
|
+
var baseMimeType, mimeType, validType, _i, _len;
|
1592
|
+
if (!acceptedFiles) {
|
1593
|
+
return true;
|
1594
|
+
}
|
1595
|
+
acceptedFiles = acceptedFiles.split(",");
|
1596
|
+
mimeType = file.type;
|
1597
|
+
baseMimeType = mimeType.replace(/\/.*$/, "");
|
1598
|
+
for (_i = 0, _len = acceptedFiles.length; _i < _len; _i++) {
|
1599
|
+
validType = acceptedFiles[_i];
|
1600
|
+
validType = validType.trim();
|
1601
|
+
if (validType.charAt(0) === ".") {
|
1602
|
+
if (file.name.indexOf(validType, file.name.length - validType.length) !== -1) {
|
1603
|
+
return true;
|
1604
|
+
}
|
1605
|
+
} else if (/\/\*$/.test(validType)) {
|
1606
|
+
if (baseMimeType === validType.replace(/\/.*$/, "")) {
|
1607
|
+
return true;
|
1608
|
+
}
|
1609
|
+
} else {
|
1610
|
+
if (mimeType === validType) {
|
1611
|
+
return true;
|
1612
|
+
}
|
1613
|
+
}
|
1614
|
+
}
|
1615
|
+
return false;
|
1616
|
+
};
|
1617
|
+
|
1618
|
+
if (typeof jQuery !== "undefined" && jQuery !== null) {
|
1619
|
+
jQuery.fn.dropzone = function(options) {
|
1620
|
+
return this.each(function() {
|
1621
|
+
return new Dropzone(this, options);
|
1622
|
+
});
|
1623
|
+
};
|
1624
|
+
}
|
1625
|
+
|
1626
|
+
if (typeof module !== "undefined" && module !== null) {
|
1627
|
+
module.exports = Dropzone;
|
1628
|
+
} else {
|
1629
|
+
window.Dropzone = Dropzone;
|
1630
|
+
}
|
1631
|
+
|
1632
|
+
Dropzone.ADDED = "added";
|
1633
|
+
|
1634
|
+
Dropzone.QUEUED = "queued";
|
1635
|
+
|
1636
|
+
Dropzone.ACCEPTED = Dropzone.QUEUED;
|
1637
|
+
|
1638
|
+
Dropzone.UPLOADING = "uploading";
|
1639
|
+
|
1640
|
+
Dropzone.PROCESSING = Dropzone.UPLOADING;
|
1641
|
+
|
1642
|
+
Dropzone.CANCELED = "canceled";
|
1643
|
+
|
1644
|
+
Dropzone.ERROR = "error";
|
1645
|
+
|
1646
|
+
Dropzone.SUCCESS = "success";
|
1647
|
+
|
1648
|
+
/*
|
1649
|
+
# contentloaded.js
|
1650
|
+
#
|
1651
|
+
# Author: Diego Perini (diego.perini at gmail.com)
|
1652
|
+
# Summary: cross-browser wrapper for DOMContentLoaded
|
1653
|
+
# Updated: 20101020
|
1654
|
+
# License: MIT
|
1655
|
+
# Version: 1.2
|
1656
|
+
#
|
1657
|
+
# URL:
|
1658
|
+
# http://javascript.nwbox.com/ContentLoaded/
|
1659
|
+
# http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
|
1660
|
+
*/
|
1661
|
+
|
1662
|
+
|
1663
|
+
contentLoaded = function(win, fn) {
|
1664
|
+
var add, doc, done, init, poll, pre, rem, root, top;
|
1665
|
+
done = false;
|
1666
|
+
top = true;
|
1667
|
+
doc = win.document;
|
1668
|
+
root = doc.documentElement;
|
1669
|
+
add = (doc.addEventListener ? "addEventListener" : "attachEvent");
|
1670
|
+
rem = (doc.addEventListener ? "removeEventListener" : "detachEvent");
|
1671
|
+
pre = (doc.addEventListener ? "" : "on");
|
1672
|
+
init = function(e) {
|
1673
|
+
if (e.type === "readystatechange" && doc.readyState !== "complete") {
|
1674
|
+
return;
|
1675
|
+
}
|
1676
|
+
(e.type === "load" ? win : doc)[rem](pre + e.type, init, false);
|
1677
|
+
if (!done && (done = true)) {
|
1678
|
+
return fn.call(win, e.type || e);
|
1679
|
+
}
|
1680
|
+
};
|
1681
|
+
poll = function() {
|
1682
|
+
var e;
|
1683
|
+
try {
|
1684
|
+
root.doScroll("left");
|
1685
|
+
} catch (_error) {
|
1686
|
+
e = _error;
|
1687
|
+
setTimeout(poll, 50);
|
1688
|
+
return;
|
1689
|
+
}
|
1690
|
+
return init("poll");
|
1691
|
+
};
|
1692
|
+
if (doc.readyState !== "complete") {
|
1693
|
+
if (doc.createEventObject && root.doScroll) {
|
1694
|
+
try {
|
1695
|
+
top = !win.frameElement;
|
1696
|
+
} catch (_error) {}
|
1697
|
+
if (top) {
|
1698
|
+
poll();
|
1699
|
+
}
|
1700
|
+
}
|
1701
|
+
doc[add](pre + "DOMContentLoaded", init, false);
|
1702
|
+
doc[add](pre + "readystatechange", init, false);
|
1703
|
+
return win[add](pre + "load", init, false);
|
1704
|
+
}
|
1705
|
+
};
|
1706
|
+
|
1707
|
+
contentLoaded(window, Dropzone.discover);
|
1708
|
+
|
1709
|
+
}).call(this);
|
1710
|
+
|
1711
|
+
});
|
1712
|
+
require.alias("component-emitter/index.js", "dropzone/deps/emitter/index.js");
|
1713
|
+
require.alias("component-emitter/index.js", "emitter/index.js");
|
1714
|
+
|
1715
|
+
if (typeof exports == "object") {
|
1716
|
+
module.exports = require("dropzone");
|
1717
|
+
} else if (typeof define == "function" && define.amd) {
|
1718
|
+
define(function(){ return require("dropzone"); });
|
1719
|
+
} else {
|
1720
|
+
this["Dropzone"] = require("dropzone");
|
1721
|
+
}})();
|