Passed
Push — master ( f898a6...8a0dc5 )
by Guangyu
08:08 queued 11s
created

admin/js/plugins/dropzone/dropzone-amd-module.js   F

Complexity

Total Complexity 700
Complexity/F 3.1

Size

Lines of Code 3844
Function Count 226

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 700
eloc 2130
mnd 474
bc 474
fnc 226
dl 0
loc 3844
rs 0.8
bpm 2.0973
cpm 3.0973
noi 137
c 0
b 0
f 0

88 Functions

Rating   Name   Duplication   Size   Complexity  
A dropzone-amd-module.js ➔ on 0 11 2
A dropzone-amd-module.js ➔ _getChunk 0 7 3
F dropzone-amd-module.js ➔ _updateFilesUploadProgress 0 145 27
A dropzone-amd-module.js ➔ camelize 0 5 2
F dropzone-amd-module.js ➔ contentLoaded 0 48 14
A dropzone-amd-module.js ➔ _handleUploadError 0 19 4
A dropzone-amd-module.js ➔ disable 0 12 3
B dropzone-amd-module.js ➔ processFiles 0 34 7
A dropzone-amd-module.js ➔ exifManipulation 0 6 1
A dropzone-amd-module.js ➔ getUploadingFiles 0 3 1
A dropzone-amd-module.js ➔ getExifArray 0 16 3
F dropzone-amd-module.js ➔ _addFilesFromDirectory 0 62 15
B dropzone-amd-module.js ➔ _typeof 0 1 8
A dropzone-amd-module.js ➔ removeFile 0 12 3
C dropzone-amd-module.js ➔ getExistingFallback 0 39 10
A dropzone-amd-module.js ➔ _renameFile 0 7 2
A dropzone-amd-module.js ➔ _createClass 0 1 3
A dropzone-amd-module.js ➔ _updateMaxFilesReachedClass 0 11 3
A dropzone-amd-module.js ➔ _getFilesWithXhr 0 8 3
A dropzone-amd-module.js ➔ restore 0 10 2
A dropzone-amd-module.js ➔ getAcceptedFiles 0 7 3
A dropzone-amd-module.js ➔ enqueueFile 0 15 4
A dropzone-amd-module.js ➔ _enqueueThumbnail 0 11 3
A dropzone-amd-module.js ➔ _getParamName 0 7 3
B dropzone-amd-module.js ➔ _errorProcessing 0 36 8
A dropzone-amd-module.js ➔ extend 0 16 5
A dropzone-amd-module.js ➔ _assertThisInitialized 0 1 2
F dropzone-amd-module.js ➔ Dropzone 0 97 19
D dropzone-amd-module.js ➔ _addFilesFromItems 0 51 12
A dropzone-amd-module.js ➔ getFilesWithStatus 0 7 3
A dropzone-amd-module.js ➔ paste 0 14 5
F dropzone-amd-module.js ➔ createThumbnailFromUrl 0 101 16
B dropzone-amd-module.js ➔ decode64 0 48 6
A dropzone-amd-module.js ➔ _transformFiles 0 21 5
A dropzone-amd-module.js ➔ _defineProperties 0 1 3
A dropzone-amd-module.js ➔ resizeImage 0 25 5
B dropzone-amd-module.js ➔ encode64 0 37 5
B dropzone-amd-module.js ➔ enqueueFiles 0 27 6
A dropzone-amd-module.js ➔ setupEventListeners 0 14 4
A dropzone-amd-module.js ➔ filesize 0 23 4
F dropzone-amd-module.js ➔ cancelUpload 0 72 17
B dropzone-amd-module.js ➔ handleFiles 0 25 6
A dropzone-amd-module.js ➔ __guard__ 0 3 4
B dropzone-amd-module.js ➔ off 0 31 6
A dropzone-amd-module.js ➔ insertExif 0 11 1
A dropzone-amd-module.js ➔ accept 0 12 4
A dropzone-amd-module.js ➔ _possibleConstructorReturn 0 1 2
F dropzone-amd-module.js ➔ _uploadData 0 134 26
A dropzone-amd-module.js ➔ initClass 0 873 1
A dropzone-amd-module.js ➔ drop 0 28 5
A dropzone-amd-module.js ➔ _classCallCheck 0 1 2
F dropzone-amd-module.js ➔ checkElements 0 35 16
B dropzone-amd-module.js ➔ _finishedUploading 0 36 8
A dropzone-amd-module.js ➔ processFile 0 3 1
B dropzone-amd-module.js ➔ processQueue 0 30 6
A dropzone-amd-module.js ➔ addFile 0 39 4
F dropzone-amd-module.js ➔ detectVerticalSquash 0 37 48
A dropzone-amd-module.js ➔ getActiveFiles 0 7 3
A dropzone-amd-module.js ➔ getQueuedFiles 0 3 1
A dropzone-amd-module.js ➔ _setPrototypeOf 0 1 2
F dropzone-amd-module.js ➔ _addFormElementData 0 64 17
F dropzone-amd-module.js ➔ uploadFiles 0 100 17
A dropzone-amd-module.js ➔ __guardMethod__ 0 7 2
B dropzone-amd-module.js ➔ _finished 0 36 8
A dropzone-amd-module.js ➔ destroy 0 12 3
C dropzone-amd-module.js ➔ emit 0 36 9
A dropzone-amd-module.js ➔ resolveOption 0 11 4
A dropzone-amd-module.js ➔ uuidv4 0 7 3
A dropzone-amd-module.js ➔ createThumbnail 0 21 4
F dropzone-amd-module.js ➔ without 0 7 23
F dropzone-amd-module.js ➔ init 0 211 44
A dropzone-amd-module.js ➔ removeEventListeners 0 14 4
B dropzone-amd-module.js ➔ removeAllFiles 0 35 8
B dropzone-amd-module.js ➔ updateTotalUploadProgress 0 39 7
A dropzone-amd-module.js ➔ slice2Segments 0 28 5
A dropzone-amd-module.js ➔ enable 0 7 2
A dropzone-amd-module.js ➔ _processThumbnailQueue 0 18 3
A dropzone-amd-module.js ➔ submitRequest 0 3 1
B dropzone-amd-module.js ➔ getFallbackForm 0 27 6
A dropzone-amd-module.js ➔ Emitter 0 3 2
A dropzone-amd-module.js ➔ getAddedFiles 0 3 1
A dropzone-amd-module.js ➔ _getPrototypeOf 0 1 3
A dropzone-amd-module.js ➔ drawImageIOSFix 0 4 1
A dropzone-amd-module.js ➔ ExifRestore 0 3 2
A dropzone-amd-module.js ➔ uploadFile 0 3 1
A dropzone-amd-module.js ➔ getRejectedFiles 0 7 3
B dropzone-amd-module.js ➔ displayExistingFile 0 21 6
A dropzone-amd-module.js ➔ _inherits 0 1 3

How to fix   Complexity   

Complexity

Complex classes like admin/js/plugins/dropzone/dropzone-amd-module.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
// Uses AMD or browser globals to create a jQuery plugin.
2
(function (factory) {
3
  if (typeof define === 'function' && define.amd) {
4
      // AMD. Register as an anonymous module.
5
      define(['jquery'], factory);
6
  } else {
7
      // Browser globals
8
      factory(jQuery);
9
  }
10
} (function (jQuery) {
11
    var module = { exports: { } }; // Fake component
12
13
"use strict";
14
15
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
0 ignored issues
show
Unused Code introduced by
The expression "@babel/helpers - typeof" has no effects. Consider removing it.
Loading history...
16
17
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
18
19
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
20
21
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
22
23
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
24
25
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
26
27
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
28
29
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
30
31
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
32
33
/*
34
 *
35
 * More info at [www.dropzonejs.com](http://www.dropzonejs.com)
36
 *
37
 * Copyright (c) 2012, Matias Meno
38
 *
39
 * Permission is hereby granted, free of charge, to any person obtaining a copy
40
 * of this software and associated documentation files (the "Software"), to deal
41
 * in the Software without restriction, including without limitation the rights
42
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
 * copies of the Software, and to permit persons to whom the Software is
44
 * furnished to do so, subject to the following conditions:
45
 *
46
 * The above copyright notice and this permission notice shall be included in
47
 * all copies or substantial portions of the Software.
48
 *
49
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
55
 * THE SOFTWARE.
56
 *
57
 */
58
// The Emitter class provides the ability to call `.on()` on Dropzone to listen
59
// to events.
60
// It is strongly based on component's emitter class, and I removed the
61
// functionality because of the dependency hell with different frameworks.
62
var Emitter =
63
/*#__PURE__*/
64
function () {
65
  function Emitter() {
66
    _classCallCheck(this, Emitter);
67
  }
68
69
  _createClass(Emitter, [{
70
    key: "on",
71
    // Add an event listener for given event
72
    value: function on(event, fn) {
73
      this._callbacks = this._callbacks || {}; // Create namespace for this event
74
75
      if (!this._callbacks[event]) {
76
        this._callbacks[event] = [];
77
      }
78
79
      this._callbacks[event].push(fn);
80
81
      return this;
82
    }
83
  }, {
84
    key: "emit",
85
    value: function emit(event) {
86
      this._callbacks = this._callbacks || {};
87
      var callbacks = this._callbacks[event];
88
89
      if (callbacks) {
90
        for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
91
          args[_key - 1] = arguments[_key];
92
        }
93
94
        var _iteratorNormalCompletion = true;
95
        var _didIteratorError = false;
96
        var _iteratorError = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError is implicitly marked as undefined by the declaration.
Loading history...
97
98
        try {
99
          for (var _iterator = callbacks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
100
            var callback = _step.value;
101
            callback.apply(this, args);
102
          }
103
        } catch (err) {
104
          _didIteratorError = true;
105
          _iteratorError = err;
106
        } finally {
107
          try {
108
            if (!_iteratorNormalCompletion && _iterator["return"] != null) {
109
              _iterator["return"]();
110
            }
111
          } finally {
112
            if (_didIteratorError) {
113
              throw _iteratorError;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
114
            }
115
          }
116
        }
117
      }
118
119
      return this;
120
    } // Remove event listener for given event. If fn is not provided, all event
121
    // listeners for that event will be removed. If neither is provided, all
122
    // event listeners will be removed.
123
124
  }, {
125
    key: "off",
126
    value: function off(event, fn) {
127
      if (!this._callbacks || arguments.length === 0) {
128
        this._callbacks = {};
129
        return this;
130
      } // specific event
131
132
133
      var callbacks = this._callbacks[event];
134
135
      if (!callbacks) {
136
        return this;
137
      } // remove all handlers
138
139
140
      if (arguments.length === 1) {
141
        delete this._callbacks[event];
142
        return this;
143
      } // remove specific handler
144
145
146
      for (var i = 0; i < callbacks.length; i++) {
147
        var callback = callbacks[i];
148
149
        if (callback === fn) {
150
          callbacks.splice(i, 1);
151
          break;
152
        }
153
      }
154
155
      return this;
156
    }
157
  }]);
158
159
  return Emitter;
160
}();
161
162
var Dropzone =
163
/*#__PURE__*/
164
function (_Emitter) {
165
  _inherits(Dropzone, _Emitter);
166
167
  _createClass(Dropzone, null, [{
168
    key: "initClass",
169
    value: function initClass() {
170
      // Exposing the emitter class, mainly for tests
171
      this.prototype.Emitter = Emitter;
172
      /*
173
       This is a list of all available events you can register on a dropzone object.
174
        You can register an event handler like this:
175
        dropzone.on("dragEnter", function() { });
176
        */
177
178
      this.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "addedfile", "addedfiles", "removedfile", "thumbnail", "error", "errormultiple", "processing", "processingmultiple", "uploadprogress", "totaluploadprogress", "sending", "sendingmultiple", "success", "successmultiple", "canceled", "canceledmultiple", "complete", "completemultiple", "reset", "maxfilesexceeded", "maxfilesreached", "queuecomplete"];
179
      this.prototype.defaultOptions = {
180
        /**
181
         * Has to be specified on elements other than form (or when the form
182
         * doesn't have an `action` attribute). You can also
183
         * provide a function that will be called with `files` and
184
         * must return the url (since `v3.12.0`)
185
         */
186
        url: null,
187
188
        /**
189
         * Can be changed to `"put"` if necessary. You can also provide a function
190
         * that will be called with `files` and must return the method (since `v3.12.0`).
191
         */
192
        method: "post",
193
194
        /**
195
         * Will be set on the XHRequest.
196
         */
197
        withCredentials: false,
198
199
        /**
200
         * The timeout for the XHR requests in milliseconds (since `v4.4.0`).
201
         */
202
        timeout: 30000,
203
204
        /**
205
         * How many file uploads to process in parallel (See the
206
         * Enqueuing file uploads documentation section for more info)
207
         */
208
        parallelUploads: 2,
209
210
        /**
211
         * Whether to send multiple files in one request. If
212
         * this it set to true, then the fallback file input element will
213
         * have the `multiple` attribute as well. This option will
214
         * also trigger additional events (like `processingmultiple`). See the events
215
         * documentation section for more information.
216
         */
217
        uploadMultiple: false,
218
219
        /**
220
         * Whether you want files to be uploaded in chunks to your server. This can't be
221
         * used in combination with `uploadMultiple`.
222
         *
223
         * See [chunksUploaded](#config-chunksUploaded) for the callback to finalise an upload.
224
         */
225
        chunking: false,
226
227
        /**
228
         * If `chunking` is enabled, this defines whether **every** file should be chunked,
229
         * even if the file size is below chunkSize. This means, that the additional chunk
230
         * form data will be submitted and the `chunksUploaded` callback will be invoked.
231
         */
232
        forceChunking: false,
233
234
        /**
235
         * If `chunking` is `true`, then this defines the chunk size in bytes.
236
         */
237
        chunkSize: 2000000,
238
239
        /**
240
         * If `true`, the individual chunks of a file are being uploaded simultaneously.
241
         */
242
        parallelChunkUploads: false,
243
244
        /**
245
         * Whether a chunk should be retried if it fails.
246
         */
247
        retryChunks: false,
248
249
        /**
250
         * If `retryChunks` is true, how many times should it be retried.
251
         */
252
        retryChunksLimit: 3,
253
254
        /**
255
         * If not `null` defines how many files this Dropzone handles. If it exceeds,
256
         * the event `maxfilesexceeded` will be called. The dropzone element gets the
257
         * class `dz-max-files-reached` accordingly so you can provide visual feedback.
258
         */
259
        maxFilesize: 256,
260
261
        /**
262
         * The name of the file param that gets transferred.
263
         * **NOTE**: If you have the option  `uploadMultiple` set to `true`, then
264
         * Dropzone will append `[]` to the name.
265
         */
266
        paramName: "file",
267
268
        /**
269
         * Whether thumbnails for images should be generated
270
         */
271
        createImageThumbnails: true,
272
273
        /**
274
         * In MB. When the filename exceeds this limit, the thumbnail will not be generated.
275
         */
276
        maxThumbnailFilesize: 10,
277
278
        /**
279
         * If `null`, the ratio of the image will be used to calculate it.
280
         */
281
        thumbnailWidth: 120,
282
283
        /**
284
         * The same as `thumbnailWidth`. If both are null, images will not be resized.
285
         */
286
        thumbnailHeight: 120,
287
288
        /**
289
         * How the images should be scaled down in case both, `thumbnailWidth` and `thumbnailHeight` are provided.
290
         * Can be either `contain` or `crop`.
291
         */
292
        thumbnailMethod: 'crop',
293
294
        /**
295
         * If set, images will be resized to these dimensions before being **uploaded**.
296
         * If only one, `resizeWidth` **or** `resizeHeight` is provided, the original aspect
297
         * ratio of the file will be preserved.
298
         *
299
         * The `options.transformFile` function uses these options, so if the `transformFile` function
300
         * is overridden, these options don't do anything.
301
         */
302
        resizeWidth: null,
303
304
        /**
305
         * See `resizeWidth`.
306
         */
307
        resizeHeight: null,
308
309
        /**
310
         * The mime type of the resized image (before it gets uploaded to the server).
311
         * If `null` the original mime type will be used. To force jpeg, for example, use `image/jpeg`.
312
         * See `resizeWidth` for more information.
313
         */
314
        resizeMimeType: null,
315
316
        /**
317
         * The quality of the resized images. See `resizeWidth`.
318
         */
319
        resizeQuality: 0.8,
320
321
        /**
322
         * How the images should be scaled down in case both, `resizeWidth` and `resizeHeight` are provided.
323
         * Can be either `contain` or `crop`.
324
         */
325
        resizeMethod: 'contain',
326
327
        /**
328
         * The base that is used to calculate the filesize. You can change this to
329
         * 1024 if you would rather display kibibytes, mebibytes, etc...
330
         * 1024 is technically incorrect, because `1024 bytes` are `1 kibibyte` not `1 kilobyte`.
331
         * You can change this to `1024` if you don't care about validity.
332
         */
333
        filesizeBase: 1000,
334
335
        /**
336
         * Can be used to limit the maximum number of files that will be handled by this Dropzone
337
         */
338
        maxFiles: null,
339
340
        /**
341
         * An optional object to send additional headers to the server. Eg:
342
         * `{ "My-Awesome-Header": "header value" }`
343
         */
344
        headers: null,
345
346
        /**
347
         * If `true`, the dropzone element itself will be clickable, if `false`
348
         * nothing will be clickable.
349
         *
350
         * You can also pass an HTML element, a CSS selector (for multiple elements)
351
         * or an array of those. In that case, all of those elements will trigger an
352
         * upload when clicked.
353
         */
354
        clickable: true,
355
356
        /**
357
         * Whether hidden files in directories should be ignored.
358
         */
359
        ignoreHiddenFiles: true,
360
361
        /**
362
         * The default implementation of `accept` checks the file's mime type or
363
         * extension against this list. This is a comma separated list of mime
364
         * types or file extensions.
365
         *
366
         * Eg.: `image/*,application/pdf,.psd`
367
         *
368
         * If the Dropzone is `clickable` this option will also be used as
369
         * [`accept`](https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-accept)
370
         * parameter on the hidden file input as well.
371
         */
372
        acceptedFiles: null,
373
374
        /**
375
         * **Deprecated!**
376
         * Use acceptedFiles instead.
377
         */
378
        acceptedMimeTypes: null,
379
380
        /**
381
         * If false, files will be added to the queue but the queue will not be
382
         * processed automatically.
383
         * This can be useful if you need some additional user input before sending
384
         * files (or if you want want all files sent at once).
385
         * If you're ready to send the file simply call `myDropzone.processQueue()`.
386
         *
387
         * See the [enqueuing file uploads](#enqueuing-file-uploads) documentation
388
         * section for more information.
389
         */
390
        autoProcessQueue: true,
391
392
        /**
393
         * If false, files added to the dropzone will not be queued by default.
394
         * You'll have to call `enqueueFile(file)` manually.
395
         */
396
        autoQueue: true,
397
398
        /**
399
         * If `true`, this will add a link to every file preview to remove or cancel (if
400
         * already uploading) the file. The `dictCancelUpload`, `dictCancelUploadConfirmation`
401
         * and `dictRemoveFile` options are used for the wording.
402
         */
403
        addRemoveLinks: false,
404
405
        /**
406
         * Defines where to display the file previews – if `null` the
407
         * Dropzone element itself is used. Can be a plain `HTMLElement` or a CSS
408
         * selector. The element should have the `dropzone-previews` class so
409
         * the previews are displayed properly.
410
         */
411
        previewsContainer: null,
412
413
        /**
414
         * This is the element the hidden input field (which is used when clicking on the
415
         * dropzone to trigger file selection) will be appended to. This might
416
         * be important in case you use frameworks to switch the content of your page.
417
         *
418
         * Can be a selector string, or an element directly.
419
         */
420
        hiddenInputContainer: "body",
421
422
        /**
423
         * If null, no capture type will be specified
424
         * If camera, mobile devices will skip the file selection and choose camera
425
         * If microphone, mobile devices will skip the file selection and choose the microphone
426
         * If camcorder, mobile devices will skip the file selection and choose the camera in video mode
427
         * On apple devices multiple must be set to false.  AcceptedFiles may need to
428
         * be set to an appropriate mime type (e.g. "image/*", "audio/*", or "video/*").
429
         */
430
        capture: null,
431
432
        /**
433
         * **Deprecated**. Use `renameFile` instead.
434
         */
435
        renameFilename: null,
436
437
        /**
438
         * A function that is invoked before the file is uploaded to the server and renames the file.
439
         * This function gets the `File` as argument and can use the `file.name`. The actual name of the
440
         * file that gets used during the upload can be accessed through `file.upload.filename`.
441
         */
442
        renameFile: null,
443
444
        /**
445
         * If `true` the fallback will be forced. This is very useful to test your server
446
         * implementations first and make sure that everything works as
447
         * expected without dropzone if you experience problems, and to test
448
         * how your fallbacks will look.
449
         */
450
        forceFallback: false,
451
452
        /**
453
         * The text used before any files are dropped.
454
         */
455
        dictDefaultMessage: "Drop files here to upload",
456
457
        /**
458
         * The text that replaces the default message text it the browser is not supported.
459
         */
460
        dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
461
462
        /**
463
         * The text that will be added before the fallback form.
464
         * If you provide a  fallback element yourself, or if this option is `null` this will
465
         * be ignored.
466
         */
467
        dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
468
469
        /**
470
         * If the filesize is too big.
471
         * `{{filesize}}` and `{{maxFilesize}}` will be replaced with the respective configuration values.
472
         */
473
        dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.",
474
475
        /**
476
         * If the file doesn't match the file type.
477
         */
478
        dictInvalidFileType: "You can't upload files of this type.",
479
480
        /**
481
         * If the server response was invalid.
482
         * `{{statusCode}}` will be replaced with the servers status code.
483
         */
484
        dictResponseError: "Server responded with {{statusCode}} code.",
485
486
        /**
487
         * If `addRemoveLinks` is true, the text to be used for the cancel upload link.
488
         */
489
        dictCancelUpload: "Cancel upload",
490
491
        /**
492
         * The text that is displayed if an upload was manually canceled
493
         */
494
        dictUploadCanceled: "Upload canceled.",
495
496
        /**
497
         * If `addRemoveLinks` is true, the text to be used for confirmation when cancelling upload.
498
         */
499
        dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
500
501
        /**
502
         * If `addRemoveLinks` is true, the text to be used to remove a file.
503
         */
504
        dictRemoveFile: "Remove file",
505
506
        /**
507
         * If this is not null, then the user will be prompted before removing a file.
508
         */
509
        dictRemoveFileConfirmation: null,
510
511
        /**
512
         * Displayed if `maxFiles` is st and exceeded.
513
         * The string `{{maxFiles}}` will be replaced by the configuration value.
514
         */
515
        dictMaxFilesExceeded: "You can not upload any more files.",
516
517
        /**
518
         * Allows you to translate the different units. Starting with `tb` for terabytes and going down to
519
         * `b` for bytes.
520
         */
521
        dictFileSizeUnits: {
522
          tb: "TB",
523
          gb: "GB",
524
          mb: "MB",
525
          kb: "KB",
526
          b: "b"
527
        },
528
529
        /**
530
         * Called when dropzone initialized
531
         * You can add event listeners here
532
         */
533
        init: function init() {},
534
535
        /**
536
         * Can be an **object** of additional parameters to transfer to the server, **or** a `Function`
537
         * that gets invoked with the `files`, `xhr` and, if it's a chunked upload, `chunk` arguments. In case
538
         * of a function, this needs to return a map.
539
         *
540
         * The default implementation does nothing for normal uploads, but adds relevant information for
541
         * chunked uploads.
542
         *
543
         * This is the same as adding hidden input fields in the form element.
544
         */
545
        params: function params(files, xhr, chunk) {
546
          if (chunk) {
547
            return {
548
              dzuuid: chunk.file.upload.uuid,
549
              dzchunkindex: chunk.index,
550
              dztotalfilesize: chunk.file.size,
551
              dzchunksize: this.options.chunkSize,
552
              dztotalchunkcount: chunk.file.upload.totalChunkCount,
553
              dzchunkbyteoffset: chunk.index * this.options.chunkSize
554
            };
555
          }
556
        },
557
558
        /**
559
         * A function that gets a [file](https://developer.mozilla.org/en-US/docs/DOM/File)
560
         * and a `done` function as parameters.
561
         *
562
         * If the done function is invoked without arguments, the file is "accepted" and will
563
         * be processed. If you pass an error message, the file is rejected, and the error
564
         * message will be displayed.
565
         * This function will not be called if the file is too big or doesn't match the mime types.
566
         */
567
        accept: function accept(file, done) {
568
          return done();
569
        },
570
571
        /**
572
         * The callback that will be invoked when all chunks have been uploaded for a file.
573
         * It gets the file for which the chunks have been uploaded as the first parameter,
574
         * and the `done` function as second. `done()` needs to be invoked when everything
575
         * needed to finish the upload process is done.
576
         */
577
        chunksUploaded: function chunksUploaded(file, done) {
578
          done();
579
        },
580
581
        /**
582
         * Gets called when the browser is not supported.
583
         * The default implementation shows the fallback input field and adds
584
         * a text.
585
         */
586
        fallback: function fallback() {
587
          // This code should pass in IE7... :(
588
          var messageElement;
589
          this.element.className = "".concat(this.element.className, " dz-browser-not-supported");
590
          var _iteratorNormalCompletion2 = true;
591
          var _didIteratorError2 = false;
592
          var _iteratorError2 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError2 is implicitly marked as undefined by the declaration.
Loading history...
593
594
          try {
595
            for (var _iterator2 = this.element.getElementsByTagName("div")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
596
              var child = _step2.value;
597
598
              if (/(^| )dz-message($| )/.test(child.className)) {
599
                messageElement = child;
600
                child.className = "dz-message"; // Removes the 'dz-default' class
601
602
                break;
603
              }
604
            }
605
          } catch (err) {
606
            _didIteratorError2 = true;
607
            _iteratorError2 = err;
608
          } finally {
609
            try {
610
              if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
611
                _iterator2["return"]();
612
              }
613
            } finally {
614
              if (_didIteratorError2) {
615
                throw _iteratorError2;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
616
              }
617
            }
618
          }
619
620
          if (!messageElement) {
621
            messageElement = Dropzone.createElement("<div class=\"dz-message\"><span></span></div>");
622
            this.element.appendChild(messageElement);
623
          }
624
625
          var span = messageElement.getElementsByTagName("span")[0];
626
627
          if (span) {
628
            if (span.textContent != null) {
629
              span.textContent = this.options.dictFallbackMessage;
630
            } else if (span.innerText != null) {
631
              span.innerText = this.options.dictFallbackMessage;
632
            }
633
          }
634
635
          return this.element.appendChild(this.getFallbackForm());
636
        },
637
638
        /**
639
         * Gets called to calculate the thumbnail dimensions.
640
         *
641
         * It gets `file`, `width` and `height` (both may be `null`) as parameters and must return an object containing:
642
         *
643
         *  - `srcWidth` & `srcHeight` (required)
644
         *  - `trgWidth` & `trgHeight` (required)
645
         *  - `srcX` & `srcY` (optional, default `0`)
646
         *  - `trgX` & `trgY` (optional, default `0`)
647
         *
648
         * Those values are going to be used by `ctx.drawImage()`.
649
         */
650
        resize: function resize(file, width, height, resizeMethod) {
651
          var info = {
652
            srcX: 0,
653
            srcY: 0,
654
            srcWidth: file.width,
655
            srcHeight: file.height
656
          };
657
          var srcRatio = file.width / file.height; // Automatically calculate dimensions if not specified
658
659
          if (width == null && height == null) {
660
            width = info.srcWidth;
661
            height = info.srcHeight;
662
          } else if (width == null) {
663
            width = height * srcRatio;
664
          } else if (height == null) {
665
            height = width / srcRatio;
666
          } // Make sure images aren't upscaled
667
668
669
          width = Math.min(width, info.srcWidth);
670
          height = Math.min(height, info.srcHeight);
671
          var trgRatio = width / height;
672
673
          if (info.srcWidth > width || info.srcHeight > height) {
674
            // Image is bigger and needs rescaling
675
            if (resizeMethod === 'crop') {
676
              if (srcRatio > trgRatio) {
677
                info.srcHeight = file.height;
678
                info.srcWidth = info.srcHeight * trgRatio;
679
              } else {
680
                info.srcWidth = file.width;
681
                info.srcHeight = info.srcWidth / trgRatio;
682
              }
683
            } else if (resizeMethod === 'contain') {
684
              // Method 'contain'
685
              if (srcRatio > trgRatio) {
686
                height = width / srcRatio;
687
              } else {
688
                width = height * srcRatio;
689
              }
690
            } else {
691
              throw new Error("Unknown resizeMethod '".concat(resizeMethod, "'"));
692
            }
693
          }
694
695
          info.srcX = (file.width - info.srcWidth) / 2;
696
          info.srcY = (file.height - info.srcHeight) / 2;
697
          info.trgWidth = width;
698
          info.trgHeight = height;
699
          return info;
700
        },
701
702
        /**
703
         * Can be used to transform the file (for example, resize an image if necessary).
704
         *
705
         * The default implementation uses `resizeWidth` and `resizeHeight` (if provided) and resizes
706
         * images according to those dimensions.
707
         *
708
         * Gets the `file` as the first parameter, and a `done()` function as the second, that needs
709
         * to be invoked with the file when the transformation is done.
710
         */
711
        transformFile: function transformFile(file, done) {
712
          if ((this.options.resizeWidth || this.options.resizeHeight) && file.type.match(/image.*/)) {
713
            return this.resizeImage(file, this.options.resizeWidth, this.options.resizeHeight, this.options.resizeMethod, done);
714
          } else {
715
            return done(file);
716
          }
717
        },
718
719
        /**
720
         * A string that contains the template used for each dropped
721
         * file. Change it to fulfill your needs but make sure to properly
722
         * provide all elements.
723
         *
724
         * If you want to use an actual HTML element instead of providing a String
725
         * as a config option, you could create a div with the id `tpl`,
726
         * put the template inside it and provide the element like this:
727
         *
728
         *     document
729
         *       .querySelector('#tpl')
730
         *       .innerHTML
731
         *
732
         */
733
        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\">\n      <title>Check</title>\n      <g stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\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\" stroke-opacity=\"0.198794158\" stroke=\"#747474\" fill-opacity=\"0.816519475\" fill=\"#FFFFFF\"></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\">\n      <title>Error</title>\n      <g stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n        <g 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\"></path>\n        </g>\n      </g>\n    </svg>\n  </div>\n</div>",
734
        // END OPTIONS
735
        // (Required by the dropzone documentation parser)
736
737
        /*
738
         Those functions register themselves to the events on init and handle all
739
         the user interface specific stuff. Overwriting them won't break the upload
740
         but can break the way it's displayed.
741
         You can overwrite them if you don't like the default behavior. If you just
742
         want to add an additional event handler, register it on the dropzone object
743
         and don't overwrite those options.
744
         */
745
        // Those are self explanatory and simply concern the DragnDrop.
746
        drop: function drop(e) {
747
          return this.element.classList.remove("dz-drag-hover");
748
        },
749
        dragstart: function dragstart(e) {},
750
        dragend: function dragend(e) {
751
          return this.element.classList.remove("dz-drag-hover");
752
        },
753
        dragenter: function dragenter(e) {
754
          return this.element.classList.add("dz-drag-hover");
755
        },
756
        dragover: function dragover(e) {
757
          return this.element.classList.add("dz-drag-hover");
758
        },
759
        dragleave: function dragleave(e) {
760
          return this.element.classList.remove("dz-drag-hover");
761
        },
762
        paste: function paste(e) {},
763
        // Called whenever there are no files left in the dropzone anymore, and the
764
        // dropzone should be displayed as if in the initial state.
765
        reset: function reset() {
766
          return this.element.classList.remove("dz-started");
767
        },
768
        // Called when a file is added to the queue
769
        // Receives `file`
770
        addedfile: function addedfile(file) {
771
          var _this2 = this;
772
773
          if (this.element === this.previewsContainer) {
774
            this.element.classList.add("dz-started");
775
          }
776
777
          if (this.previewsContainer) {
778
            file.previewElement = Dropzone.createElement(this.options.previewTemplate.trim());
779
            file.previewTemplate = file.previewElement; // Backwards compatibility
780
781
            this.previewsContainer.appendChild(file.previewElement);
782
            var _iteratorNormalCompletion3 = true;
783
            var _didIteratorError3 = false;
784
            var _iteratorError3 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError3 is implicitly marked as undefined by the declaration.
Loading history...
785
786
            try {
787
              for (var _iterator3 = file.previewElement.querySelectorAll("[data-dz-name]")[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
788
                var node = _step3.value;
789
                node.textContent = file.name;
790
              }
791
            } catch (err) {
792
              _didIteratorError3 = true;
793
              _iteratorError3 = err;
794
            } finally {
795
              try {
796
                if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
797
                  _iterator3["return"]();
798
                }
799
              } finally {
800
                if (_didIteratorError3) {
801
                  throw _iteratorError3;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
802
                }
803
              }
804
            }
805
806
            var _iteratorNormalCompletion4 = true;
807
            var _didIteratorError4 = false;
808
            var _iteratorError4 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError4 is implicitly marked as undefined by the declaration.
Loading history...
809
810
            try {
811
              for (var _iterator4 = file.previewElement.querySelectorAll("[data-dz-size]")[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
812
                node = _step4.value;
813
                node.innerHTML = this.filesize(file.size);
814
              }
815
            } catch (err) {
816
              _didIteratorError4 = true;
817
              _iteratorError4 = err;
818
            } finally {
819
              try {
820
                if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
821
                  _iterator4["return"]();
822
                }
823
              } finally {
824
                if (_didIteratorError4) {
825
                  throw _iteratorError4;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
826
                }
827
              }
828
            }
829
830
            if (this.options.addRemoveLinks) {
831
              file._removeLink = Dropzone.createElement("<a class=\"dz-remove\" href=\"javascript:undefined;\" data-dz-remove>".concat(this.options.dictRemoveFile, "</a>"));
832
              file.previewElement.appendChild(file._removeLink);
833
            }
834
835
            var removeFileEvent = function removeFileEvent(e) {
836
              e.preventDefault();
837
              e.stopPropagation();
838
839
              if (file.status === Dropzone.UPLOADING) {
840
                return Dropzone.confirm(_this2.options.dictCancelUploadConfirmation, function () {
841
                  return _this2.removeFile(file);
842
                });
843
              } else {
844
                if (_this2.options.dictRemoveFileConfirmation) {
845
                  return Dropzone.confirm(_this2.options.dictRemoveFileConfirmation, function () {
846
                    return _this2.removeFile(file);
847
                  });
848
                } else {
849
                  return _this2.removeFile(file);
850
                }
851
              }
852
            };
853
854
            var _iteratorNormalCompletion5 = true;
855
            var _didIteratorError5 = false;
856
            var _iteratorError5 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError5 is implicitly marked as undefined by the declaration.
Loading history...
857
858
            try {
859
              for (var _iterator5 = file.previewElement.querySelectorAll("[data-dz-remove]")[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
860
                var removeLink = _step5.value;
861
                removeLink.addEventListener("click", removeFileEvent);
862
              }
863
            } catch (err) {
864
              _didIteratorError5 = true;
865
              _iteratorError5 = err;
866
            } finally {
867
              try {
868
                if (!_iteratorNormalCompletion5 && _iterator5["return"] != null) {
869
                  _iterator5["return"]();
870
                }
871
              } finally {
872
                if (_didIteratorError5) {
873
                  throw _iteratorError5;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
874
                }
875
              }
876
            }
877
          }
878
        },
879
        // Called whenever a file is removed.
880
        removedfile: function removedfile(file) {
881
          if (file.previewElement != null && file.previewElement.parentNode != null) {
882
            file.previewElement.parentNode.removeChild(file.previewElement);
883
          }
884
885
          return this._updateMaxFilesReachedClass();
886
        },
887
        // Called when a thumbnail has been generated
888
        // Receives `file` and `dataUrl`
889
        thumbnail: function thumbnail(file, dataUrl) {
890
          if (file.previewElement) {
891
            file.previewElement.classList.remove("dz-file-preview");
892
            var _iteratorNormalCompletion6 = true;
893
            var _didIteratorError6 = false;
894
            var _iteratorError6 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError6 is implicitly marked as undefined by the declaration.
Loading history...
895
896
            try {
897
              for (var _iterator6 = file.previewElement.querySelectorAll("[data-dz-thumbnail]")[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
898
                var thumbnailElement = _step6.value;
899
                thumbnailElement.alt = file.name;
900
                thumbnailElement.src = dataUrl;
901
              }
902
            } catch (err) {
903
              _didIteratorError6 = true;
904
              _iteratorError6 = err;
905
            } finally {
906
              try {
907
                if (!_iteratorNormalCompletion6 && _iterator6["return"] != null) {
908
                  _iterator6["return"]();
909
                }
910
              } finally {
911
                if (_didIteratorError6) {
912
                  throw _iteratorError6;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
913
                }
914
              }
915
            }
916
917
            return setTimeout(function () {
918
              return file.previewElement.classList.add("dz-image-preview");
919
            }, 1);
920
          }
921
        },
922
        // Called whenever an error occurs
923
        // Receives `file` and `message`
924
        error: function error(file, message) {
925
          if (file.previewElement) {
926
            file.previewElement.classList.add("dz-error");
927
928
            if (typeof message !== "String" && message.error) {
929
              message = message.error;
930
            }
931
932
            var _iteratorNormalCompletion7 = true;
933
            var _didIteratorError7 = false;
934
            var _iteratorError7 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError7 is implicitly marked as undefined by the declaration.
Loading history...
935
936
            try {
937
              for (var _iterator7 = file.previewElement.querySelectorAll("[data-dz-errormessage]")[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
938
                var node = _step7.value;
939
                node.textContent = message;
940
              }
941
            } catch (err) {
942
              _didIteratorError7 = true;
943
              _iteratorError7 = err;
944
            } finally {
945
              try {
946
                if (!_iteratorNormalCompletion7 && _iterator7["return"] != null) {
947
                  _iterator7["return"]();
948
                }
949
              } finally {
950
                if (_didIteratorError7) {
951
                  throw _iteratorError7;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
952
                }
953
              }
954
            }
955
          }
956
        },
957
        errormultiple: function errormultiple() {},
958
        // Called when a file gets processed. Since there is a cue, not all added
959
        // files are processed immediately.
960
        // Receives `file`
961
        processing: function processing(file) {
962
          if (file.previewElement) {
963
            file.previewElement.classList.add("dz-processing");
964
965
            if (file._removeLink) {
966
              return file._removeLink.innerHTML = this.options.dictCancelUpload;
967
            }
968
          }
969
        },
970
        processingmultiple: function processingmultiple() {},
971
        // Called whenever the upload progress gets updated.
972
        // Receives `file`, `progress` (percentage 0-100) and `bytesSent`.
973
        // To get the total number of bytes of the file, use `file.size`
974
        uploadprogress: function uploadprogress(file, progress, bytesSent) {
975
          if (file.previewElement) {
976
            var _iteratorNormalCompletion8 = true;
977
            var _didIteratorError8 = false;
978
            var _iteratorError8 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError8 is implicitly marked as undefined by the declaration.
Loading history...
979
980
            try {
981
              for (var _iterator8 = file.previewElement.querySelectorAll("[data-dz-uploadprogress]")[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
982
                var node = _step8.value;
983
                node.nodeName === 'PROGRESS' ? node.value = progress : node.style.width = "".concat(progress, "%");
984
              }
985
            } catch (err) {
986
              _didIteratorError8 = true;
987
              _iteratorError8 = err;
988
            } finally {
989
              try {
990
                if (!_iteratorNormalCompletion8 && _iterator8["return"] != null) {
991
                  _iterator8["return"]();
992
                }
993
              } finally {
994
                if (_didIteratorError8) {
995
                  throw _iteratorError8;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
996
                }
997
              }
998
            }
999
          }
1000
        },
1001
        // Called whenever the total upload progress gets updated.
1002
        // Called with totalUploadProgress (0-100), totalBytes and totalBytesSent
1003
        totaluploadprogress: function totaluploadprogress() {},
1004
        // Called just before the file is sent. Gets the `xhr` object as second
1005
        // parameter, so you can modify it (for example to add a CSRF token) and a
1006
        // `formData` object to add additional information.
1007
        sending: function sending() {},
1008
        sendingmultiple: function sendingmultiple() {},
1009
        // When the complete upload is finished and successful
1010
        // Receives `file`
1011
        success: function success(file) {
1012
          if (file.previewElement) {
1013
            return file.previewElement.classList.add("dz-success");
1014
          }
1015
        },
1016
        successmultiple: function successmultiple() {},
1017
        // When the upload is canceled.
1018
        canceled: function canceled(file) {
1019
          return this.emit("error", file, this.options.dictUploadCanceled);
1020
        },
1021
        canceledmultiple: function canceledmultiple() {},
1022
        // When the upload is finished, either with success or an error.
1023
        // Receives `file`
1024
        complete: function complete(file) {
1025
          if (file._removeLink) {
1026
            file._removeLink.innerHTML = this.options.dictRemoveFile;
1027
          }
1028
1029
          if (file.previewElement) {
1030
            return file.previewElement.classList.add("dz-complete");
1031
          }
1032
        },
1033
        completemultiple: function completemultiple() {},
1034
        maxfilesexceeded: function maxfilesexceeded() {},
1035
        maxfilesreached: function maxfilesreached() {},
1036
        queuecomplete: function queuecomplete() {},
1037
        addedfiles: function addedfiles() {}
1038
      };
1039
      this.prototype._thumbnailQueue = [];
1040
      this.prototype._processingThumbnail = false;
1041
    } // global utility
1042
1043
  }, {
1044
    key: "extend",
1045
    value: function extend(target) {
1046
      for (var _len2 = arguments.length, objects = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
1047
        objects[_key2 - 1] = arguments[_key2];
1048
      }
1049
1050
      for (var _i = 0, _objects = objects; _i < _objects.length; _i++) {
1051
        var object = _objects[_i];
1052
1053
        for (var key in object) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
1054
          var val = object[key];
1055
          target[key] = val;
1056
        }
1057
      }
1058
1059
      return target;
1060
    }
1061
  }]);
1062
1063
  function Dropzone(el, options) {
1064
    var _this;
1065
1066
    _classCallCheck(this, Dropzone);
1067
1068
    _this = _possibleConstructorReturn(this, _getPrototypeOf(Dropzone).call(this));
1069
    var fallback, left;
1070
    _this.element = el; // For backwards compatibility since the version was in the prototype previously
1071
1072
    _this.version = Dropzone.version;
1073
    _this.defaultOptions.previewTemplate = _this.defaultOptions.previewTemplate.replace(/\n*/g, "");
1074
    _this.clickableElements = [];
1075
    _this.listeners = [];
1076
    _this.files = []; // All files
1077
1078
    if (typeof _this.element === "string") {
1079
      _this.element = document.querySelector(_this.element);
1080
    } // Not checking if instance of HTMLElement or Element since IE9 is extremely weird.
1081
1082
1083
    if (!_this.element || _this.element.nodeType == null) {
1084
      throw new Error("Invalid dropzone element.");
1085
    }
1086
1087
    if (_this.element.dropzone) {
1088
      throw new Error("Dropzone already attached.");
1089
    } // Now add this dropzone to the instances.
1090
1091
1092
    Dropzone.instances.push(_assertThisInitialized(_this)); // Put the dropzone inside the element itself.
1093
1094
    _this.element.dropzone = _assertThisInitialized(_this);
1095
    var elementOptions = (left = Dropzone.optionsForElement(_this.element)) != null ? left : {};
1096
    _this.options = Dropzone.extend({}, _this.defaultOptions, elementOptions, options != null ? options : {}); // If the browser failed, just call the fallback and leave
1097
1098
    if (_this.options.forceFallback || !Dropzone.isBrowserSupported()) {
1099
      return _possibleConstructorReturn(_this, _this.options.fallback.call(_assertThisInitialized(_this)));
1100
    } // @options.url = @element.getAttribute "action" unless @options.url?
1101
1102
1103
    if (_this.options.url == null) {
1104
      _this.options.url = _this.element.getAttribute("action");
1105
    }
1106
1107
    if (!_this.options.url) {
1108
      throw new Error("No URL provided.");
1109
    }
1110
1111
    if (_this.options.acceptedFiles && _this.options.acceptedMimeTypes) {
1112
      throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");
1113
    }
1114
1115
    if (_this.options.uploadMultiple && _this.options.chunking) {
1116
      throw new Error('You cannot set both: uploadMultiple and chunking.');
1117
    } // Backwards compatibility
1118
1119
1120
    if (_this.options.acceptedMimeTypes) {
1121
      _this.options.acceptedFiles = _this.options.acceptedMimeTypes;
1122
      delete _this.options.acceptedMimeTypes;
1123
    } // Backwards compatibility
1124
1125
1126
    if (_this.options.renameFilename != null) {
1127
      _this.options.renameFile = function (file) {
1128
        return _this.options.renameFilename.call(_assertThisInitialized(_this), file.name, file);
1129
      };
1130
    }
1131
1132
    _this.options.method = _this.options.method.toUpperCase();
1133
1134
    if ((fallback = _this.getExistingFallback()) && fallback.parentNode) {
1135
      // Remove the fallback
1136
      fallback.parentNode.removeChild(fallback);
1137
    } // Display previews in the previewsContainer element or the Dropzone element unless explicitly set to false
1138
1139
1140
    if (_this.options.previewsContainer !== false) {
1141
      if (_this.options.previewsContainer) {
1142
        _this.previewsContainer = Dropzone.getElement(_this.options.previewsContainer, "previewsContainer");
1143
      } else {
1144
        _this.previewsContainer = _this.element;
1145
      }
1146
    }
1147
1148
    if (_this.options.clickable) {
1149
      if (_this.options.clickable === true) {
1150
        _this.clickableElements = [_this.element];
1151
      } else {
1152
        _this.clickableElements = Dropzone.getElements(_this.options.clickable, "clickable");
1153
      }
1154
    }
1155
1156
    _this.init();
1157
1158
    return _this;
1159
  } // Returns all files that have been accepted
1160
1161
1162
  _createClass(Dropzone, [{
1163
    key: "getAcceptedFiles",
1164
    value: function getAcceptedFiles() {
1165
      return this.files.filter(function (file) {
1166
        return file.accepted;
1167
      }).map(function (file) {
1168
        return file;
1169
      });
1170
    } // Returns all files that have been rejected
1171
    // Not sure when that's going to be useful, but added for completeness.
1172
1173
  }, {
1174
    key: "getRejectedFiles",
1175
    value: function getRejectedFiles() {
1176
      return this.files.filter(function (file) {
1177
        return !file.accepted;
1178
      }).map(function (file) {
1179
        return file;
1180
      });
1181
    }
1182
  }, {
1183
    key: "getFilesWithStatus",
1184
    value: function getFilesWithStatus(status) {
1185
      return this.files.filter(function (file) {
1186
        return file.status === status;
1187
      }).map(function (file) {
1188
        return file;
1189
      });
1190
    } // Returns all files that are in the queue
1191
1192
  }, {
1193
    key: "getQueuedFiles",
1194
    value: function getQueuedFiles() {
1195
      return this.getFilesWithStatus(Dropzone.QUEUED);
1196
    }
1197
  }, {
1198
    key: "getUploadingFiles",
1199
    value: function getUploadingFiles() {
1200
      return this.getFilesWithStatus(Dropzone.UPLOADING);
1201
    }
1202
  }, {
1203
    key: "getAddedFiles",
1204
    value: function getAddedFiles() {
1205
      return this.getFilesWithStatus(Dropzone.ADDED);
1206
    } // Files that are either queued or uploading
1207
1208
  }, {
1209
    key: "getActiveFiles",
1210
    value: function getActiveFiles() {
1211
      return this.files.filter(function (file) {
1212
        return file.status === Dropzone.UPLOADING || file.status === Dropzone.QUEUED;
1213
      }).map(function (file) {
1214
        return file;
1215
      });
1216
    } // The function that gets called when Dropzone is initialized. You
1217
    // can (and should) setup event listeners inside this function.
1218
1219
  }, {
1220
    key: "init",
1221
    value: function init() {
1222
      var _this3 = this;
1223
1224
      // In case it isn't set already
1225
      if (this.element.tagName === "form") {
1226
        this.element.setAttribute("enctype", "multipart/form-data");
1227
      }
1228
1229
      if (this.element.classList.contains("dropzone") && !this.element.querySelector(".dz-message")) {
1230
        this.element.appendChild(Dropzone.createElement("<div class=\"dz-default dz-message\"><button class=\"dz-button\" type=\"button\">".concat(this.options.dictDefaultMessage, "</button></div>")));
1231
      }
1232
1233
      if (this.clickableElements.length) {
1234
        var setupHiddenFileInput = function setupHiddenFileInput() {
1235
          if (_this3.hiddenFileInput) {
1236
            _this3.hiddenFileInput.parentNode.removeChild(_this3.hiddenFileInput);
1237
          }
1238
1239
          _this3.hiddenFileInput = document.createElement("input");
1240
1241
          _this3.hiddenFileInput.setAttribute("type", "file");
1242
1243
          if (_this3.options.maxFiles === null || _this3.options.maxFiles > 1) {
1244
            _this3.hiddenFileInput.setAttribute("multiple", "multiple");
1245
          }
1246
1247
          _this3.hiddenFileInput.className = "dz-hidden-input";
1248
1249
          if (_this3.options.acceptedFiles !== null) {
1250
            _this3.hiddenFileInput.setAttribute("accept", _this3.options.acceptedFiles);
1251
          }
1252
1253
          if (_this3.options.capture !== null) {
1254
            _this3.hiddenFileInput.setAttribute("capture", _this3.options.capture);
1255
          } // Not setting `display="none"` because some browsers don't accept clicks
1256
          // on elements that aren't displayed.
1257
1258
1259
          _this3.hiddenFileInput.style.visibility = "hidden";
1260
          _this3.hiddenFileInput.style.position = "absolute";
1261
          _this3.hiddenFileInput.style.top = "0";
1262
          _this3.hiddenFileInput.style.left = "0";
1263
          _this3.hiddenFileInput.style.height = "0";
1264
          _this3.hiddenFileInput.style.width = "0";
1265
          Dropzone.getElement(_this3.options.hiddenInputContainer, 'hiddenInputContainer').appendChild(_this3.hiddenFileInput);
1266
          return _this3.hiddenFileInput.addEventListener("change", function () {
1267
            var files = _this3.hiddenFileInput.files;
1268
1269
            if (files.length) {
1270
              var _iteratorNormalCompletion9 = true;
1271
              var _didIteratorError9 = false;
1272
              var _iteratorError9 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError9 is implicitly marked as undefined by the declaration.
Loading history...
1273
1274
              try {
1275
                for (var _iterator9 = files[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
1276
                  var file = _step9.value;
1277
1278
                  _this3.addFile(file);
1279
                }
1280
              } catch (err) {
1281
                _didIteratorError9 = true;
1282
                _iteratorError9 = err;
1283
              } finally {
1284
                try {
1285
                  if (!_iteratorNormalCompletion9 && _iterator9["return"] != null) {
1286
                    _iterator9["return"]();
1287
                  }
1288
                } finally {
1289
                  if (_didIteratorError9) {
1290
                    throw _iteratorError9;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
1291
                  }
1292
                }
1293
              }
1294
            }
1295
1296
            _this3.emit("addedfiles", files);
1297
1298
            return setupHiddenFileInput();
1299
          });
1300
        };
1301
1302
        setupHiddenFileInput();
1303
      }
1304
1305
      this.URL = window.URL !== null ? window.URL : window.webkitURL; // Setup all event listeners on the Dropzone object itself.
1306
      // They're not in @setupEventListeners() because they shouldn't be removed
1307
      // again when the dropzone gets disabled.
1308
1309
      var _iteratorNormalCompletion10 = true;
1310
      var _didIteratorError10 = false;
1311
      var _iteratorError10 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError10 is implicitly marked as undefined by the declaration.
Loading history...
1312
1313
      try {
1314
        for (var _iterator10 = this.events[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
1315
          var eventName = _step10.value;
1316
          this.on(eventName, this.options[eventName]);
1317
        }
1318
      } catch (err) {
1319
        _didIteratorError10 = true;
1320
        _iteratorError10 = err;
1321
      } finally {
1322
        try {
1323
          if (!_iteratorNormalCompletion10 && _iterator10["return"] != null) {
1324
            _iterator10["return"]();
1325
          }
1326
        } finally {
1327
          if (_didIteratorError10) {
1328
            throw _iteratorError10;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
1329
          }
1330
        }
1331
      }
1332
1333
      this.on("uploadprogress", function () {
1334
        return _this3.updateTotalUploadProgress();
1335
      });
1336
      this.on("removedfile", function () {
1337
        return _this3.updateTotalUploadProgress();
1338
      });
1339
      this.on("canceled", function (file) {
1340
        return _this3.emit("complete", file);
1341
      }); // Emit a `queuecomplete` event if all files finished uploading.
1342
1343
      this.on("complete", function (file) {
1344
        if (_this3.getAddedFiles().length === 0 && _this3.getUploadingFiles().length === 0 && _this3.getQueuedFiles().length === 0) {
1345
          // This needs to be deferred so that `queuecomplete` really triggers after `complete`
1346
          return setTimeout(function () {
1347
            return _this3.emit("queuecomplete");
1348
          }, 0);
1349
        }
1350
      });
1351
1352
      var containsFiles = function containsFiles(e) {
1353
        return e.dataTransfer.types && e.dataTransfer.types.some(function (type) {
1354
          return type == "Files";
1355
        });
1356
      };
1357
1358
      var noPropagation = function noPropagation(e) {
1359
        // If there are no files, we don't want to stop
1360
        // propagation so we don't interfere with other
1361
        // drag and drop behaviour.
1362
        if (!containsFiles(e)) return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
1363
        e.stopPropagation();
1364
1365
        if (e.preventDefault) {
1366
          return e.preventDefault();
1367
        } else {
1368
          return e.returnValue = false;
1369
        }
1370
      }; // Create the listeners
1371
1372
1373
      this.listeners = [{
1374
        element: this.element,
1375
        events: {
1376
          "dragstart": function dragstart(e) {
1377
            return _this3.emit("dragstart", e);
1378
          },
1379
          "dragenter": function dragenter(e) {
1380
            noPropagation(e);
1381
            return _this3.emit("dragenter", e);
1382
          },
1383
          "dragover": function dragover(e) {
1384
            // Makes it possible to drag files from chrome's download bar
1385
            // http://stackoverflow.com/questions/19526430/drag-and-drop-file-uploads-from-chrome-downloads-bar
1386
            // Try is required to prevent bug in Internet Explorer 11 (SCRIPT65535 exception)
1387
            var efct;
1388
1389
            try {
1390
              efct = e.dataTransfer.effectAllowed;
1391
            } catch (error) {}
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
1392
1393
            e.dataTransfer.dropEffect = 'move' === efct || 'linkMove' === efct ? 'move' : 'copy';
1394
            noPropagation(e);
1395
            return _this3.emit("dragover", e);
1396
          },
1397
          "dragleave": function dragleave(e) {
1398
            return _this3.emit("dragleave", e);
1399
          },
1400
          "drop": function drop(e) {
1401
            noPropagation(e);
1402
            return _this3.drop(e);
1403
          },
1404
          "dragend": function dragend(e) {
1405
            return _this3.emit("dragend", e);
1406
          }
1407
        } // This is disabled right now, because the browsers don't implement it properly.
1408
        // "paste": (e) =>
1409
        //   noPropagation e
1410
        //   @paste e
1411
1412
      }];
1413
      this.clickableElements.forEach(function (clickableElement) {
1414
        return _this3.listeners.push({
1415
          element: clickableElement,
1416
          events: {
1417
            "click": function click(evt) {
1418
              // Only the actual dropzone or the message element should trigger file selection
1419
              if (clickableElement !== _this3.element || evt.target === _this3.element || Dropzone.elementInside(evt.target, _this3.element.querySelector(".dz-message"))) {
1420
                _this3.hiddenFileInput.click(); // Forward the click
1421
1422
              }
1423
1424
              return true;
1425
            }
1426
          }
1427
        });
1428
      });
1429
      this.enable();
1430
      return this.options.init.call(this);
1431
    } // Not fully tested yet
1432
1433
  }, {
1434
    key: "destroy",
1435
    value: function destroy() {
1436
      this.disable();
1437
      this.removeAllFiles(true);
1438
1439
      if (this.hiddenFileInput != null ? this.hiddenFileInput.parentNode : undefined) {
1440
        this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput);
1441
        this.hiddenFileInput = null;
1442
      }
1443
1444
      delete this.element.dropzone;
1445
      return Dropzone.instances.splice(Dropzone.instances.indexOf(this), 1);
1446
    }
1447
  }, {
1448
    key: "updateTotalUploadProgress",
1449
    value: function updateTotalUploadProgress() {
1450
      var totalUploadProgress;
1451
      var totalBytesSent = 0;
1452
      var totalBytes = 0;
1453
      var activeFiles = this.getActiveFiles();
1454
1455
      if (activeFiles.length) {
1456
        var _iteratorNormalCompletion11 = true;
1457
        var _didIteratorError11 = false;
1458
        var _iteratorError11 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError11 is implicitly marked as undefined by the declaration.
Loading history...
1459
1460
        try {
1461
          for (var _iterator11 = this.getActiveFiles()[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
1462
            var file = _step11.value;
1463
            totalBytesSent += file.upload.bytesSent;
1464
            totalBytes += file.upload.total;
1465
          }
1466
        } catch (err) {
1467
          _didIteratorError11 = true;
1468
          _iteratorError11 = err;
1469
        } finally {
1470
          try {
1471
            if (!_iteratorNormalCompletion11 && _iterator11["return"] != null) {
1472
              _iterator11["return"]();
1473
            }
1474
          } finally {
1475
            if (_didIteratorError11) {
1476
              throw _iteratorError11;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
1477
            }
1478
          }
1479
        }
1480
1481
        totalUploadProgress = 100 * totalBytesSent / totalBytes;
1482
      } else {
1483
        totalUploadProgress = 100;
1484
      }
1485
1486
      return this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent);
1487
    } // @options.paramName can be a function taking one parameter rather than a string.
1488
    // A parameter name for a file is obtained simply by calling this with an index number.
1489
1490
  }, {
1491
    key: "_getParamName",
1492
    value: function _getParamName(n) {
1493
      if (typeof this.options.paramName === "function") {
1494
        return this.options.paramName(n);
1495
      } else {
1496
        return "".concat(this.options.paramName).concat(this.options.uploadMultiple ? "[".concat(n, "]") : "");
1497
      }
1498
    } // If @options.renameFile is a function,
1499
    // the function will be used to rename the file.name before appending it to the formData
1500
1501
  }, {
1502
    key: "_renameFile",
1503
    value: function _renameFile(file) {
1504
      if (typeof this.options.renameFile !== "function") {
1505
        return file.name;
1506
      }
1507
1508
      return this.options.renameFile(file);
1509
    } // Returns a form that can be used as fallback if the browser does not support DragnDrop
1510
    //
1511
    // If the dropzone is already a form, only the input field and button are returned. Otherwise a complete form element is provided.
1512
    // This code has to pass in IE7 :(
1513
1514
  }, {
1515
    key: "getFallbackForm",
1516
    value: function getFallbackForm() {
1517
      var existingFallback, form;
1518
1519
      if (existingFallback = this.getExistingFallback()) {
1520
        return existingFallback;
1521
      }
1522
1523
      var fieldsString = "<div class=\"dz-fallback\">";
1524
1525
      if (this.options.dictFallbackText) {
1526
        fieldsString += "<p>".concat(this.options.dictFallbackText, "</p>");
1527
      }
1528
1529
      fieldsString += "<input type=\"file\" name=\"".concat(this._getParamName(0), "\" ").concat(this.options.uploadMultiple ? 'multiple="multiple"' : undefined, " /><input type=\"submit\" value=\"Upload!\"></div>");
1530
      var fields = Dropzone.createElement(fieldsString);
1531
1532
      if (this.element.tagName !== "FORM") {
1533
        form = Dropzone.createElement("<form action=\"".concat(this.options.url, "\" enctype=\"multipart/form-data\" method=\"").concat(this.options.method, "\"></form>"));
1534
        form.appendChild(fields);
1535
      } else {
1536
        // Make sure that the enctype and method attributes are set properly
1537
        this.element.setAttribute("enctype", "multipart/form-data");
1538
        this.element.setAttribute("method", this.options.method);
1539
      }
1540
1541
      return form != null ? form : fields;
0 ignored issues
show
Bug introduced by
The variable form seems to not be initialized for all possible execution paths.
Loading history...
1542
    } // Returns the fallback elements if they exist already
1543
    //
1544
    // This code has to pass in IE7 :(
1545
1546
  }, {
1547
    key: "getExistingFallback",
1548
    value: function getExistingFallback() {
1549
      var getFallback = function getFallback(elements) {
1550
        var _iteratorNormalCompletion12 = true;
1551
        var _didIteratorError12 = false;
1552
        var _iteratorError12 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError12 is implicitly marked as undefined by the declaration.
Loading history...
1553
1554
        try {
1555
          for (var _iterator12 = elements[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
1556
            var el = _step12.value;
1557
1558
            if (/(^| )fallback($| )/.test(el.className)) {
1559
              return el;
1560
            }
1561
          }
1562
        } catch (err) {
1563
          _didIteratorError12 = true;
1564
          _iteratorError12 = err;
1565
        } finally {
1566
          try {
1567
            if (!_iteratorNormalCompletion12 && _iterator12["return"] != null) {
1568
              _iterator12["return"]();
1569
            }
1570
          } finally {
1571
            if (_didIteratorError12) {
1572
              throw _iteratorError12;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
1573
            }
1574
          }
1575
        }
1576
      };
1577
1578
      for (var _i2 = 0, _arr = ["div", "form"]; _i2 < _arr.length; _i2++) {
1579
        var tagName = _arr[_i2];
1580
        var fallback;
1581
1582
        if (fallback = getFallback(this.element.getElementsByTagName(tagName))) {
1583
          return fallback;
1584
        }
1585
      }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
1586
    } // Activates all listeners stored in @listeners
1587
1588
  }, {
1589
    key: "setupEventListeners",
1590
    value: function setupEventListeners() {
1591
      return this.listeners.map(function (elementListeners) {
1592
        return function () {
1593
          var result = [];
1594
1595
          for (var event in elementListeners.events) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
1596
            var listener = elementListeners.events[event];
1597
            result.push(elementListeners.element.addEventListener(event, listener, false));
1598
          }
1599
1600
          return result;
1601
        }();
1602
      });
1603
    } // Deactivates all listeners stored in @listeners
1604
1605
  }, {
1606
    key: "removeEventListeners",
1607
    value: function removeEventListeners() {
1608
      return this.listeners.map(function (elementListeners) {
1609
        return function () {
1610
          var result = [];
1611
1612
          for (var event in elementListeners.events) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
1613
            var listener = elementListeners.events[event];
1614
            result.push(elementListeners.element.removeEventListener(event, listener, false));
1615
          }
1616
1617
          return result;
1618
        }();
1619
      });
1620
    } // Removes all event listeners and cancels all files in the queue or being processed.
1621
1622
  }, {
1623
    key: "disable",
1624
    value: function disable() {
1625
      var _this4 = this;
1626
1627
      this.clickableElements.forEach(function (element) {
1628
        return element.classList.remove("dz-clickable");
1629
      });
1630
      this.removeEventListeners();
1631
      this.disabled = true;
1632
      return this.files.map(function (file) {
1633
        return _this4.cancelUpload(file);
1634
      });
1635
    }
1636
  }, {
1637
    key: "enable",
1638
    value: function enable() {
1639
      delete this.disabled;
1640
      this.clickableElements.forEach(function (element) {
1641
        return element.classList.add("dz-clickable");
1642
      });
1643
      return this.setupEventListeners();
1644
    } // Returns a nicely formatted filesize
1645
1646
  }, {
1647
    key: "filesize",
1648
    value: function filesize(size) {
1649
      var selectedSize = 0;
1650
      var selectedUnit = "b";
1651
1652
      if (size > 0) {
1653
        var units = ['tb', 'gb', 'mb', 'kb', 'b'];
1654
1655
        for (var i = 0; i < units.length; i++) {
1656
          var unit = units[i];
1657
          var cutoff = Math.pow(this.options.filesizeBase, 4 - i) / 10;
1658
1659
          if (size >= cutoff) {
1660
            selectedSize = size / Math.pow(this.options.filesizeBase, 4 - i);
1661
            selectedUnit = unit;
1662
            break;
1663
          }
1664
        }
1665
1666
        selectedSize = Math.round(10 * selectedSize) / 10; // Cutting of digits
1667
      }
1668
1669
      return "<strong>".concat(selectedSize, "</strong> ").concat(this.options.dictFileSizeUnits[selectedUnit]);
1670
    } // Adds or removes the `dz-max-files-reached` class from the form.
1671
1672
  }, {
1673
    key: "_updateMaxFilesReachedClass",
1674
    value: function _updateMaxFilesReachedClass() {
1675
      if (this.options.maxFiles != null && this.getAcceptedFiles().length >= this.options.maxFiles) {
1676
        if (this.getAcceptedFiles().length === this.options.maxFiles) {
1677
          this.emit('maxfilesreached', this.files);
1678
        }
1679
1680
        return this.element.classList.add("dz-max-files-reached");
1681
      } else {
1682
        return this.element.classList.remove("dz-max-files-reached");
1683
      }
1684
    }
1685
  }, {
1686
    key: "drop",
1687
    value: function drop(e) {
1688
      if (!e.dataTransfer) {
1689
        return;
1690
      }
1691
1692
      this.emit("drop", e); // Convert the FileList to an Array
1693
      // This is necessary for IE11
1694
1695
      var files = [];
1696
1697
      for (var i = 0; i < e.dataTransfer.files.length; i++) {
1698
        files[i] = e.dataTransfer.files[i];
1699
      } // Even if it's a folder, files.length will contain the folders.
1700
1701
1702
      if (files.length) {
1703
        var items = e.dataTransfer.items;
1704
1705
        if (items && items.length && items[0].webkitGetAsEntry != null) {
1706
          // The browser supports dropping of folders, so handle items instead of files
1707
          this._addFilesFromItems(items);
1708
        } else {
1709
          this.handleFiles(files);
1710
        }
1711
      }
1712
1713
      this.emit("addedfiles", files);
1714
    }
1715
  }, {
1716
    key: "paste",
1717
    value: function paste(e) {
1718
      if (__guard__(e != null ? e.clipboardData : undefined, function (x) {
1719
        return x.items;
1720
      }) == null) {
1721
        return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
1722
      }
1723
1724
      this.emit("paste", e);
1725
      var items = e.clipboardData.items;
1726
1727
      if (items.length) {
1728
        return this._addFilesFromItems(items);
1729
      }
1730
    }
1731
  }, {
1732
    key: "handleFiles",
1733
    value: function handleFiles(files) {
1734
      var _iteratorNormalCompletion13 = true;
1735
      var _didIteratorError13 = false;
1736
      var _iteratorError13 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError13 is implicitly marked as undefined by the declaration.
Loading history...
1737
1738
      try {
1739
        for (var _iterator13 = files[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
1740
          var file = _step13.value;
1741
          this.addFile(file);
1742
        }
1743
      } catch (err) {
1744
        _didIteratorError13 = true;
1745
        _iteratorError13 = err;
1746
      } finally {
1747
        try {
1748
          if (!_iteratorNormalCompletion13 && _iterator13["return"] != null) {
1749
            _iterator13["return"]();
1750
          }
1751
        } finally {
1752
          if (_didIteratorError13) {
1753
            throw _iteratorError13;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
1754
          }
1755
        }
1756
      }
1757
    } // When a folder is dropped (or files are pasted), items must be handled
1758
    // instead of files.
1759
1760
  }, {
1761
    key: "_addFilesFromItems",
1762
    value: function _addFilesFromItems(items) {
1763
      var _this5 = this;
1764
1765
      return function () {
1766
        var result = [];
1767
        var _iteratorNormalCompletion14 = true;
1768
        var _didIteratorError14 = false;
1769
        var _iteratorError14 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError14 is implicitly marked as undefined by the declaration.
Loading history...
1770
1771
        try {
1772
          for (var _iterator14 = items[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) {
1773
            var item = _step14.value;
1774
            var entry;
1775
1776
            if (item.webkitGetAsEntry != null && (entry = item.webkitGetAsEntry())) {
1777
              if (entry.isFile) {
1778
                result.push(_this5.addFile(item.getAsFile()));
1779
              } else if (entry.isDirectory) {
1780
                // Append all files from that directory to files
1781
                result.push(_this5._addFilesFromDirectory(entry, entry.name));
1782
              } else {
1783
                result.push(undefined);
1784
              }
1785
            } else if (item.getAsFile != null) {
1786
              if (item.kind == null || item.kind === "file") {
1787
                result.push(_this5.addFile(item.getAsFile()));
1788
              } else {
1789
                result.push(undefined);
1790
              }
1791
            } else {
1792
              result.push(undefined);
1793
            }
1794
          }
1795
        } catch (err) {
1796
          _didIteratorError14 = true;
1797
          _iteratorError14 = err;
1798
        } finally {
1799
          try {
1800
            if (!_iteratorNormalCompletion14 && _iterator14["return"] != null) {
1801
              _iterator14["return"]();
1802
            }
1803
          } finally {
1804
            if (_didIteratorError14) {
1805
              throw _iteratorError14;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
1806
            }
1807
          }
1808
        }
1809
1810
        return result;
1811
      }();
1812
    } // Goes through the directory, and adds each file it finds recursively
1813
1814
  }, {
1815
    key: "_addFilesFromDirectory",
1816
    value: function _addFilesFromDirectory(directory, path) {
1817
      var _this6 = this;
1818
1819
      var dirReader = directory.createReader();
1820
1821
      var errorHandler = function errorHandler(error) {
1822
        return __guardMethod__(console, 'log', function (o) {
1823
          return o.log(error);
1824
        });
1825
      };
1826
1827
      var readEntries = function readEntries() {
1828
        return dirReader.readEntries(function (entries) {
1829
          if (entries.length > 0) {
1830
            var _iteratorNormalCompletion15 = true;
1831
            var _didIteratorError15 = false;
1832
            var _iteratorError15 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError15 is implicitly marked as undefined by the declaration.
Loading history...
1833
1834
            try {
1835
              for (var _iterator15 = entries[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) {
1836
                var entry = _step15.value;
1837
1838
                if (entry.isFile) {
1839
                  entry.file(function (file) {
1840
                    if (_this6.options.ignoreHiddenFiles && file.name.substring(0, 1) === '.') {
1841
                      return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
1842
                    }
1843
1844
                    file.fullPath = "".concat(path, "/").concat(file.name);
1845
                    return _this6.addFile(file);
1846
                  });
1847
                } else if (entry.isDirectory) {
1848
                  _this6._addFilesFromDirectory(entry, "".concat(path, "/").concat(entry.name));
1849
                }
1850
              } // Recursively call readEntries() again, since browser only handle
1851
              // the first 100 entries.
1852
              // See: https://developer.mozilla.org/en-US/docs/Web/API/DirectoryReader#readEntries
1853
1854
            } catch (err) {
1855
              _didIteratorError15 = true;
1856
              _iteratorError15 = err;
1857
            } finally {
1858
              try {
1859
                if (!_iteratorNormalCompletion15 && _iterator15["return"] != null) {
1860
                  _iterator15["return"]();
1861
                }
1862
              } finally {
1863
                if (_didIteratorError15) {
1864
                  throw _iteratorError15;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
1865
                }
1866
              }
1867
            }
1868
1869
            readEntries();
1870
          }
1871
1872
          return null;
1873
        }, errorHandler);
1874
      };
1875
1876
      return readEntries();
1877
    } // If `done()` is called without argument the file is accepted
1878
    // If you call it with an error message, the file is rejected
1879
    // (This allows for asynchronous validation)
1880
    //
1881
    // This function checks the filesize, and if the file.type passes the
1882
    // `acceptedFiles` check.
1883
1884
  }, {
1885
    key: "accept",
1886
    value: function accept(file, done) {
1887
      if (this.options.maxFilesize && file.size > this.options.maxFilesize * 1024 * 1024) {
1888
        done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize));
1889
      } else if (!Dropzone.isValidFile(file, this.options.acceptedFiles)) {
1890
        done(this.options.dictInvalidFileType);
1891
      } else if (this.options.maxFiles != null && this.getAcceptedFiles().length >= this.options.maxFiles) {
1892
        done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}", this.options.maxFiles));
1893
        this.emit("maxfilesexceeded", file);
1894
      } else {
1895
        this.options.accept.call(this, file, done);
1896
      }
1897
    }
1898
  }, {
1899
    key: "addFile",
1900
    value: function addFile(file) {
1901
      var _this7 = this;
1902
1903
      file.upload = {
1904
        uuid: Dropzone.uuidv4(),
1905
        progress: 0,
1906
        // Setting the total upload size to file.size for the beginning
1907
        // It's actual different than the size to be transmitted.
1908
        total: file.size,
1909
        bytesSent: 0,
1910
        filename: this._renameFile(file) // Not setting chunking information here, because the acutal data — and
1911
        // thus the chunks — might change if `options.transformFile` is set
1912
        // and does something to the data.
1913
1914
      };
1915
      this.files.push(file);
1916
      file.status = Dropzone.ADDED;
1917
      this.emit("addedfile", file);
1918
1919
      this._enqueueThumbnail(file);
1920
1921
      this.accept(file, function (error) {
1922
        if (error) {
1923
          file.accepted = false;
1924
1925
          _this7._errorProcessing([file], error); // Will set the file.status
1926
1927
        } else {
1928
          file.accepted = true;
1929
1930
          if (_this7.options.autoQueue) {
1931
            _this7.enqueueFile(file);
1932
          } // Will set .accepted = true
1933
1934
        }
1935
1936
        _this7._updateMaxFilesReachedClass();
1937
      });
1938
    } // Wrapper for enqueueFile
1939
1940
  }, {
1941
    key: "enqueueFiles",
1942
    value: function enqueueFiles(files) {
1943
      var _iteratorNormalCompletion16 = true;
1944
      var _didIteratorError16 = false;
1945
      var _iteratorError16 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError16 is implicitly marked as undefined by the declaration.
Loading history...
1946
1947
      try {
1948
        for (var _iterator16 = files[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) {
1949
          var file = _step16.value;
1950
          this.enqueueFile(file);
1951
        }
1952
      } catch (err) {
1953
        _didIteratorError16 = true;
1954
        _iteratorError16 = err;
1955
      } finally {
1956
        try {
1957
          if (!_iteratorNormalCompletion16 && _iterator16["return"] != null) {
1958
            _iterator16["return"]();
1959
          }
1960
        } finally {
1961
          if (_didIteratorError16) {
1962
            throw _iteratorError16;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
1963
          }
1964
        }
1965
      }
1966
1967
      return null;
1968
    }
1969
  }, {
1970
    key: "enqueueFile",
1971
    value: function enqueueFile(file) {
1972
      var _this8 = this;
1973
1974
      if (file.status === Dropzone.ADDED && file.accepted === true) {
1975
        file.status = Dropzone.QUEUED;
1976
1977
        if (this.options.autoProcessQueue) {
1978
          return setTimeout(function () {
1979
            return _this8.processQueue();
1980
          }, 0); // Deferring the call
1981
        }
1982
      } else {
1983
        throw new Error("This file can't be queued because it has already been processed or was rejected.");
1984
      }
1985
    }
1986
  }, {
1987
    key: "_enqueueThumbnail",
1988
    value: function _enqueueThumbnail(file) {
1989
      var _this9 = this;
1990
1991
      if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) {
1992
        this._thumbnailQueue.push(file);
1993
1994
        return setTimeout(function () {
1995
          return _this9._processThumbnailQueue();
1996
        }, 0); // Deferring the call
1997
      }
1998
    }
1999
  }, {
2000
    key: "_processThumbnailQueue",
2001
    value: function _processThumbnailQueue() {
2002
      var _this10 = this;
2003
2004
      if (this._processingThumbnail || this._thumbnailQueue.length === 0) {
2005
        return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
2006
      }
2007
2008
      this._processingThumbnail = true;
2009
2010
      var file = this._thumbnailQueue.shift();
2011
2012
      return this.createThumbnail(file, this.options.thumbnailWidth, this.options.thumbnailHeight, this.options.thumbnailMethod, true, function (dataUrl) {
2013
        _this10.emit("thumbnail", file, dataUrl);
2014
2015
        _this10._processingThumbnail = false;
2016
        return _this10._processThumbnailQueue();
2017
      });
2018
    } // Can be called by the user to remove a file
2019
2020
  }, {
2021
    key: "removeFile",
2022
    value: function removeFile(file) {
2023
      if (file.status === Dropzone.UPLOADING) {
2024
        this.cancelUpload(file);
2025
      }
2026
2027
      this.files = without(this.files, file);
2028
      this.emit("removedfile", file);
2029
2030
      if (this.files.length === 0) {
2031
        return this.emit("reset");
2032
      }
2033
    } // Removes all files that aren't currently processed from the list
2034
2035
  }, {
2036
    key: "removeAllFiles",
2037
    value: function removeAllFiles(cancelIfNecessary) {
2038
      // Create a copy of files since removeFile() changes the @files array.
2039
      if (cancelIfNecessary == null) {
2040
        cancelIfNecessary = false;
2041
      }
2042
2043
      var _iteratorNormalCompletion17 = true;
2044
      var _didIteratorError17 = false;
2045
      var _iteratorError17 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError17 is implicitly marked as undefined by the declaration.
Loading history...
2046
2047
      try {
2048
        for (var _iterator17 = this.files.slice()[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) {
2049
          var file = _step17.value;
2050
2051
          if (file.status !== Dropzone.UPLOADING || cancelIfNecessary) {
2052
            this.removeFile(file);
2053
          }
2054
        }
2055
      } catch (err) {
2056
        _didIteratorError17 = true;
2057
        _iteratorError17 = err;
2058
      } finally {
2059
        try {
2060
          if (!_iteratorNormalCompletion17 && _iterator17["return"] != null) {
2061
            _iterator17["return"]();
2062
          }
2063
        } finally {
2064
          if (_didIteratorError17) {
2065
            throw _iteratorError17;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2066
          }
2067
        }
2068
      }
2069
2070
      return null;
2071
    } // Resizes an image before it gets sent to the server. This function is the default behavior of
2072
    // `options.transformFile` if `resizeWidth` or `resizeHeight` are set. The callback is invoked with
2073
    // the resized blob.
2074
2075
  }, {
2076
    key: "resizeImage",
2077
    value: function resizeImage(file, width, height, resizeMethod, callback) {
2078
      var _this11 = this;
2079
2080
      return this.createThumbnail(file, width, height, resizeMethod, true, function (dataUrl, canvas) {
2081
        if (canvas == null) {
2082
          // The image has not been resized
2083
          return callback(file);
2084
        } else {
2085
          var resizeMimeType = _this11.options.resizeMimeType;
2086
2087
          if (resizeMimeType == null) {
2088
            resizeMimeType = file.type;
2089
          }
2090
2091
          var resizedDataURL = canvas.toDataURL(resizeMimeType, _this11.options.resizeQuality);
2092
2093
          if (resizeMimeType === 'image/jpeg' || resizeMimeType === 'image/jpg') {
2094
            // Now add the original EXIF information
2095
            resizedDataURL = ExifRestore.restore(file.dataURL, resizedDataURL);
2096
          }
2097
2098
          return callback(Dropzone.dataURItoBlob(resizedDataURL));
2099
        }
2100
      });
2101
    }
2102
  }, {
2103
    key: "createThumbnail",
2104
    value: function createThumbnail(file, width, height, resizeMethod, fixOrientation, callback) {
2105
      var _this12 = this;
2106
2107
      var fileReader = new FileReader();
2108
2109
      fileReader.onload = function () {
2110
        file.dataURL = fileReader.result; // Don't bother creating a thumbnail for SVG images since they're vector
2111
2112
        if (file.type === "image/svg+xml") {
2113
          if (callback != null) {
2114
            callback(fileReader.result);
2115
          }
2116
2117
          return;
2118
        }
2119
2120
        _this12.createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback);
2121
      };
2122
2123
      fileReader.readAsDataURL(file);
2124
    } // `mockFile` needs to have these attributes:
2125
    // 
2126
    //     { name: 'name', size: 12345, imageUrl: '' }
2127
    //
2128
    // `callback` will be invoked when the image has been downloaded and displayed.
2129
    // `crossOrigin` will be added to the `img` tag when accessing the file.
2130
2131
  }, {
2132
    key: "displayExistingFile",
2133
    value: function displayExistingFile(mockFile, imageUrl, callback, crossOrigin) {
2134
      var _this13 = this;
2135
2136
      var resizeThumbnail = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
2137
      this.emit("addedfile", mockFile);
2138
      this.emit("complete", mockFile);
2139
2140
      if (!resizeThumbnail) {
2141
        this.emit("thumbnail", mockFile, imageUrl);
2142
        if (callback) callback();
2143
      } else {
2144
        var onDone = function onDone(thumbnail) {
2145
          _this13.emit('thumbnail', mockFile, thumbnail);
2146
2147
          if (callback) callback();
2148
        };
2149
2150
        mockFile.dataURL = imageUrl;
2151
        this.createThumbnailFromUrl(mockFile, this.options.thumbnailWidth, this.options.thumbnailHeight, this.options.resizeMethod, this.options.fixOrientation, onDone, crossOrigin);
2152
      }
2153
    }
2154
  }, {
2155
    key: "createThumbnailFromUrl",
2156
    value: function createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback, crossOrigin) {
2157
      var _this14 = this;
2158
2159
      // Not using `new Image` here because of a bug in latest Chrome versions.
2160
      // See https://github.com/enyo/dropzone/pull/226
2161
      var img = document.createElement("img");
2162
2163
      if (crossOrigin) {
2164
        img.crossOrigin = crossOrigin;
2165
      }
2166
2167
      img.onload = function () {
2168
        var loadExif = function loadExif(callback) {
2169
          return callback(1);
2170
        };
2171
2172
        if (typeof EXIF !== 'undefined' && EXIF !== null && fixOrientation) {
2173
          loadExif = function loadExif(callback) {
2174
            return EXIF.getData(img, function () {
2175
              return callback(EXIF.getTag(this, 'Orientation'));
2176
            });
2177
          };
2178
        }
2179
2180
        return loadExif(function (orientation) {
2181
          file.width = img.width;
2182
          file.height = img.height;
2183
2184
          var resizeInfo = _this14.options.resize.call(_this14, file, width, height, resizeMethod);
2185
2186
          var canvas = document.createElement("canvas");
2187
          var ctx = canvas.getContext("2d");
2188
          canvas.width = resizeInfo.trgWidth;
2189
          canvas.height = resizeInfo.trgHeight;
2190
2191
          if (orientation > 4) {
2192
            canvas.width = resizeInfo.trgHeight;
2193
            canvas.height = resizeInfo.trgWidth;
2194
          }
2195
2196
          switch (orientation) {
2197
            case 2:
2198
              // horizontal flip
2199
              ctx.translate(canvas.width, 0);
2200
              ctx.scale(-1, 1);
2201
              break;
2202
2203
            case 3:
2204
              // 180° rotate left
2205
              ctx.translate(canvas.width, canvas.height);
2206
              ctx.rotate(Math.PI);
2207
              break;
2208
2209
            case 4:
2210
              // vertical flip
2211
              ctx.translate(0, canvas.height);
2212
              ctx.scale(1, -1);
2213
              break;
2214
2215
            case 5:
2216
              // vertical flip + 90 rotate right
2217
              ctx.rotate(0.5 * Math.PI);
2218
              ctx.scale(1, -1);
2219
              break;
2220
2221
            case 6:
2222
              // 90° rotate right
2223
              ctx.rotate(0.5 * Math.PI);
2224
              ctx.translate(0, -canvas.width);
2225
              break;
2226
2227
            case 7:
2228
              // horizontal flip + 90 rotate right
2229
              ctx.rotate(0.5 * Math.PI);
2230
              ctx.translate(canvas.height, -canvas.width);
2231
              ctx.scale(-1, 1);
2232
              break;
2233
2234
            case 8:
2235
              // 90° rotate left
2236
              ctx.rotate(-0.5 * Math.PI);
2237
              ctx.translate(-canvas.height, 0);
2238
              break;
2239
          } // This is a bugfix for iOS' scaling bug.
2240
2241
2242
          drawImageIOSFix(ctx, img, resizeInfo.srcX != null ? resizeInfo.srcX : 0, resizeInfo.srcY != null ? resizeInfo.srcY : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, resizeInfo.trgX != null ? resizeInfo.trgX : 0, resizeInfo.trgY != null ? resizeInfo.trgY : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
2243
          var thumbnail = canvas.toDataURL("image/png");
2244
2245
          if (callback != null) {
2246
            return callback(thumbnail, canvas);
2247
          }
2248
        });
2249
      };
2250
2251
      if (callback != null) {
2252
        img.onerror = callback;
2253
      }
2254
2255
      return img.src = file.dataURL;
2256
    } // Goes through the queue and processes files if there aren't too many already.
2257
2258
  }, {
2259
    key: "processQueue",
2260
    value: function processQueue() {
2261
      var parallelUploads = this.options.parallelUploads;
2262
      var processingLength = this.getUploadingFiles().length;
2263
      var i = processingLength; // There are already at least as many files uploading than should be
2264
2265
      if (processingLength >= parallelUploads) {
2266
        return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
2267
      }
2268
2269
      var queuedFiles = this.getQueuedFiles();
2270
2271
      if (!(queuedFiles.length > 0)) {
2272
        return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
2273
      }
2274
2275
      if (this.options.uploadMultiple) {
2276
        // The files should be uploaded in one request
2277
        return this.processFiles(queuedFiles.slice(0, parallelUploads - processingLength));
2278
      } else {
2279
        while (i < parallelUploads) {
2280
          if (!queuedFiles.length) {
2281
            return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
2282
          } // Nothing left to process
2283
2284
2285
          this.processFile(queuedFiles.shift());
2286
          i++;
2287
        }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
2288
      }
2289
    } // Wrapper for `processFiles`
2290
2291
  }, {
2292
    key: "processFile",
2293
    value: function processFile(file) {
2294
      return this.processFiles([file]);
2295
    } // Loads the file, then calls finishedLoading()
2296
2297
  }, {
2298
    key: "processFiles",
2299
    value: function processFiles(files) {
2300
      var _iteratorNormalCompletion18 = true;
2301
      var _didIteratorError18 = false;
2302
      var _iteratorError18 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError18 is implicitly marked as undefined by the declaration.
Loading history...
2303
2304
      try {
2305
        for (var _iterator18 = files[Symbol.iterator](), _step18; !(_iteratorNormalCompletion18 = (_step18 = _iterator18.next()).done); _iteratorNormalCompletion18 = true) {
2306
          var file = _step18.value;
2307
          file.processing = true; // Backwards compatibility
2308
2309
          file.status = Dropzone.UPLOADING;
2310
          this.emit("processing", file);
2311
        }
2312
      } catch (err) {
2313
        _didIteratorError18 = true;
2314
        _iteratorError18 = err;
2315
      } finally {
2316
        try {
2317
          if (!_iteratorNormalCompletion18 && _iterator18["return"] != null) {
2318
            _iterator18["return"]();
2319
          }
2320
        } finally {
2321
          if (_didIteratorError18) {
2322
            throw _iteratorError18;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2323
          }
2324
        }
2325
      }
2326
2327
      if (this.options.uploadMultiple) {
2328
        this.emit("processingmultiple", files);
2329
      }
2330
2331
      return this.uploadFiles(files);
2332
    }
2333
  }, {
2334
    key: "_getFilesWithXhr",
2335
    value: function _getFilesWithXhr(xhr) {
2336
      var files;
2337
      return files = this.files.filter(function (file) {
0 ignored issues
show
Unused Code introduced by
The assignment to variable files seems to be never used. Consider removing it.
Loading history...
Comprehensibility introduced by
Are you sure you want to assign to files here, or did you intend to make a comparison like files === this.files.fil...aram) { return file; })?
Loading history...
2338
        return file.xhr === xhr;
2339
      }).map(function (file) {
2340
        return file;
2341
      });
2342
    } // Cancels the file upload and sets the status to CANCELED
2343
    // **if** the file is actually being uploaded.
2344
    // If it's still in the queue, the file is being removed from it and the status
2345
    // set to CANCELED.
2346
2347
  }, {
2348
    key: "cancelUpload",
2349
    value: function cancelUpload(file) {
2350
      if (file.status === Dropzone.UPLOADING) {
2351
        var groupedFiles = this._getFilesWithXhr(file.xhr);
2352
2353
        var _iteratorNormalCompletion19 = true;
2354
        var _didIteratorError19 = false;
2355
        var _iteratorError19 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError19 is implicitly marked as undefined by the declaration.
Loading history...
2356
2357
        try {
2358
          for (var _iterator19 = groupedFiles[Symbol.iterator](), _step19; !(_iteratorNormalCompletion19 = (_step19 = _iterator19.next()).done); _iteratorNormalCompletion19 = true) {
2359
            var groupedFile = _step19.value;
2360
            groupedFile.status = Dropzone.CANCELED;
2361
          }
2362
        } catch (err) {
2363
          _didIteratorError19 = true;
2364
          _iteratorError19 = err;
2365
        } finally {
2366
          try {
2367
            if (!_iteratorNormalCompletion19 && _iterator19["return"] != null) {
2368
              _iterator19["return"]();
2369
            }
2370
          } finally {
2371
            if (_didIteratorError19) {
2372
              throw _iteratorError19;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2373
            }
2374
          }
2375
        }
2376
2377
        if (typeof file.xhr !== 'undefined') {
2378
          file.xhr.abort();
2379
        }
2380
2381
        var _iteratorNormalCompletion20 = true;
2382
        var _didIteratorError20 = false;
2383
        var _iteratorError20 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError20 is implicitly marked as undefined by the declaration.
Loading history...
2384
2385
        try {
2386
          for (var _iterator20 = groupedFiles[Symbol.iterator](), _step20; !(_iteratorNormalCompletion20 = (_step20 = _iterator20.next()).done); _iteratorNormalCompletion20 = true) {
2387
            var _groupedFile = _step20.value;
2388
            this.emit("canceled", _groupedFile);
2389
          }
2390
        } catch (err) {
2391
          _didIteratorError20 = true;
2392
          _iteratorError20 = err;
2393
        } finally {
2394
          try {
2395
            if (!_iteratorNormalCompletion20 && _iterator20["return"] != null) {
2396
              _iterator20["return"]();
2397
            }
2398
          } finally {
2399
            if (_didIteratorError20) {
2400
              throw _iteratorError20;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2401
            }
2402
          }
2403
        }
2404
2405
        if (this.options.uploadMultiple) {
2406
          this.emit("canceledmultiple", groupedFiles);
2407
        }
2408
      } else if (file.status === Dropzone.ADDED || file.status === Dropzone.QUEUED) {
2409
        file.status = Dropzone.CANCELED;
2410
        this.emit("canceled", file);
2411
2412
        if (this.options.uploadMultiple) {
2413
          this.emit("canceledmultiple", [file]);
2414
        }
2415
      }
2416
2417
      if (this.options.autoProcessQueue) {
2418
        return this.processQueue();
2419
      }
2420
    }
2421
  }, {
2422
    key: "resolveOption",
2423
    value: function resolveOption(option) {
2424
      if (typeof option === 'function') {
2425
        for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
2426
          args[_key3 - 1] = arguments[_key3];
2427
        }
2428
2429
        return option.apply(this, args);
2430
      }
2431
2432
      return option;
2433
    }
2434
  }, {
2435
    key: "uploadFile",
2436
    value: function uploadFile(file) {
2437
      return this.uploadFiles([file]);
2438
    }
2439
  }, {
2440
    key: "uploadFiles",
2441
    value: function uploadFiles(files) {
2442
      var _this15 = this;
2443
2444
      this._transformFiles(files, function (transformedFiles) {
2445
        if (_this15.options.chunking) {
2446
          // Chunking is not allowed to be used with `uploadMultiple` so we know
2447
          // that there is only __one__file.
2448
          var transformedFile = transformedFiles[0];
2449
          files[0].upload.chunked = _this15.options.chunking && (_this15.options.forceChunking || transformedFile.size > _this15.options.chunkSize);
2450
          files[0].upload.totalChunkCount = Math.ceil(transformedFile.size / _this15.options.chunkSize);
2451
        }
2452
2453
        if (files[0].upload.chunked) {
2454
          // This file should be sent in chunks!
2455
          // If the chunking option is set, we **know** that there can only be **one** file, since
2456
          // uploadMultiple is not allowed with this option.
2457
          var file = files[0];
2458
          var _transformedFile = transformedFiles[0];
2459
          var startedChunkCount = 0;
2460
          file.upload.chunks = [];
2461
2462
          var handleNextChunk = function handleNextChunk() {
2463
            var chunkIndex = 0; // Find the next item in file.upload.chunks that is not defined yet.
2464
2465
            while (file.upload.chunks[chunkIndex] !== undefined) {
2466
              chunkIndex++;
2467
            } // This means, that all chunks have already been started.
2468
2469
2470
            if (chunkIndex >= file.upload.totalChunkCount) return;
2471
            startedChunkCount++;
2472
            var start = chunkIndex * _this15.options.chunkSize;
2473
            var end = Math.min(start + _this15.options.chunkSize, file.size);
2474
            var dataBlock = {
2475
              name: _this15._getParamName(0),
2476
              data: _transformedFile.webkitSlice ? _transformedFile.webkitSlice(start, end) : _transformedFile.slice(start, end),
2477
              filename: file.upload.filename,
2478
              chunkIndex: chunkIndex
2479
            };
2480
            file.upload.chunks[chunkIndex] = {
2481
              file: file,
2482
              index: chunkIndex,
2483
              dataBlock: dataBlock,
2484
              // In case we want to retry.
2485
              status: Dropzone.UPLOADING,
2486
              progress: 0,
2487
              retries: 0 // The number of times this block has been retried.
2488
2489
            };
2490
2491
            _this15._uploadData(files, [dataBlock]);
2492
          };
2493
2494
          file.upload.finishedChunkUpload = function (chunk) {
2495
            var allFinished = true;
2496
            chunk.status = Dropzone.SUCCESS; // Clear the data from the chunk
2497
2498
            chunk.dataBlock = null; // Leaving this reference to xhr intact here will cause memory leaks in some browsers
2499
2500
            chunk.xhr = null;
2501
2502
            for (var i = 0; i < file.upload.totalChunkCount; i++) {
2503
              if (file.upload.chunks[i] === undefined) {
2504
                return handleNextChunk();
2505
              }
2506
2507
              if (file.upload.chunks[i].status !== Dropzone.SUCCESS) {
2508
                allFinished = false;
2509
              }
2510
            }
2511
2512
            if (allFinished) {
2513
              _this15.options.chunksUploaded(file, function () {
2514
                _this15._finished(files, '', null);
2515
              });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
2516
            }
2517
          };
2518
2519
          if (_this15.options.parallelChunkUploads) {
2520
            for (var i = 0; i < file.upload.totalChunkCount; i++) {
2521
              handleNextChunk();
2522
            }
2523
          } else {
2524
            handleNextChunk();
2525
          }
2526
        } else {
2527
          var dataBlocks = [];
2528
2529
          for (var _i3 = 0; _i3 < files.length; _i3++) {
2530
            dataBlocks[_i3] = {
2531
              name: _this15._getParamName(_i3),
2532
              data: transformedFiles[_i3],
2533
              filename: files[_i3].upload.filename
2534
            };
2535
          }
2536
2537
          _this15._uploadData(files, dataBlocks);
2538
        }
2539
      });
2540
    } /// Returns the right chunk for given file and xhr
2541
2542
  }, {
2543
    key: "_getChunk",
2544
    value: function _getChunk(file, xhr) {
2545
      for (var i = 0; i < file.upload.totalChunkCount; i++) {
2546
        if (file.upload.chunks[i] !== undefined && file.upload.chunks[i].xhr === xhr) {
2547
          return file.upload.chunks[i];
2548
        }
2549
      }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
2550
    } // This function actually uploads the file(s) to the server.
2551
    // If dataBlocks contains the actual data to upload (meaning, that this could either be transformed
2552
    // files, or individual chunks for chunked upload).
2553
2554
  }, {
2555
    key: "_uploadData",
2556
    value: function _uploadData(files, dataBlocks) {
2557
      var _this16 = this;
2558
2559
      var xhr = new XMLHttpRequest(); // Put the xhr object in the file objects to be able to reference it later.
2560
2561
      var _iteratorNormalCompletion21 = true;
2562
      var _didIteratorError21 = false;
2563
      var _iteratorError21 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError21 is implicitly marked as undefined by the declaration.
Loading history...
2564
2565
      try {
2566
        for (var _iterator21 = files[Symbol.iterator](), _step21; !(_iteratorNormalCompletion21 = (_step21 = _iterator21.next()).done); _iteratorNormalCompletion21 = true) {
2567
          var file = _step21.value;
2568
          file.xhr = xhr;
2569
        }
2570
      } catch (err) {
2571
        _didIteratorError21 = true;
2572
        _iteratorError21 = err;
2573
      } finally {
2574
        try {
2575
          if (!_iteratorNormalCompletion21 && _iterator21["return"] != null) {
2576
            _iterator21["return"]();
2577
          }
2578
        } finally {
2579
          if (_didIteratorError21) {
2580
            throw _iteratorError21;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2581
          }
2582
        }
2583
      }
2584
2585
      if (files[0].upload.chunked) {
2586
        // Put the xhr object in the right chunk object, so it can be associated later, and found with _getChunk
2587
        files[0].upload.chunks[dataBlocks[0].chunkIndex].xhr = xhr;
2588
      }
2589
2590
      var method = this.resolveOption(this.options.method, files);
2591
      var url = this.resolveOption(this.options.url, files);
2592
      xhr.open(method, url, true); // Setting the timeout after open because of IE11 issue: https://gitlab.com/meno/dropzone/issues/8
2593
2594
      xhr.timeout = this.resolveOption(this.options.timeout, files); // Has to be after `.open()`. See https://github.com/enyo/dropzone/issues/179
2595
2596
      xhr.withCredentials = !!this.options.withCredentials;
2597
2598
      xhr.onload = function (e) {
2599
        _this16._finishedUploading(files, xhr, e);
2600
      };
2601
2602
      xhr.ontimeout = function () {
2603
        _this16._handleUploadError(files, xhr, "Request timedout after ".concat(_this16.options.timeout, " seconds"));
2604
      };
2605
2606
      xhr.onerror = function () {
2607
        _this16._handleUploadError(files, xhr);
2608
      }; // Some browsers do not have the .upload property
2609
2610
2611
      var progressObj = xhr.upload != null ? xhr.upload : xhr;
2612
2613
      progressObj.onprogress = function (e) {
2614
        return _this16._updateFilesUploadProgress(files, xhr, e);
2615
      };
2616
2617
      var headers = {
2618
        "Accept": "application/json",
2619
        "Cache-Control": "no-cache",
2620
        "X-Requested-With": "XMLHttpRequest"
2621
      };
2622
2623
      if (this.options.headers) {
2624
        Dropzone.extend(headers, this.options.headers);
2625
      }
2626
2627
      for (var headerName in headers) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
2628
        var headerValue = headers[headerName];
2629
2630
        if (headerValue) {
2631
          xhr.setRequestHeader(headerName, headerValue);
2632
        }
2633
      }
2634
2635
      var formData = new FormData(); // Adding all @options parameters
2636
2637
      if (this.options.params) {
2638
        var additionalParams = this.options.params;
2639
2640
        if (typeof additionalParams === 'function') {
2641
          additionalParams = additionalParams.call(this, files, xhr, files[0].upload.chunked ? this._getChunk(files[0], xhr) : null);
2642
        }
2643
2644
        for (var key in additionalParams) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
2645
          var value = additionalParams[key];
2646
          formData.append(key, value);
2647
        }
2648
      } // Let the user add additional data if necessary
2649
2650
2651
      var _iteratorNormalCompletion22 = true;
2652
      var _didIteratorError22 = false;
2653
      var _iteratorError22 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError22 is implicitly marked as undefined by the declaration.
Loading history...
2654
2655
      try {
2656
        for (var _iterator22 = files[Symbol.iterator](), _step22; !(_iteratorNormalCompletion22 = (_step22 = _iterator22.next()).done); _iteratorNormalCompletion22 = true) {
2657
          var _file = _step22.value;
2658
          this.emit("sending", _file, xhr, formData);
2659
        }
2660
      } catch (err) {
2661
        _didIteratorError22 = true;
2662
        _iteratorError22 = err;
2663
      } finally {
2664
        try {
2665
          if (!_iteratorNormalCompletion22 && _iterator22["return"] != null) {
2666
            _iterator22["return"]();
2667
          }
2668
        } finally {
2669
          if (_didIteratorError22) {
2670
            throw _iteratorError22;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2671
          }
2672
        }
2673
      }
2674
2675
      if (this.options.uploadMultiple) {
2676
        this.emit("sendingmultiple", files, xhr, formData);
2677
      }
2678
2679
      this._addFormElementData(formData); // Finally add the files
2680
      // Has to be last because some servers (eg: S3) expect the file to be the last parameter
2681
2682
2683
      for (var i = 0; i < dataBlocks.length; i++) {
2684
        var dataBlock = dataBlocks[i];
2685
        formData.append(dataBlock.name, dataBlock.data, dataBlock.filename);
2686
      }
2687
2688
      this.submitRequest(xhr, formData, files);
2689
    } // Transforms all files with this.options.transformFile and invokes done with the transformed files when done.
2690
2691
  }, {
2692
    key: "_transformFiles",
2693
    value: function _transformFiles(files, done) {
2694
      var _this17 = this;
2695
2696
      var transformedFiles = []; // Clumsy way of handling asynchronous calls, until I get to add a proper Future library.
2697
2698
      var doneCounter = 0;
2699
2700
      var _loop = function _loop(i) {
2701
        _this17.options.transformFile.call(_this17, files[i], function (transformedFile) {
2702
          transformedFiles[i] = transformedFile;
2703
2704
          if (++doneCounter === files.length) {
2705
            done(transformedFiles);
2706
          }
2707
        });
2708
      };
2709
2710
      for (var i = 0; i < files.length; i++) {
2711
        _loop(i);
2712
      }
2713
    } // Takes care of adding other input elements of the form to the AJAX request
2714
2715
  }, {
2716
    key: "_addFormElementData",
2717
    value: function _addFormElementData(formData) {
2718
      // Take care of other input elements
2719
      if (this.element.tagName === "FORM") {
2720
        var _iteratorNormalCompletion23 = true;
2721
        var _didIteratorError23 = false;
2722
        var _iteratorError23 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError23 is implicitly marked as undefined by the declaration.
Loading history...
2723
2724
        try {
2725
          for (var _iterator23 = this.element.querySelectorAll("input, textarea, select, button")[Symbol.iterator](), _step23; !(_iteratorNormalCompletion23 = (_step23 = _iterator23.next()).done); _iteratorNormalCompletion23 = true) {
2726
            var input = _step23.value;
2727
            var inputName = input.getAttribute("name");
2728
            var inputType = input.getAttribute("type");
2729
            if (inputType) inputType = inputType.toLowerCase(); // If the input doesn't have a name, we can't use it.
2730
2731
            if (typeof inputName === 'undefined' || inputName === null) continue;
2732
2733
            if (input.tagName === "SELECT" && input.hasAttribute("multiple")) {
2734
              // Possibly multiple values
2735
              var _iteratorNormalCompletion24 = true;
2736
              var _didIteratorError24 = false;
2737
              var _iteratorError24 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError24 is implicitly marked as undefined by the declaration.
Loading history...
2738
2739
              try {
2740
                for (var _iterator24 = input.options[Symbol.iterator](), _step24; !(_iteratorNormalCompletion24 = (_step24 = _iterator24.next()).done); _iteratorNormalCompletion24 = true) {
2741
                  var option = _step24.value;
2742
2743
                  if (option.selected) {
2744
                    formData.append(inputName, option.value);
2745
                  }
2746
                }
2747
              } catch (err) {
2748
                _didIteratorError24 = true;
2749
                _iteratorError24 = err;
2750
              } finally {
2751
                try {
2752
                  if (!_iteratorNormalCompletion24 && _iterator24["return"] != null) {
2753
                    _iterator24["return"]();
2754
                  }
2755
                } finally {
2756
                  if (_didIteratorError24) {
2757
                    throw _iteratorError24;
2758
                  }
2759
                }
2760
              }
2761
            } else if (!inputType || inputType !== "checkbox" && inputType !== "radio" || input.checked) {
2762
              formData.append(inputName, input.value);
2763
            }
2764
          }
2765
        } catch (err) {
2766
          _didIteratorError23 = true;
2767
          _iteratorError23 = err;
2768
        } finally {
2769
          try {
2770
            if (!_iteratorNormalCompletion23 && _iterator23["return"] != null) {
2771
              _iterator23["return"]();
2772
            }
2773
          } finally {
2774
            if (_didIteratorError23) {
2775
              throw _iteratorError23;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2776
            }
2777
          }
2778
        }
2779
      }
2780
    } // Invoked when there is new progress information about given files.
2781
    // If e is not provided, it is assumed that the upload is finished.
2782
2783
  }, {
2784
    key: "_updateFilesUploadProgress",
2785
    value: function _updateFilesUploadProgress(files, xhr, e) {
2786
      var progress;
2787
2788
      if (typeof e !== 'undefined') {
2789
        progress = 100 * e.loaded / e.total;
2790
2791
        if (files[0].upload.chunked) {
2792
          var file = files[0]; // Since this is a chunked upload, we need to update the appropriate chunk progress.
2793
2794
          var chunk = this._getChunk(file, xhr);
2795
2796
          chunk.progress = progress;
2797
          chunk.total = e.total;
2798
          chunk.bytesSent = e.loaded;
2799
          var fileProgress = 0,
0 ignored issues
show
Unused Code introduced by
The variable fileProgress seems to be never used. Consider removing it.
Loading history...
2800
              fileTotal,
0 ignored issues
show
Unused Code introduced by
The variable fileTotal seems to be never used. Consider removing it.
Loading history...
2801
              fileBytesSent;
0 ignored issues
show
Unused Code introduced by
The variable fileBytesSent seems to be never used. Consider removing it.
Loading history...
2802
          file.upload.progress = 0;
2803
          file.upload.total = 0;
2804
          file.upload.bytesSent = 0;
2805
2806
          for (var i = 0; i < file.upload.totalChunkCount; i++) {
2807
            if (file.upload.chunks[i] !== undefined && file.upload.chunks[i].progress !== undefined) {
2808
              file.upload.progress += file.upload.chunks[i].progress;
2809
              file.upload.total += file.upload.chunks[i].total;
2810
              file.upload.bytesSent += file.upload.chunks[i].bytesSent;
2811
            }
2812
          }
2813
2814
          file.upload.progress = file.upload.progress / file.upload.totalChunkCount;
2815
        } else {
2816
          var _iteratorNormalCompletion25 = true;
2817
          var _didIteratorError25 = false;
2818
          var _iteratorError25 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError25 is implicitly marked as undefined by the declaration.
Loading history...
2819
2820
          try {
2821
            for (var _iterator25 = files[Symbol.iterator](), _step25; !(_iteratorNormalCompletion25 = (_step25 = _iterator25.next()).done); _iteratorNormalCompletion25 = true) {
2822
              var _file2 = _step25.value;
2823
              _file2.upload.progress = progress;
2824
              _file2.upload.total = e.total;
2825
              _file2.upload.bytesSent = e.loaded;
2826
            }
2827
          } catch (err) {
2828
            _didIteratorError25 = true;
2829
            _iteratorError25 = err;
2830
          } finally {
2831
            try {
2832
              if (!_iteratorNormalCompletion25 && _iterator25["return"] != null) {
2833
                _iterator25["return"]();
2834
              }
2835
            } finally {
2836
              if (_didIteratorError25) {
2837
                throw _iteratorError25;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2838
              }
2839
            }
2840
          }
2841
        }
2842
2843
        var _iteratorNormalCompletion26 = true;
2844
        var _didIteratorError26 = false;
2845
        var _iteratorError26 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError26 is implicitly marked as undefined by the declaration.
Loading history...
2846
2847
        try {
2848
          for (var _iterator26 = files[Symbol.iterator](), _step26; !(_iteratorNormalCompletion26 = (_step26 = _iterator26.next()).done); _iteratorNormalCompletion26 = true) {
2849
            var _file3 = _step26.value;
2850
            this.emit("uploadprogress", _file3, _file3.upload.progress, _file3.upload.bytesSent);
2851
          }
2852
        } catch (err) {
2853
          _didIteratorError26 = true;
2854
          _iteratorError26 = err;
2855
        } finally {
2856
          try {
2857
            if (!_iteratorNormalCompletion26 && _iterator26["return"] != null) {
2858
              _iterator26["return"]();
2859
            }
2860
          } finally {
2861
            if (_didIteratorError26) {
2862
              throw _iteratorError26;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2863
            }
2864
          }
2865
        }
2866
      } else {
2867
        // Called when the file finished uploading
2868
        var allFilesFinished = true;
2869
        progress = 100;
2870
        var _iteratorNormalCompletion27 = true;
2871
        var _didIteratorError27 = false;
2872
        var _iteratorError27 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError27 is implicitly marked as undefined by the declaration.
Loading history...
2873
2874
        try {
2875
          for (var _iterator27 = files[Symbol.iterator](), _step27; !(_iteratorNormalCompletion27 = (_step27 = _iterator27.next()).done); _iteratorNormalCompletion27 = true) {
2876
            var _file4 = _step27.value;
2877
2878
            if (_file4.upload.progress !== 100 || _file4.upload.bytesSent !== _file4.upload.total) {
2879
              allFilesFinished = false;
2880
            }
2881
2882
            _file4.upload.progress = progress;
2883
            _file4.upload.bytesSent = _file4.upload.total;
2884
          } // Nothing to do, all files already at 100%
2885
2886
        } catch (err) {
2887
          _didIteratorError27 = true;
2888
          _iteratorError27 = err;
2889
        } finally {
2890
          try {
2891
            if (!_iteratorNormalCompletion27 && _iterator27["return"] != null) {
2892
              _iterator27["return"]();
2893
            }
2894
          } finally {
2895
            if (_didIteratorError27) {
2896
              throw _iteratorError27;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2897
            }
2898
          }
2899
        }
2900
2901
        if (allFilesFinished) {
2902
          return;
2903
        }
2904
2905
        var _iteratorNormalCompletion28 = true;
2906
        var _didIteratorError28 = false;
2907
        var _iteratorError28 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError28 is implicitly marked as undefined by the declaration.
Loading history...
2908
2909
        try {
2910
          for (var _iterator28 = files[Symbol.iterator](), _step28; !(_iteratorNormalCompletion28 = (_step28 = _iterator28.next()).done); _iteratorNormalCompletion28 = true) {
2911
            var _file5 = _step28.value;
2912
            this.emit("uploadprogress", _file5, progress, _file5.upload.bytesSent);
2913
          }
2914
        } catch (err) {
2915
          _didIteratorError28 = true;
2916
          _iteratorError28 = err;
2917
        } finally {
2918
          try {
2919
            if (!_iteratorNormalCompletion28 && _iterator28["return"] != null) {
2920
              _iterator28["return"]();
2921
            }
2922
          } finally {
2923
            if (_didIteratorError28) {
2924
              throw _iteratorError28;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
2925
            }
2926
          }
2927
        }
2928
      }
2929
    }
2930
  }, {
2931
    key: "_finishedUploading",
2932
    value: function _finishedUploading(files, xhr, e) {
2933
      var response;
2934
2935
      if (files[0].status === Dropzone.CANCELED) {
2936
        return;
2937
      }
2938
2939
      if (xhr.readyState !== 4) {
2940
        return;
2941
      }
2942
2943
      if (xhr.responseType !== 'arraybuffer' && xhr.responseType !== 'blob') {
2944
        response = xhr.responseText;
2945
2946
        if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
2947
          try {
2948
            response = JSON.parse(response);
2949
          } catch (error) {
2950
            e = error;
2951
            response = "Invalid JSON response from server.";
2952
          }
2953
        }
2954
      }
2955
2956
      this._updateFilesUploadProgress(files);
2957
2958
      if (!(200 <= xhr.status && xhr.status < 300)) {
2959
        this._handleUploadError(files, xhr, response);
0 ignored issues
show
Bug introduced by
The variable response does not seem to be initialized in case xhr.responseType !== "ar...responseType !== "blob" on line 2943 is false. Are you sure the function _handleUploadError handles undefined variables?
Loading history...
2960
      } else {
2961
        if (files[0].upload.chunked) {
2962
          files[0].upload.finishedChunkUpload(this._getChunk(files[0], xhr));
2963
        } else {
2964
          this._finished(files, response, e);
2965
        }
2966
      }
2967
    }
2968
  }, {
2969
    key: "_handleUploadError",
2970
    value: function _handleUploadError(files, xhr, response) {
2971
      if (files[0].status === Dropzone.CANCELED) {
2972
        return;
2973
      }
2974
2975
      if (files[0].upload.chunked && this.options.retryChunks) {
2976
        var chunk = this._getChunk(files[0], xhr);
2977
2978
        if (chunk.retries++ < this.options.retryChunksLimit) {
2979
          this._uploadData(files, [chunk.dataBlock]);
2980
2981
          return;
2982
        } else {
2983
          console.warn('Retried this chunk too often. Giving up.');
2984
        }
2985
      }
2986
2987
      this._errorProcessing(files, response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr);
2988
    }
2989
  }, {
2990
    key: "submitRequest",
2991
    value: function submitRequest(xhr, formData, files) {
2992
      xhr.send(formData);
2993
    } // Called internally when processing is finished.
2994
    // Individual callbacks have to be called in the appropriate sections.
2995
2996
  }, {
2997
    key: "_finished",
2998
    value: function _finished(files, responseText, e) {
2999
      var _iteratorNormalCompletion29 = true;
3000
      var _didIteratorError29 = false;
3001
      var _iteratorError29 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError29 is implicitly marked as undefined by the declaration.
Loading history...
3002
3003
      try {
3004
        for (var _iterator29 = files[Symbol.iterator](), _step29; !(_iteratorNormalCompletion29 = (_step29 = _iterator29.next()).done); _iteratorNormalCompletion29 = true) {
3005
          var file = _step29.value;
3006
          file.status = Dropzone.SUCCESS;
3007
          this.emit("success", file, responseText, e);
3008
          this.emit("complete", file);
3009
        }
3010
      } catch (err) {
3011
        _didIteratorError29 = true;
3012
        _iteratorError29 = err;
3013
      } finally {
3014
        try {
3015
          if (!_iteratorNormalCompletion29 && _iterator29["return"] != null) {
3016
            _iterator29["return"]();
3017
          }
3018
        } finally {
3019
          if (_didIteratorError29) {
3020
            throw _iteratorError29;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
3021
          }
3022
        }
3023
      }
3024
3025
      if (this.options.uploadMultiple) {
3026
        this.emit("successmultiple", files, responseText, e);
3027
        this.emit("completemultiple", files);
3028
      }
3029
3030
      if (this.options.autoProcessQueue) {
3031
        return this.processQueue();
3032
      }
3033
    } // Called internally when processing is finished.
3034
    // Individual callbacks have to be called in the appropriate sections.
3035
3036
  }, {
3037
    key: "_errorProcessing",
3038
    value: function _errorProcessing(files, message, xhr) {
3039
      var _iteratorNormalCompletion30 = true;
3040
      var _didIteratorError30 = false;
3041
      var _iteratorError30 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError30 is implicitly marked as undefined by the declaration.
Loading history...
3042
3043
      try {
3044
        for (var _iterator30 = files[Symbol.iterator](), _step30; !(_iteratorNormalCompletion30 = (_step30 = _iterator30.next()).done); _iteratorNormalCompletion30 = true) {
3045
          var file = _step30.value;
3046
          file.status = Dropzone.ERROR;
3047
          this.emit("error", file, message, xhr);
3048
          this.emit("complete", file);
3049
        }
3050
      } catch (err) {
3051
        _didIteratorError30 = true;
3052
        _iteratorError30 = err;
3053
      } finally {
3054
        try {
3055
          if (!_iteratorNormalCompletion30 && _iterator30["return"] != null) {
3056
            _iterator30["return"]();
3057
          }
3058
        } finally {
3059
          if (_didIteratorError30) {
3060
            throw _iteratorError30;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
3061
          }
3062
        }
3063
      }
3064
3065
      if (this.options.uploadMultiple) {
3066
        this.emit("errormultiple", files, message, xhr);
3067
        this.emit("completemultiple", files);
3068
      }
3069
3070
      if (this.options.autoProcessQueue) {
3071
        return this.processQueue();
3072
      }
3073
    }
3074
  }], [{
3075
    key: "uuidv4",
3076
    value: function uuidv4() {
3077
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
3078
        var r = Math.random() * 16 | 0,
3079
            v = c === 'x' ? r : r & 0x3 | 0x8;
3080
        return v.toString(16);
3081
      });
3082
    }
3083
  }]);
3084
3085
  return Dropzone;
3086
}(Emitter);
3087
3088
Dropzone.initClass();
3089
Dropzone.version = "5.7.0"; // This is a map of options for your different dropzones. Add configurations
3090
// to this object for your different dropzone elemens.
3091
//
3092
// Example:
3093
//
3094
//     Dropzone.options.myDropzoneElementId = { maxFilesize: 1 };
3095
//
3096
// To disable autoDiscover for a specific element, you can set `false` as an option:
3097
//
3098
//     Dropzone.options.myDisabledElementId = false;
3099
//
3100
// And in html:
3101
//
3102
//     <form action="/upload" id="my-dropzone-element-id" class="dropzone"></form>
3103
3104
Dropzone.options = {}; // Returns the options for an element or undefined if none available.
3105
3106
Dropzone.optionsForElement = function (element) {
3107
  // Get the `Dropzone.options.elementId` for this element if it exists
3108
  if (element.getAttribute("id")) {
3109
    return Dropzone.options[camelize(element.getAttribute("id"))];
3110
  } else {
3111
    return undefined;
3112
  }
3113
}; // Holds a list of all dropzone instances
3114
3115
3116
Dropzone.instances = []; // Returns the dropzone for given element if any
3117
3118
Dropzone.forElement = function (element) {
3119
  if (typeof element === "string") {
3120
    element = document.querySelector(element);
3121
  }
3122
3123
  if ((element != null ? element.dropzone : undefined) == null) {
3124
    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.");
3125
  }
3126
3127
  return element.dropzone;
3128
}; // Set to false if you don't want Dropzone to automatically find and attach to .dropzone elements.
3129
3130
3131
Dropzone.autoDiscover = true; // Looks for all .dropzone elements and creates a dropzone for them
3132
3133
Dropzone.discover = function () {
3134
  var dropzones;
3135
3136
  if (document.querySelectorAll) {
3137
    dropzones = document.querySelectorAll(".dropzone");
3138
  } else {
3139
    dropzones = []; // IE :(
3140
3141
    var checkElements = function checkElements(elements) {
3142
      return function () {
3143
        var result = [];
3144
        var _iteratorNormalCompletion31 = true;
3145
        var _didIteratorError31 = false;
3146
        var _iteratorError31 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError31 is implicitly marked as undefined by the declaration.
Loading history...
3147
3148
        try {
3149
          for (var _iterator31 = elements[Symbol.iterator](), _step31; !(_iteratorNormalCompletion31 = (_step31 = _iterator31.next()).done); _iteratorNormalCompletion31 = true) {
3150
            var el = _step31.value;
3151
3152
            if (/(^| )dropzone($| )/.test(el.className)) {
3153
              result.push(dropzones.push(el));
3154
            } else {
3155
              result.push(undefined);
3156
            }
3157
          }
3158
        } catch (err) {
3159
          _didIteratorError31 = true;
3160
          _iteratorError31 = err;
3161
        } finally {
3162
          try {
3163
            if (!_iteratorNormalCompletion31 && _iterator31["return"] != null) {
3164
              _iterator31["return"]();
3165
            }
3166
          } finally {
3167
            if (_didIteratorError31) {
3168
              throw _iteratorError31;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
3169
            }
3170
          }
3171
        }
3172
3173
        return result;
3174
      }();
3175
    };
3176
3177
    checkElements(document.getElementsByTagName("div"));
3178
    checkElements(document.getElementsByTagName("form"));
3179
  }
3180
3181
  return function () {
3182
    var result = [];
3183
    var _iteratorNormalCompletion32 = true;
3184
    var _didIteratorError32 = false;
3185
    var _iteratorError32 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError32 is implicitly marked as undefined by the declaration.
Loading history...
3186
3187
    try {
3188
      for (var _iterator32 = dropzones[Symbol.iterator](), _step32; !(_iteratorNormalCompletion32 = (_step32 = _iterator32.next()).done); _iteratorNormalCompletion32 = true) {
3189
        var dropzone = _step32.value;
3190
3191
        // Create a dropzone unless auto discover has been disabled for specific element
3192
        if (Dropzone.optionsForElement(dropzone) !== false) {
3193
          result.push(new Dropzone(dropzone));
3194
        } else {
3195
          result.push(undefined);
3196
        }
3197
      }
3198
    } catch (err) {
3199
      _didIteratorError32 = true;
3200
      _iteratorError32 = err;
3201
    } finally {
3202
      try {
3203
        if (!_iteratorNormalCompletion32 && _iterator32["return"] != null) {
3204
          _iterator32["return"]();
3205
        }
3206
      } finally {
3207
        if (_didIteratorError32) {
3208
          throw _iteratorError32;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
3209
        }
3210
      }
3211
    }
3212
3213
    return result;
3214
  }();
3215
}; // Since the whole Drag'n'Drop API is pretty new, some browsers implement it,
3216
// but not correctly.
3217
// So I created a blacklist of userAgents. Yes, yes. Browser sniffing, I know.
3218
// But what to do when browsers *theoretically* support an API, but crash
3219
// when using it.
3220
//
3221
// This is a list of regular expressions tested against navigator.userAgent
3222
//
3223
// ** It should only be used on browser that *do* support the API, but
3224
// incorrectly **
3225
//
3226
3227
3228
Dropzone.blacklistedBrowsers = [// The mac os and windows phone version of opera 12 seems to have a problem with the File drag'n'drop API.
3229
/opera.*(Macintosh|Windows Phone).*version\/12/i]; // Checks if the browser is supported
3230
3231
Dropzone.isBrowserSupported = function () {
3232
  var capableBrowser = true;
3233
3234
  if (window.File && window.FileReader && window.FileList && window.Blob && window.FormData && document.querySelector) {
3235
    if (!("classList" in document.createElement("a"))) {
3236
      capableBrowser = false;
3237
    } else {
3238
      // The browser supports the API, but may be blacklisted.
3239
      var _iteratorNormalCompletion33 = true;
3240
      var _didIteratorError33 = false;
3241
      var _iteratorError33 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError33 is implicitly marked as undefined by the declaration.
Loading history...
3242
3243
      try {
3244
        for (var _iterator33 = Dropzone.blacklistedBrowsers[Symbol.iterator](), _step33; !(_iteratorNormalCompletion33 = (_step33 = _iterator33.next()).done); _iteratorNormalCompletion33 = true) {
3245
          var regex = _step33.value;
3246
3247
          if (regex.test(navigator.userAgent)) {
3248
            capableBrowser = false;
3249
            continue;
0 ignored issues
show
Unused Code introduced by
This continue has no effect on the loop flow and can be removed.
Loading history...
3250
          }
3251
        }
3252
      } catch (err) {
3253
        _didIteratorError33 = true;
3254
        _iteratorError33 = err;
3255
      } finally {
3256
        try {
3257
          if (!_iteratorNormalCompletion33 && _iterator33["return"] != null) {
3258
            _iterator33["return"]();
3259
          }
3260
        } finally {
3261
          if (_didIteratorError33) {
3262
            throw _iteratorError33;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
3263
          }
3264
        }
3265
      }
3266
    }
3267
  } else {
3268
    capableBrowser = false;
3269
  }
3270
3271
  return capableBrowser;
3272
};
3273
3274
Dropzone.dataURItoBlob = function (dataURI) {
3275
  // convert base64 to raw binary data held in a string
3276
  // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
3277
  var byteString = atob(dataURI.split(',')[1]); // separate out the mime component
3278
3279
  var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; // write the bytes of the string to an ArrayBuffer
3280
3281
  var ab = new ArrayBuffer(byteString.length);
3282
  var ia = new Uint8Array(ab);
3283
3284
  for (var i = 0, end = byteString.length, asc = 0 <= end; asc ? i <= end : i >= end; asc ? i++ : i--) {
3285
    ia[i] = byteString.charCodeAt(i);
3286
  } // write the ArrayBuffer to a blob
3287
3288
3289
  return new Blob([ab], {
3290
    type: mimeString
3291
  });
3292
}; // Returns an array without the rejected item
3293
3294
3295
var without = function without(list, rejectedItem) {
3296
  return list.filter(function (item) {
3297
    return item !== rejectedItem;
3298
  }).map(function (item) {
3299
    return item;
3300
  });
3301
}; // abc-def_ghi -> abcDefGhi
3302
3303
3304
var camelize = function camelize(str) {
3305
  return str.replace(/[\-_](\w)/g, function (match) {
3306
    return match.charAt(1).toUpperCase();
3307
  });
3308
}; // Creates an element from string
3309
3310
3311
Dropzone.createElement = function (string) {
3312
  var div = document.createElement("div");
3313
  div.innerHTML = string;
3314
  return div.childNodes[0];
3315
}; // Tests if given element is inside (or simply is) the container
3316
3317
3318
Dropzone.elementInside = function (element, container) {
3319
  if (element === container) {
3320
    return true;
3321
  } // Coffeescript doesn't support do/while loops
3322
3323
3324
  while (element = element.parentNode) {
3325
    if (element === container) {
3326
      return true;
3327
    }
3328
  }
3329
3330
  return false;
3331
};
3332
3333
Dropzone.getElement = function (el, name) {
3334
  var element;
3335
3336
  if (typeof el === "string") {
3337
    element = document.querySelector(el);
3338
  } else if (el.nodeType != null) {
3339
    element = el;
3340
  }
3341
3342
  if (element == null) {
0 ignored issues
show
Bug introduced by
The variable element does not seem to be initialized in case el.nodeType != null on line 3338 is false. Are you sure this can never be the case?
Loading history...
3343
    throw new Error("Invalid `".concat(name, "` option provided. Please provide a CSS selector or a plain HTML element."));
3344
  }
3345
3346
  return element;
3347
};
3348
3349
Dropzone.getElements = function (els, name) {
3350
  var el, elements;
3351
3352
  if (els instanceof Array) {
3353
    elements = [];
3354
3355
    try {
3356
      var _iteratorNormalCompletion34 = true;
3357
      var _didIteratorError34 = false;
3358
      var _iteratorError34 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError34 is implicitly marked as undefined by the declaration.
Loading history...
3359
3360
      try {
3361
        for (var _iterator34 = els[Symbol.iterator](), _step34; !(_iteratorNormalCompletion34 = (_step34 = _iterator34.next()).done); _iteratorNormalCompletion34 = true) {
3362
          el = _step34.value;
3363
          elements.push(this.getElement(el, name));
3364
        }
3365
      } catch (err) {
3366
        _didIteratorError34 = true;
3367
        _iteratorError34 = err;
3368
      } finally {
3369
        try {
3370
          if (!_iteratorNormalCompletion34 && _iterator34["return"] != null) {
3371
            _iterator34["return"]();
3372
          }
3373
        } finally {
3374
          if (_didIteratorError34) {
3375
            throw _iteratorError34;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
3376
          }
3377
        }
3378
      }
3379
    } catch (e) {
3380
      elements = null;
3381
    }
3382
  } else if (typeof els === "string") {
3383
    elements = [];
3384
    var _iteratorNormalCompletion35 = true;
3385
    var _didIteratorError35 = false;
3386
    var _iteratorError35 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError35 is implicitly marked as undefined by the declaration.
Loading history...
3387
3388
    try {
3389
      for (var _iterator35 = document.querySelectorAll(els)[Symbol.iterator](), _step35; !(_iteratorNormalCompletion35 = (_step35 = _iterator35.next()).done); _iteratorNormalCompletion35 = true) {
3390
        el = _step35.value;
3391
        elements.push(el);
3392
      }
3393
    } catch (err) {
3394
      _didIteratorError35 = true;
3395
      _iteratorError35 = err;
3396
    } finally {
3397
      try {
3398
        if (!_iteratorNormalCompletion35 && _iterator35["return"] != null) {
3399
          _iterator35["return"]();
3400
        }
3401
      } finally {
3402
        if (_didIteratorError35) {
3403
          throw _iteratorError35;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
3404
        }
3405
      }
3406
    }
3407
  } else if (els.nodeType != null) {
3408
    elements = [els];
3409
  }
3410
3411
  if (elements == null || !elements.length) {
0 ignored issues
show
Bug introduced by
The variable elements does not seem to be initialized in case els.nodeType != null on line 3407 is false. Are you sure this can never be the case?
Loading history...
3412
    throw new Error("Invalid `".concat(name, "` option provided. Please provide a CSS selector, a plain HTML element or a list of those."));
3413
  }
3414
3415
  return elements;
3416
}; // Asks the user the question and calls accepted or rejected accordingly
3417
//
3418
// The default implementation just uses `window.confirm` and then calls the
3419
// appropriate callback.
3420
3421
3422
Dropzone.confirm = function (question, accepted, rejected) {
3423
  if (window.confirm(question)) {
3424
    return accepted();
3425
  } else if (rejected != null) {
3426
    return rejected();
3427
  }
3428
}; // Validates the mime type like this:
3429
//
3430
// https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-accept
3431
3432
3433
Dropzone.isValidFile = function (file, acceptedFiles) {
3434
  if (!acceptedFiles) {
3435
    return true;
3436
  } // If there are no accepted mime types, it's OK
3437
3438
3439
  acceptedFiles = acceptedFiles.split(",");
3440
  var mimeType = file.type;
3441
  var baseMimeType = mimeType.replace(/\/.*$/, "");
3442
  var _iteratorNormalCompletion36 = true;
3443
  var _didIteratorError36 = false;
3444
  var _iteratorError36 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as _iteratorError36 is implicitly marked as undefined by the declaration.
Loading history...
3445
3446
  try {
3447
    for (var _iterator36 = acceptedFiles[Symbol.iterator](), _step36; !(_iteratorNormalCompletion36 = (_step36 = _iterator36.next()).done); _iteratorNormalCompletion36 = true) {
3448
      var validType = _step36.value;
3449
      validType = validType.trim();
3450
3451
      if (validType.charAt(0) === ".") {
3452
        if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) {
3453
          return true;
3454
        }
3455
      } else if (/\/\*$/.test(validType)) {
3456
        // This is something like a image/* mime type
3457
        if (baseMimeType === validType.replace(/\/.*$/, "")) {
3458
          return true;
3459
        }
3460
      } else {
3461
        if (mimeType === validType) {
3462
          return true;
3463
        }
3464
      }
3465
    }
3466
  } catch (err) {
3467
    _didIteratorError36 = true;
3468
    _iteratorError36 = err;
3469
  } finally {
3470
    try {
3471
      if (!_iteratorNormalCompletion36 && _iterator36["return"] != null) {
3472
        _iterator36["return"]();
3473
      }
3474
    } finally {
3475
      if (_didIteratorError36) {
3476
        throw _iteratorError36;
0 ignored issues
show
Comprehensibility Bug introduced by
Usage of the throw statement in a finally clause is discouraged. This construct may mask errors and makes debugging difficult.
Loading history...
3477
      }
3478
    }
3479
  }
3480
3481
  return false;
3482
}; // Augment jQuery
3483
3484
3485
if (typeof jQuery !== 'undefined' && jQuery !== null) {
3486
  jQuery.fn.dropzone = function (options) {
3487
    return this.each(function () {
3488
      return new Dropzone(this, options);
3489
    });
3490
  };
3491
}
3492
3493
if (typeof module !== 'undefined' && module !== null) {
3494
  module.exports = Dropzone;
3495
} else {
3496
  window.Dropzone = Dropzone;
3497
} // Dropzone file status codes
3498
3499
3500
Dropzone.ADDED = "added";
3501
Dropzone.QUEUED = "queued"; // For backwards compatibility. Now, if a file is accepted, it's either queued
3502
// or uploading.
3503
3504
Dropzone.ACCEPTED = Dropzone.QUEUED;
3505
Dropzone.UPLOADING = "uploading";
3506
Dropzone.PROCESSING = Dropzone.UPLOADING; // alias
3507
3508
Dropzone.CANCELED = "canceled";
3509
Dropzone.ERROR = "error";
3510
Dropzone.SUCCESS = "success";
3511
/*
3512
3513
 Bugfix for iOS 6 and 7
3514
 Source: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
3515
 based on the work of https://github.com/stomita/ios-imagefile-megapixel
3516
3517
 */
3518
// Detecting vertical squash in loaded image.
3519
// Fixes a bug which squash image vertically while drawing into canvas for some images.
3520
// This is a bug in iOS6 devices. This function from https://github.com/stomita/ios-imagefile-megapixel
3521
3522
var detectVerticalSquash = function detectVerticalSquash(img) {
3523
  var iw = img.naturalWidth;
0 ignored issues
show
Unused Code introduced by
The variable iw seems to be never used. Consider removing it.
Loading history...
3524
  var ih = img.naturalHeight;
3525
  var canvas = document.createElement("canvas");
3526
  canvas.width = 1;
3527
  canvas.height = ih;
3528
  var ctx = canvas.getContext("2d");
3529
  ctx.drawImage(img, 0, 0);
3530
3531
  var _ctx$getImageData = ctx.getImageData(1, 0, 1, ih),
3532
      data = _ctx$getImageData.data; // search image edge pixel position in case it is squashed vertically.
3533
3534
3535
  var sy = 0;
3536
  var ey = ih;
3537
  var py = ih;
3538
3539
  while (py > sy) {
3540
    var alpha = data[(py - 1) * 4 + 3];
3541
3542
    if (alpha === 0) {
3543
      ey = py;
3544
    } else {
3545
      sy = py;
3546
    }
3547
3548
    py = ey + sy >> 1;
3549
  }
3550
3551
  var ratio = py / ih;
3552
3553
  if (ratio === 0) {
3554
    return 1;
3555
  } else {
3556
    return ratio;
3557
  }
3558
}; // A replacement for context.drawImage
3559
// (args are for source and destination).
3560
3561
3562
var drawImageIOSFix = function drawImageIOSFix(ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) {
3563
  var vertSquashRatio = detectVerticalSquash(img);
3564
  return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);
3565
}; // Based on MinifyJpeg
3566
// Source: http://www.perry.cz/files/ExifRestorer.js
3567
// http://elicon.blog57.fc2.com/blog-entry-206.html
3568
3569
3570
var ExifRestore =
3571
/*#__PURE__*/
3572
function () {
3573
  function ExifRestore() {
3574
    _classCallCheck(this, ExifRestore);
3575
  }
3576
3577
  _createClass(ExifRestore, null, [{
3578
    key: "initClass",
3579
    value: function initClass() {
3580
      this.KEY_STR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
3581
    }
3582
  }, {
3583
    key: "encode64",
3584
    value: function encode64(input) {
3585
      var output = '';
3586
      var chr1 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as chr1 is implicitly marked as undefined by the declaration.
Loading history...
3587
      var chr2 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as chr2 is implicitly marked as undefined by the declaration.
Loading history...
3588
      var chr3 = '';
3589
      var enc1 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as enc1 is implicitly marked as undefined by the declaration.
Loading history...
3590
      var enc2 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as enc2 is implicitly marked as undefined by the declaration.
Loading history...
3591
      var enc3 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as enc3 is implicitly marked as undefined by the declaration.
Loading history...
3592
      var enc4 = '';
3593
      var i = 0;
3594
3595
      while (true) {
3596
        chr1 = input[i++];
3597
        chr2 = input[i++];
3598
        chr3 = input[i++];
3599
        enc1 = chr1 >> 2;
3600
        enc2 = (chr1 & 3) << 4 | chr2 >> 4;
3601
        enc3 = (chr2 & 15) << 2 | chr3 >> 6;
3602
        enc4 = chr3 & 63;
3603
3604
        if (isNaN(chr2)) {
3605
          enc3 = enc4 = 64;
3606
        } else if (isNaN(chr3)) {
3607
          enc4 = 64;
3608
        }
3609
3610
        output = output + this.KEY_STR.charAt(enc1) + this.KEY_STR.charAt(enc2) + this.KEY_STR.charAt(enc3) + this.KEY_STR.charAt(enc4);
3611
        chr1 = chr2 = chr3 = '';
0 ignored issues
show
Unused Code introduced by
The assignment to variable chr1 seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable chr3 seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable chr2 seems to be never used. Consider removing it.
Loading history...
3612
        enc1 = enc2 = enc3 = enc4 = '';
0 ignored issues
show
Unused Code introduced by
The assignment to variable enc3 seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable enc4 seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable enc1 seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable enc2 seems to be never used. Consider removing it.
Loading history...
3613
3614
        if (!(i < input.length)) {
3615
          break;
3616
        }
3617
      }
3618
3619
      return output;
3620
    }
3621
  }, {
3622
    key: "restore",
3623
    value: function restore(origFileBase64, resizedFileBase64) {
3624
      if (!origFileBase64.match('data:image/jpeg;base64,')) {
3625
        return resizedFileBase64;
3626
      }
3627
3628
      var rawImage = this.decode64(origFileBase64.replace('data:image/jpeg;base64,', ''));
3629
      var segments = this.slice2Segments(rawImage);
3630
      var image = this.exifManipulation(resizedFileBase64, segments);
3631
      return "data:image/jpeg;base64,".concat(this.encode64(image));
3632
    }
3633
  }, {
3634
    key: "exifManipulation",
3635
    value: function exifManipulation(resizedFileBase64, segments) {
3636
      var exifArray = this.getExifArray(segments);
3637
      var newImageArray = this.insertExif(resizedFileBase64, exifArray);
3638
      var aBuffer = new Uint8Array(newImageArray);
3639
      return aBuffer;
3640
    }
3641
  }, {
3642
    key: "getExifArray",
3643
    value: function getExifArray(segments) {
3644
      var seg = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as seg is implicitly marked as undefined by the declaration.
Loading history...
3645
      var x = 0;
3646
3647
      while (x < segments.length) {
3648
        seg = segments[x];
3649
3650
        if (seg[0] === 255 & seg[1] === 225) {
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
3651
          return seg;
3652
        }
3653
3654
        x++;
3655
      }
3656
3657
      return [];
3658
    }
3659
  }, {
3660
    key: "insertExif",
3661
    value: function insertExif(resizedFileBase64, exifArray) {
3662
      var imageData = resizedFileBase64.replace('data:image/jpeg;base64,', '');
3663
      var buf = this.decode64(imageData);
3664
      var separatePoint = buf.indexOf(255, 3);
3665
      var mae = buf.slice(0, separatePoint);
3666
      var ato = buf.slice(separatePoint);
3667
      var array = mae;
3668
      array = array.concat(exifArray);
3669
      array = array.concat(ato);
3670
      return array;
3671
    }
3672
  }, {
3673
    key: "slice2Segments",
3674
    value: function slice2Segments(rawImageArray) {
3675
      var head = 0;
3676
      var segments = [];
3677
3678
      while (true) {
3679
        var length;
3680
3681
        if (rawImageArray[head] === 255 & rawImageArray[head + 1] === 218) {
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
3682
          break;
3683
        }
3684
3685
        if (rawImageArray[head] === 255 & rawImageArray[head + 1] === 216) {
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
3686
          head += 2;
3687
        } else {
3688
          length = rawImageArray[head + 2] * 256 + rawImageArray[head + 3];
3689
          var endPoint = head + length + 2;
3690
          var seg = rawImageArray.slice(head, endPoint);
3691
          segments.push(seg);
3692
          head = endPoint;
3693
        }
3694
3695
        if (head > rawImageArray.length) {
3696
          break;
3697
        }
3698
      }
3699
3700
      return segments;
3701
    }
3702
  }, {
3703
    key: "decode64",
3704
    value: function decode64(input) {
3705
      var output = '';
0 ignored issues
show
Unused Code introduced by
The variable output seems to be never used. Consider removing it.
Loading history...
3706
      var chr1 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as chr1 is implicitly marked as undefined by the declaration.
Loading history...
3707
      var chr2 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as chr2 is implicitly marked as undefined by the declaration.
Loading history...
3708
      var chr3 = '';
3709
      var enc1 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as enc1 is implicitly marked as undefined by the declaration.
Loading history...
3710
      var enc2 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as enc2 is implicitly marked as undefined by the declaration.
Loading history...
3711
      var enc3 = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as enc3 is implicitly marked as undefined by the declaration.
Loading history...
3712
      var enc4 = '';
3713
      var i = 0;
3714
      var buf = []; // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
3715
3716
      var base64test = /[^A-Za-z0-9\+\/\=]/g;
3717
3718
      if (base64test.exec(input)) {
3719
        console.warn('There were invalid base64 characters in the input text.\nValid base64 characters are A-Z, a-z, 0-9, \'+\', \'/\',and \'=\'\nExpect errors in decoding.');
3720
      }
3721
3722
      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
3723
3724
      while (true) {
3725
        enc1 = this.KEY_STR.indexOf(input.charAt(i++));
3726
        enc2 = this.KEY_STR.indexOf(input.charAt(i++));
3727
        enc3 = this.KEY_STR.indexOf(input.charAt(i++));
3728
        enc4 = this.KEY_STR.indexOf(input.charAt(i++));
3729
        chr1 = enc1 << 2 | enc2 >> 4;
3730
        chr2 = (enc2 & 15) << 4 | enc3 >> 2;
3731
        chr3 = (enc3 & 3) << 6 | enc4;
3732
        buf.push(chr1);
3733
3734
        if (enc3 !== 64) {
3735
          buf.push(chr2);
3736
        }
3737
3738
        if (enc4 !== 64) {
3739
          buf.push(chr3);
3740
        }
3741
3742
        chr1 = chr2 = chr3 = '';
0 ignored issues
show
Unused Code introduced by
The assignment to variable chr3 seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable chr2 seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable chr1 seems to be never used. Consider removing it.
Loading history...
3743
        enc1 = enc2 = enc3 = enc4 = '';
0 ignored issues
show
Unused Code introduced by
The assignment to variable enc2 seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable enc1 seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable enc3 seems to be never used. Consider removing it.
Loading history...
Unused Code introduced by
The assignment to variable enc4 seems to be never used. Consider removing it.
Loading history...
3744
3745
        if (!(i < input.length)) {
3746
          break;
3747
        }
3748
      }
3749
3750
      return buf;
3751
    }
3752
  }]);
3753
3754
  return ExifRestore;
3755
}();
3756
3757
ExifRestore.initClass();
3758
/*
3759
 * contentloaded.js
3760
 *
3761
 * Author: Diego Perini (diego.perini at gmail.com)
3762
 * Summary: cross-browser wrapper for DOMContentLoaded
3763
 * Updated: 20101020
3764
 * License: MIT
3765
 * Version: 1.2
3766
 *
3767
 * URL:
3768
 * http://javascript.nwbox.com/ContentLoaded/
3769
 * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
3770
 */
3771
// @win window reference
3772
// @fn function reference
3773
3774
var contentLoaded = function contentLoaded(win, fn) {
3775
  var done = false;
3776
  var top = true;
0 ignored issues
show
Unused Code introduced by
The assignment to variable top seems to be never used. Consider removing it.
Loading history...
3777
  var doc = win.document;
3778
  var root = doc.documentElement;
3779
  var add = doc.addEventListener ? "addEventListener" : "attachEvent";
3780
  var rem = doc.addEventListener ? "removeEventListener" : "detachEvent";
3781
  var pre = doc.addEventListener ? "" : "on";
3782
3783
  var init = function init(e) {
3784
    if (e.type === "readystatechange" && doc.readyState !== "complete") {
3785
      return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
3786
    }
3787
3788
    (e.type === "load" ? win : doc)[rem](pre + e.type, init, false);
3789
3790
    if (!done && (done = true)) {
3791
      return fn.call(win, e.type || e);
3792
    }
3793
  };
3794
3795
  var poll = function poll() {
3796
    try {
3797
      root.doScroll("left");
3798
    } catch (e) {
3799
      setTimeout(poll, 50);
3800
      return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
3801
    }
3802
3803
    return init("poll");
3804
  };
3805
3806
  if (doc.readyState !== "complete") {
3807
    if (doc.createEventObject && root.doScroll) {
3808
      try {
3809
        top = !win.frameElement;
3810
      } catch (error) {}
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
3811
3812
      if (top) {
3813
        poll();
3814
      }
3815
    }
3816
3817
    doc[add](pre + "DOMContentLoaded", init, false);
3818
    doc[add](pre + "readystatechange", init, false);
3819
    return win[add](pre + "load", init, false);
3820
  }
3821
}; // As a single function to be able to write tests.
3822
3823
3824
Dropzone._autoDiscoverFunction = function () {
3825
  if (Dropzone.autoDiscover) {
3826
    return Dropzone.discover();
3827
  }
3828
};
3829
3830
contentLoaded(window, Dropzone._autoDiscoverFunction);
3831
3832
function __guard__(value, transform) {
3833
  return typeof value !== 'undefined' && value !== null ? transform(value) : undefined;
3834
}
3835
3836
function __guardMethod__(obj, methodName, transform) {
3837
  if (typeof obj !== 'undefined' && obj !== null && typeof obj[methodName] === 'function') {
3838
    return transform(obj, methodName);
3839
  } else {
3840
    return undefined;
3841
  }
3842
}
3843
3844
    return module.exports;
3845
}));