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