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