You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3526 lines
118 KiB

6 years ago
  1. "use strict";
  2. var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6. /*
  7. *
  8. * More info at [www.dropzonejs.com](http://www.dropzonejs.com)
  9. *
  10. * Copyright (c) 2012, Matias Meno
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining a copy
  13. * of this software and associated documentation files (the "Software"), to deal
  14. * in the Software without restriction, including without limitation the rights
  15. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16. * copies of the Software, and to permit persons to whom the Software is
  17. * furnished to do so, subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be included in
  20. * all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  28. * THE SOFTWARE.
  29. *
  30. */
  31. // The Emitter class provides the ability to call `.on()` on Dropzone to listen
  32. // to events.
  33. // It is strongly based on component's emitter class, and I removed the
  34. // functionality because of the dependency hell with different frameworks.
  35. var Emitter = function () {
  36. function Emitter() {
  37. _classCallCheck(this, Emitter);
  38. }
  39. _createClass(Emitter, [{
  40. key: "on",
  41. // Add an event listener for given event
  42. value: function on(event, fn) {
  43. this._callbacks = this._callbacks || {};
  44. // Create namespace for this event
  45. if (!this._callbacks[event]) {
  46. this._callbacks[event] = [];
  47. }
  48. this._callbacks[event].push(fn);
  49. return this;
  50. }
  51. }, {
  52. key: "emit",
  53. value: function emit(event) {
  54. this._callbacks = this._callbacks || {};
  55. var callbacks = this._callbacks[event];
  56. if (callbacks) {
  57. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  58. args[_key - 1] = arguments[_key];
  59. }
  60. for (var _iterator = callbacks, _isArray = true, _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  61. var _ref;
  62. if (_isArray) {
  63. if (_i >= _iterator.length) break;
  64. _ref = _iterator[_i++];
  65. } else {
  66. _i = _iterator.next();
  67. if (_i.done) break;
  68. _ref = _i.value;
  69. }
  70. var callback = _ref;
  71. callback.apply(this, args);
  72. }
  73. }
  74. return this;
  75. }
  76. // Remove event listener for given event. If fn is not provided, all event
  77. // listeners for that event will be removed. If neither is provided, all
  78. // event listeners will be removed.
  79. }, {
  80. key: "off",
  81. value: function off(event, fn) {
  82. if (!this._callbacks || arguments.length === 0) {
  83. this._callbacks = {};
  84. return this;
  85. }
  86. // specific event
  87. var callbacks = this._callbacks[event];
  88. if (!callbacks) {
  89. return this;
  90. }
  91. // remove all handlers
  92. if (arguments.length === 1) {
  93. delete this._callbacks[event];
  94. return this;
  95. }
  96. // remove specific handler
  97. for (var i = 0; i < callbacks.length; i++) {
  98. var callback = callbacks[i];
  99. if (callback === fn) {
  100. callbacks.splice(i, 1);
  101. break;
  102. }
  103. }
  104. return this;
  105. }
  106. }]);
  107. return Emitter;
  108. }();
  109. var Dropzone = function (_Emitter) {
  110. _inherits(Dropzone, _Emitter);
  111. _createClass(Dropzone, null, [{
  112. key: "initClass",
  113. value: function initClass() {
  114. // Exposing the emitter class, mainly for tests
  115. this.prototype.Emitter = Emitter;
  116. /*
  117. This is a list of all available events you can register on a dropzone object.
  118. You can register an event handler like this:
  119. dropzone.on("dragEnter", function() { });
  120. */
  121. 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"];
  122. this.prototype.defaultOptions = {
  123. /**
  124. * Has to be specified on elements other than form (or when the form
  125. * doesn't have an `action` attribute). You can also
  126. * provide a function that will be called with `files` and
  127. * must return the url (since `v3.12.0`)
  128. */
  129. url: null,
  130. /**
  131. * Can be changed to `"put"` if necessary. You can also provide a function
  132. * that will be called with `files` and must return the method (since `v3.12.0`).
  133. */
  134. method: "post",
  135. /**
  136. * Will be set on the XHRequest.
  137. */
  138. withCredentials: false,
  139. /**
  140. * The timeout for the XHR requests in milliseconds (since `v4.4.0`).
  141. */
  142. timeout: 30000,
  143. /**
  144. * How many file uploads to process in parallel (See the
  145. * Enqueuing file uploads* documentation section for more info)
  146. */
  147. parallelUploads: 2,
  148. /**
  149. * Whether to send multiple files in one request. If
  150. * this it set to true, then the fallback file input element will
  151. * have the `multiple` attribute as well. This option will
  152. * also trigger additional events (like `processingmultiple`). See the events
  153. * documentation section for more information.
  154. */
  155. uploadMultiple: false,
  156. /**
  157. * Whether you want files to be uploaded in chunks to your server. This can't be
  158. * used in combination with `uploadMultiple`.
  159. *
  160. * See [chunksUploaded](#config-chunksUploaded) for the callback to finalise an upload.
  161. */
  162. chunking: false,
  163. /**
  164. * If `chunking` is enabled, this defines whether **every** file should be chunked,
  165. * even if the file size is below chunkSize. This means, that the additional chunk
  166. * form data will be submitted and the `chunksUploaded` callback will be invoked.
  167. */
  168. forceChunking: false,
  169. /**
  170. * If `chunking` is `true`, then this defines the chunk size in bytes.
  171. */
  172. chunkSize: 2000000,
  173. /**
  174. * If `true`, the individual chunks of a file are being uploaded simultaneously.
  175. */
  176. parallelChunkUploads: false,
  177. /**
  178. * Whether a chunk should be retried if it fails.
  179. */
  180. retryChunks: false,
  181. /**
  182. * If `retryChunks` is true, how many times should it be retried.
  183. */
  184. retryChunksLimit: 3,
  185. /**
  186. * If not `null` defines how many files this Dropzone handles. If it exceeds,
  187. * the event `maxfilesexceeded` will be called. The dropzone element gets the
  188. * class `dz-max-files-reached` accordingly so you can provide visual feedback.
  189. */
  190. maxFilesize: 256,
  191. /**
  192. * The name of the file param that gets transferred.
  193. * **NOTE**: If you have the option `uploadMultiple` set to `true`, then
  194. * Dropzone will append `[]` to the name.
  195. */
  196. paramName: "file",
  197. /**
  198. * Whether thumbnails for images should be generated
  199. */
  200. createImageThumbnails: true,
  201. /**
  202. * In MB. When the filename exceeds this limit, the thumbnail will not be generated.
  203. */
  204. maxThumbnailFilesize: 10,
  205. /**
  206. * If `null`, the ratio of the image will be used to calculate it.
  207. */
  208. thumbnailWidth: 120,
  209. /**
  210. * The same as `thumbnailWidth`. If both are null, images will not be resized.
  211. */
  212. thumbnailHeight: 120,
  213. /**
  214. * How the images should be scaled down in case both, `thumbnailWidth` and `thumbnailHeight` are provided.
  215. * Can be either `contain` or `crop`.
  216. */
  217. thumbnailMethod: 'crop',
  218. /**
  219. * If set, images will be resized to these dimensions before being **uploaded**.
  220. * If only one, `resizeWidth` **or** `resizeHeight` is provided, the original aspect
  221. * ratio of the file will be preserved.
  222. *
  223. * The `options.transformFile` function uses these options, so if the `transformFile` function
  224. * is overridden, these options don't do anything.
  225. */
  226. resizeWidth: null,
  227. /**
  228. * See `resizeWidth`.
  229. */
  230. resizeHeight: null,
  231. /**
  232. * The mime type of the resized image (before it gets uploaded to the server).
  233. * If `null` the original mime type will be used. To force jpeg, for example, use `image/jpeg`.
  234. * See `resizeWidth` for more information.
  235. */
  236. resizeMimeType: null,
  237. /**
  238. * The quality of the resized images. See `resizeWidth`.
  239. */
  240. resizeQuality: 0.8,
  241. /**
  242. * How the images should be scaled down in case both, `resizeWidth` and `resizeHeight` are provided.
  243. * Can be either `contain` or `crop`.
  244. */
  245. resizeMethod: 'contain',
  246. /**
  247. * The base that is used to calculate the filesize. You can change this to
  248. * 1024 if you would rather display kibibytes, mebibytes, etc...
  249. * 1024 is technically incorrect, because `1024 bytes` are `1 kibibyte` not `1 kilobyte`.
  250. * You can change this to `1024` if you don't care about validity.
  251. */
  252. filesizeBase: 1000,
  253. /**
  254. * Can be used to limit the maximum number of files that will be handled by this Dropzone
  255. */
  256. maxFiles: null,
  257. /**
  258. * An optional object to send additional headers to the server. Eg:
  259. * `{ "My-Awesome-Header": "header value" }`
  260. */
  261. headers: null,
  262. /**
  263. * If `true`, the dropzone element itself will be clickable, if `false`
  264. * nothing will be clickable.
  265. *
  266. * You can also pass an HTML element, a CSS selector (for multiple elements)
  267. * or an array of those. In that case, all of those elements will trigger an
  268. * upload when clicked.
  269. */
  270. clickable: true,
  271. /**
  272. * Whether hidden files in directories should be ignored.
  273. */
  274. ignoreHiddenFiles: true,
  275. /**
  276. * The default implementation of `accept` checks the file's mime type or
  277. * extension against this list. This is a comma separated list of mime
  278. * types or file extensions.
  279. *
  280. * Eg.: `image/*,application/pdf,.psd`
  281. *
  282. * If the Dropzone is `clickable` this option will also be used as
  283. * [`accept`](https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-accept)
  284. * parameter on the hidden file input as well.
  285. */
  286. acceptedFiles: null,
  287. /**
  288. * **Deprecated!**
  289. * Use acceptedFiles instead.
  290. */
  291. acceptedMimeTypes: null,
  292. /**
  293. * If false, files will be added to the queue but the queue will not be
  294. * processed automatically.
  295. * This can be useful if you need some additional user input before sending
  296. * files (or if you want want all files sent at once).
  297. * If you're ready to send the file simply call `myDropzone.processQueue()`.
  298. *
  299. * See the [enqueuing file uploads](#enqueuing-file-uploads) documentation
  300. * section for more information.
  301. */
  302. autoProcessQueue: true,
  303. /**
  304. * If false, files added to the dropzone will not be queued by default.
  305. * You'll have to call `enqueueFile(file)` manually.
  306. */
  307. autoQueue: true,
  308. /**
  309. * If `true`, this will add a link to every file preview to remove or cancel (if
  310. * already uploading) the file. The `dictCancelUpload`, `dictCancelUploadConfirmation`
  311. * and `dictRemoveFile` options are used for the wording.
  312. */
  313. addRemoveLinks: false,
  314. /**
  315. * Defines where to display the file previews if `null` the
  316. * Dropzone element itself is used. Can be a plain `HTMLElement` or a CSS
  317. * selector. The element should have the `dropzone-previews` class so
  318. * the previews are displayed properly.
  319. */
  320. previewsContainer: null,
  321. /**
  322. * This is the element the hidden input field (which is used when clicking on the
  323. * dropzone to trigger file selection) will be appended to. This might
  324. * be important in case you use frameworks to switch the content of your page.
  325. */
  326. hiddenInputContainer: "body",
  327. /**
  328. * If null, no capture type will be specified
  329. * If camera, mobile devices will skip the file selection and choose camera
  330. * If microphone, mobile devices will skip the file selection and choose the microphone
  331. * If camcorder, mobile devices will skip the file selection and choose the camera in video mode
  332. * On apple devices multiple must be set to false. AcceptedFiles may need to
  333. * be set to an appropriate mime type (e.g. "image/*", "audio/*", or "video/*").
  334. */
  335. capture: null,
  336. /**
  337. * **Deprecated**. Use `renameFile` instead.
  338. */
  339. renameFilename: null,
  340. /**
  341. * A function that is invoked before the file is uploaded to the server and renames the file.
  342. * This function gets the `File` as argument and can use the `file.name`. The actual name of the
  343. * file that gets used during the upload can be accessed through `file.upload.filename`.
  344. */
  345. renameFile: null,
  346. /**
  347. * If `true` the fallback will be forced. This is very useful to test your server
  348. * implementations first and make sure that everything works as
  349. * expected without dropzone if you experience problems, and to test
  350. * how your fallbacks will look.
  351. */
  352. forceFallback: false,
  353. /**
  354. * The text used before any files are dropped.
  355. */
  356. dictDefaultMessage: "Drop files here to upload",
  357. /**
  358. * The text that replaces the default message text it the browser is not supported.
  359. */
  360. dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
  361. /**
  362. * The text that will be added before the fallback form.
  363. * If you provide a fallback element yourself, or if this option is `null` this will
  364. * be ignored.
  365. */
  366. dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
  367. /**
  368. * If the filesize is too big.
  369. * `{{filesize}}` and `{{maxFilesize}}` will be replaced with the respective configuration values.
  370. */
  371. dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.",
  372. /**
  373. * If the file doesn't match the file type.
  374. */
  375. dictInvalidFileType: "You can't upload files of this type.",
  376. /**
  377. * If the server response was invalid.
  378. * `{{statusCode}}` will be replaced with the servers status code.
  379. */
  380. dictResponseError: "Server responded with {{statusCode}} code.",
  381. /**
  382. * If `addRemoveLinks` is true, the text to be used for the cancel upload link.
  383. */
  384. dictCancelUpload: "Cancel upload",
  385. /**
  386. * The text that is displayed if an upload was manually canceled
  387. */
  388. dictUploadCanceled: "Upload canceled.",
  389. /**
  390. * If `addRemoveLinks` is true, the text to be used for confirmation when cancelling upload.
  391. */
  392. dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
  393. /**
  394. * If `addRemoveLinks` is true, the text to be used to remove a file.
  395. */
  396. dictRemoveFile: "Remove file",
  397. /**
  398. * If this is not null, then the user will be prompted before removing a file.
  399. */
  400. dictRemoveFileConfirmation: null,
  401. /**
  402. * Displayed if `maxFiles` is st and exceeded.
  403. * The string `{{maxFiles}}` will be replaced by the configuration value.
  404. */
  405. dictMaxFilesExceeded: "You can not upload any more files.",
  406. /**
  407. * Allows you to translate the different units. Starting with `tb` for terabytes and going down to
  408. * `b` for bytes.
  409. */
  410. dictFileSizeUnits: { tb: "TB", gb: "GB", mb: "MB", kb: "KB", b: "b" },
  411. /**
  412. * Called when dropzone initialized
  413. * You can add event listeners here
  414. */
  415. init: function init() {},
  416. /**
  417. * Can be an **object** of additional parameters to transfer to the server, **or** a `Function`
  418. * that gets invoked with the `files`, `xhr` and, if it's a chunked upload, `chunk` arguments. In case
  419. * of a function, this needs to return a map.
  420. *
  421. * The default implementation does nothing for normal uploads, but adds relevant information for
  422. * chunked uploads.
  423. *
  424. * This is the same as adding hidden input fields in the form element.
  425. */
  426. params: function params(files, xhr, chunk) {
  427. if (chunk) {
  428. return {
  429. dzuuid: chunk.file.upload.uuid,
  430. dzchunkindex: chunk.index,
  431. dztotalfilesize: chunk.file.size,
  432. dzchunksize: this.options.chunkSize,
  433. dztotalchunkcount: chunk.file.upload.totalChunkCount,
  434. dzchunkbyteoffset: chunk.index * this.options.chunkSize
  435. };
  436. }
  437. },
  438. /**
  439. * A function that gets a [file](https://developer.mozilla.org/en-US/docs/DOM/File)
  440. * and a `done` function as parameters.
  441. *
  442. * If the done function is invoked without arguments, the file is "accepted" and will
  443. * be processed. If you pass an error message, the file is rejected, and the error
  444. * message will be displayed.
  445. * This function will not be called if the file is too big or doesn't match the mime types.
  446. */
  447. accept: function accept(file, done) {
  448. return done();
  449. },
  450. /**
  451. * The callback that will be invoked when all chunks have been uploaded for a file.
  452. * It gets the file for which the chunks have been uploaded as the first parameter,
  453. * and the `done` function as second. `done()` needs to be invoked when everything
  454. * needed to finish the upload process is done.
  455. */
  456. chunksUploaded: function chunksUploaded(file, done) {
  457. done();
  458. },
  459. /**
  460. * Gets called when the browser is not supported.
  461. * The default implementation shows the fallback input field and adds
  462. * a text.
  463. */
  464. fallback: function fallback() {
  465. // This code should pass in IE7... :(
  466. var messageElement = void 0;
  467. this.element.className = this.element.className + " dz-browser-not-supported";
  468. for (var _iterator2 = this.element.getElementsByTagName("div"), _isArray2 = true, _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
  469. var _ref2;
  470. if (_isArray2) {
  471. if (_i2 >= _iterator2.length) break;
  472. _ref2 = _iterator2[_i2++];
  473. } else {
  474. _i2 = _iterator2.next();
  475. if (_i2.done) break;
  476. _ref2 = _i2.value;
  477. }
  478. var child = _ref2;
  479. if (/(^| )dz-message($| )/.test(child.className)) {
  480. messageElement = child;
  481. child.className = "dz-message"; // Removes the 'dz-default' class
  482. break;
  483. }
  484. }
  485. if (!messageElement) {
  486. messageElement = Dropzone.createElement("<div class=\"dz-message\"><span></span></div>");
  487. this.element.appendChild(messageElement);
  488. }
  489. var span = messageElement.getElementsByTagName("span")[0];
  490. if (span) {
  491. if (span.textContent != null) {
  492. span.textContent = this.options.dictFallbackMessage;
  493. } else if (span.innerText != null) {
  494. span.innerText = this.options.dictFallbackMessage;
  495. }
  496. }
  497. return this.element.appendChild(this.getFallbackForm());
  498. },
  499. /**
  500. * Gets called to calculate the thumbnail dimensions.
  501. *
  502. * It gets `file`, `width` and `height` (both may be `null`) as parameters and must return an object containing:
  503. *
  504. * - `srcWidth` & `srcHeight` (required)
  505. * - `trgWidth` & `trgHeight` (required)
  506. * - `srcX` & `srcY` (optional, default `0`)
  507. * - `trgX` & `trgY` (optional, default `0`)
  508. *
  509. * Those values are going to be used by `ctx.drawImage()`.
  510. */
  511. resize: function resize(file, width, height, resizeMethod) {
  512. var info = {
  513. srcX: 0,
  514. srcY: 0,
  515. srcWidth: file.width,
  516. srcHeight: file.height
  517. };
  518. var srcRatio = file.width / file.height;
  519. // Automatically calculate dimensions if not specified
  520. if (width == null && height == null) {
  521. width = info.srcWidth;
  522. height = info.srcHeight;
  523. } else if (width == null) {
  524. width = height * srcRatio;
  525. } else if (height == null) {
  526. height = width / srcRatio;
  527. }
  528. // Make sure images aren't upscaled
  529. width = Math.min(width, info.srcWidth);
  530. height = Math.min(height, info.srcHeight);
  531. var trgRatio = width / height;
  532. if (info.srcWidth > width || info.srcHeight > height) {
  533. // Image is bigger and needs rescaling
  534. if (resizeMethod === 'crop') {
  535. if (srcRatio > trgRatio) {
  536. info.srcHeight = file.height;
  537. info.srcWidth = info.srcHeight * trgRatio;
  538. } else {
  539. info.srcWidth = file.width;
  540. info.srcHeight = info.srcWidth / trgRatio;
  541. }
  542. } else if (resizeMethod === 'contain') {
  543. // Method 'contain'
  544. if (srcRatio > trgRatio) {
  545. height = width / srcRatio;
  546. } else {
  547. width = height * srcRatio;
  548. }
  549. } else {
  550. throw new Error("Unknown resizeMethod '" + resizeMethod + "'");
  551. }
  552. }
  553. info.srcX = (file.width - info.srcWidth) / 2;
  554. info.srcY = (file.height - info.srcHeight) / 2;
  555. info.trgWidth = width;
  556. info.trgHeight = height;
  557. return info;
  558. },
  559. /**
  560. * Can be used to transform the file (for example, resize an image if necessary).
  561. *
  562. * The default implementation uses `resizeWidth` and `resizeHeight` (if provided) and resizes
  563. * images according to those dimensions.
  564. *
  565. * Gets the `file` as the first parameter, and a `done()` function as the second, that needs
  566. * to be invoked with the file when the transformation is done.
  567. */
  568. transformFile: function transformFile(file, done) {
  569. if ((this.options.resizeWidth || this.options.resizeHeight) && file.type.match(/image.*/)) {
  570. return this.resizeImage(file, this.options.resizeWidth, this.options.resizeHeight, this.options.resizeMethod, done);
  571. } else {
  572. return done(file);
  573. }
  574. },
  575. /**
  576. * A string that contains the template used for each dropped
  577. * file. Change it to fulfill your needs but make sure to properly
  578. * provide all elements.
  579. *
  580. * If you want to use an actual HTML element instead of providing a String
  581. * as a config option, you could create a div with the id `tpl`,
  582. * put the template inside it and provide the element like this:
  583. *
  584. * document
  585. * .querySelector('#tpl')
  586. * .innerHTML
  587. *
  588. */
  589. previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n <div class=\"dz-image\"><img data-dz-thumbnail /></div>\n <div class=\"dz-details\">\n <div class=\"dz-size\"><span data-dz-size></span></div>\n <div class=\"dz-filename\"><span data-dz-name></span></div>\n </div>\n <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress></span></div>\n <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n <div class=\"dz-success-mark\">\n <svg width=\"54px\" height=\"54px\" viewBox=\"0 0 54 54\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:sketch=\"http://www.bohemiancoding.com/sketch/ns\">\n <title>Check</title>\n <defs></defs>\n <g id=\"Page-1\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\" sketch:type=\"MSPage\">\n <path d=\"M23.5,31.8431458 L17.5852419,25.9283877 C16.0248253,24.3679711 13.4910294,24.366835 11.9289322,25.9289322 C10.3700136,27.4878508 10.3665912,30.0234455 11.9283877,31.5852419 L20.4147581,40.0716123 C20.5133999,40.1702541 20.6159315,40.2626649 20.7218615,40.3488435 C22.2835669,41.8725651 24.794234,41.8626202 26.3461564,40.3106978 L43.3106978,23.3461564 C44.8771021,21.7797521 44.8758057,19.2483887 43.3137085,17.6862915 C41.7547899,16.1273729 39.2176035,16.1255422 37.6538436,17.6893022 L23.5,31.8431458 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z\" id=\"Oval-2\" stroke-opacity=\"0.198794158\" stroke=\"#747474\" fill-opacity=\"0.816519475\" fill=\"#FFFFFF\" sketch:type=\"MSShapeGroup\"></path>\n </g>\n </svg>\n </div>\n <div class=\"dz-error-mark\">\n <svg width=\"54px\" height=\"54px\" viewBox=\"0 0 54 54\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:sketch=\"http://www.bohemiancoding.com/sketch/ns\">\n <title>Error</title>\n <defs></defs>\n <g id=\"Page-1\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\" sketch:type=\"MSPage\">\n <g id=\"Check-+-Oval-2\" sketch:type=\"MSLayerGroup\" stroke=\"#747474\" stroke-opacity=\"0.198794158\" fill=\"#FFFFFF\" fill-opacity=\"0.816519475\">\n <path d=\"M32.6568542,29 L38.3106978,23.3461564 C39.8771021,21.7797521 39.8758057,19.2483887 38.3137085,17.6862915 C36.7547899,16.1273729 34.2176035,16.1255422 32.6538436,17.6893022 L27,23.3431458 L21.3461564,17.6893022 C19.7823965,16.1255422 17.2452101,16.1273729 15.6862915,17.6862915 C14.1241943,19.2483887 14.1228979,21.7797521 15.6893022,23.3461564 L21.3431458,29 L15.6893022,34.6538436 C14.1228979,36.2202479 14.1241943,38.7516113 15.6862915,40.3137085 C17.2452101,41.8726271 19.7823965,41.8744578 21.3461564,40.3106978 L27,34.6568542 L32.6538436,40.3106978 C34.2176035,41.8744578 36.7547899,41.8726271 38.3137085,40.3137085 C39.8758057,38.7516113 39.8771021,36.2202479 38.3106978,34.6538436 L32.6568542,29 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z\" id=\"Oval-2\" sketch:type=\"MSShapeGroup\"></path>\n </g>\n </g>\n </svg>\n </div>\n</div>",
  590. // END OPTIONS
  591. // (Required by the dropzone documentation parser)
  592. /*
  593. Those functions register themselves to the events on init and handle all
  594. the user interface specific stuff. Overwriting them won't break the upload
  595. but can break the way it's displayed.
  596. You can overwrite them if you don't like the default behavior. If you just
  597. want to add an additional event handler, register it on the dropzone object
  598. and don't overwrite those options.
  599. */
  600. // Those are self explanatory and simply concern the DragnDrop.
  601. drop: function drop(e) {
  602. return this.element.classList.remove("dz-drag-hover");
  603. },
  604. dragstart: function dragstart(e) {},
  605. dragend: function dragend(e) {
  606. return this.element.classList.remove("dz-drag-hover");
  607. },
  608. dragenter: function dragenter(e) {
  609. return this.element.classList.add("dz-drag-hover");
  610. },
  611. dragover: function dragover(e) {
  612. return this.element.classList.add("dz-drag-hover");
  613. },
  614. dragleave: function dragleave(e) {
  615. return this.element.classList.remove("dz-drag-hover");
  616. },
  617. paste: function paste(e) {},
  618. // Called whenever there are no files left in the dropzone anymore, and the
  619. // dropzone should be displayed as if in the initial state.
  620. reset: function reset() {
  621. return this.element.classList.remove("dz-started");
  622. },
  623. // Called when a file is added to the queue
  624. // Receives `file`
  625. addedfile: function addedfile(file) {
  626. var _this2 = this;
  627. if (this.element === this.previewsContainer) {
  628. this.element.classList.add("dz-started");
  629. }
  630. if (this.previewsContainer) {
  631. file.previewElement = Dropzone.createElement(this.options.previewTemplate.trim());
  632. file.previewTemplate = file.previewElement; // Backwards compatibility
  633. this.previewsContainer.appendChild(file.previewElement);
  634. for (var _iterator3 = file.previewElement.querySelectorAll("[data-dz-name]"), _isArray3 = true, _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
  635. var _ref3;
  636. if (_isArray3) {
  637. if (_i3 >= _iterator3.length) break;
  638. _ref3 = _iterator3[_i3++];
  639. } else {
  640. _i3 = _iterator3.next();
  641. if (_i3.done) break;
  642. _ref3 = _i3.value;
  643. }
  644. var node = _ref3;
  645. node.textContent = file.name;
  646. }
  647. for (var _iterator4 = file.previewElement.querySelectorAll("[data-dz-size]"), _isArray4 = true, _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
  648. if (_isArray4) {
  649. if (_i4 >= _iterator4.length) break;
  650. node = _iterator4[_i4++];
  651. } else {
  652. _i4 = _iterator4.next();
  653. if (_i4.done) break;
  654. node = _i4.value;
  655. }
  656. node.innerHTML = this.filesize(file.size);
  657. }
  658. if (this.options.addRemoveLinks) {
  659. file._removeLink = Dropzone.createElement("<a class=\"dz-remove\" href=\"javascript:undefined;\" data-dz-remove>" + this.options.dictRemoveFile + "</a>");
  660. file.previewElement.appendChild(file._removeLink);
  661. }
  662. var removeFileEvent = function removeFileEvent(e) {
  663. e.preventDefault();
  664. e.stopPropagation();
  665. if (file.status === Dropzone.UPLOADING) {
  666. return Dropzone.confirm(_this2.options.dictCancelUploadConfirmation, function () {
  667. return _this2.removeFile(file);
  668. });
  669. } else {
  670. if (_this2.options.dictRemoveFileConfirmation) {
  671. return Dropzone.confirm(_this2.options.dictRemoveFileConfirmation, function () {
  672. return _this2.removeFile(file);
  673. });
  674. } else {
  675. return _this2.removeFile(file);
  676. }
  677. }
  678. };
  679. for (var _iterator5 = file.previewElement.querySelectorAll("[data-dz-remove]"), _isArray5 = true, _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
  680. var _ref4;
  681. if (_isArray5) {
  682. if (_i5 >= _iterator5.length) break;
  683. _ref4 = _iterator5[_i5++];
  684. } else {
  685. _i5 = _iterator5.next();
  686. if (_i5.done) break;
  687. _ref4 = _i5.value;
  688. }
  689. var removeLink = _ref4;
  690. removeLink.addEventListener("click", removeFileEvent);
  691. }
  692. }
  693. },
  694. // Called whenever a file is removed.
  695. removedfile: function removedfile(file) {
  696. if (file.previewElement != null && file.previewElement.parentNode != null) {
  697. file.previewElement.parentNode.removeChild(file.previewElement);
  698. }
  699. return this._updateMaxFilesReachedClass();
  700. },
  701. // Called when a thumbnail has been generated
  702. // Receives `file` and `dataUrl`
  703. thumbnail: function thumbnail(file, dataUrl) {
  704. if (file.previewElement) {
  705. file.previewElement.classList.remove("dz-file-preview");
  706. for (var _iterator6 = file.previewElement.querySelectorAll("[data-dz-thumbnail]"), _isArray6 = true, _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
  707. var _ref5;
  708. if (_isArray6) {
  709. if (_i6 >= _iterator6.length) break;
  710. _ref5 = _iterator6[_i6++];
  711. } else {
  712. _i6 = _iterator6.next();
  713. if (_i6.done) break;
  714. _ref5 = _i6.value;
  715. }
  716. var thumbnailElement = _ref5;
  717. thumbnailElement.alt = file.name;
  718. thumbnailElement.src = dataUrl;
  719. }
  720. return setTimeout(function () {
  721. return file.previewElement.classList.add("dz-image-preview");
  722. }, 1);
  723. }
  724. },
  725. // Called whenever an error occurs
  726. // Receives `file` and `message`
  727. error: function error(file, message) {
  728. if (file.previewElement) {
  729. file.previewElement.classList.add("dz-error");
  730. if (typeof message !== "String" && message.error) {
  731. message = message.error;
  732. }
  733. for (var _iterator7 = file.previewElement.querySelectorAll("[data-dz-errormessage]"), _isArray7 = true, _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
  734. var _ref6;
  735. if (_isArray7) {
  736. if (_i7 >= _iterator7.length) break;
  737. _ref6 = _iterator7[_i7++];
  738. } else {
  739. _i7 = _iterator7.next();
  740. if (_i7.done) break;
  741. _ref6 = _i7.value;
  742. }
  743. var node = _ref6;
  744. node.textContent = message;
  745. }
  746. }
  747. },
  748. errormultiple: function errormultiple() {},
  749. // Called when a file gets processed. Since there is a cue, not all added
  750. // files are processed immediately.
  751. // Receives `file`
  752. processing: function processing(file) {
  753. if (file.previewElement) {
  754. file.previewElement.classList.add("dz-processing");
  755. if (file._removeLink) {
  756. return file._removeLink.textContent = this.options.dictCancelUpload;
  757. }
  758. }
  759. },
  760. processingmultiple: function processingmultiple() {},
  761. // Called whenever the upload progress gets updated.
  762. // Receives `file`, `progress` (percentage 0-100) and `bytesSent`.
  763. // To get the total number of bytes of the file, use `file.size`
  764. uploadprogress: function uploadprogress(file, progress, bytesSent) {
  765. if (file.previewElement) {
  766. for (var _iterator8 = file.previewElement.querySelectorAll("[data-dz-uploadprogress]"), _isArray8 = true, _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
  767. var _ref7;
  768. if (_isArray8) {
  769. if (_i8 >= _iterator8.length) break;
  770. _ref7 = _iterator8[_i8++];
  771. } else {
  772. _i8 = _iterator8.next();
  773. if (_i8.done) break;
  774. _ref7 = _i8.value;
  775. }
  776. var node = _ref7;
  777. node.nodeName === 'PROGRESS' ? node.value = progress : node.style.width = progress + "%";
  778. }
  779. }
  780. },
  781. // Called whenever the total upload progress gets updated.
  782. // Called with totalUploadProgress (0-100), totalBytes and totalBytesSent
  783. totaluploadprogress: function totaluploadprogress() {},
  784. // Called just before the file is sent. Gets the `xhr` object as second
  785. // parameter, so you can modify it (for example to add a CSRF token) and a
  786. // `formData` object to add additional information.
  787. sending: function sending() {},
  788. sendingmultiple: function sendingmultiple() {},
  789. // When the complete upload is finished and successful
  790. // Receives `file`
  791. success: function success(file) {
  792. if (file.previewElement) {
  793. return file.previewElement.classList.add("dz-success");
  794. }
  795. },
  796. successmultiple: function successmultiple() {},
  797. // When the upload is canceled.
  798. canceled: function canceled(file) {
  799. return this.emit("error", file, this.options.dictUploadCanceled);
  800. },
  801. canceledmultiple: function canceledmultiple() {},
  802. // When the upload is finished, either with success or an error.
  803. // Receives `file`
  804. complete: function complete(file) {
  805. if (file._removeLink) {
  806. file._removeLink.textContent = this.options.dictRemoveFile;
  807. }
  808. if (file.previewElement) {
  809. return file.previewElement.classList.add("dz-complete");
  810. }
  811. },
  812. completemultiple: function completemultiple() {},
  813. maxfilesexceeded: function maxfilesexceeded() {},
  814. maxfilesreached: function maxfilesreached() {},
  815. queuecomplete: function queuecomplete() {},
  816. addedfiles: function addedfiles() {}
  817. };
  818. this.prototype._thumbnailQueue = [];
  819. this.prototype._processingThumbnail = false;
  820. }
  821. // global utility
  822. }, {
  823. key: "extend",
  824. value: function extend(target) {
  825. for (var _len2 = arguments.length, objects = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  826. objects[_key2 - 1] = arguments[_key2];
  827. }
  828. for (var _iterator9 = objects, _isArray9 = true, _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) {
  829. var _ref8;
  830. if (_isArray9) {
  831. if (_i9 >= _iterator9.length) break;
  832. _ref8 = _iterator9[_i9++];
  833. } else {
  834. _i9 = _iterator9.next();
  835. if (_i9.done) break;
  836. _ref8 = _i9.value;
  837. }
  838. var object = _ref8;
  839. for (var key in object) {
  840. var val = object[key];
  841. target[key] = val;
  842. }
  843. }
  844. return target;
  845. }
  846. }]);
  847. function Dropzone(el, options) {
  848. _classCallCheck(this, Dropzone);
  849. var _this = _possibleConstructorReturn(this, (Dropzone.__proto__ || Object.getPrototypeOf(Dropzone)).call(this));
  850. var fallback = void 0,
  851. left = void 0;
  852. _this.element = el;
  853. // For backwards compatibility since the version was in the prototype previously
  854. _this.version = Dropzone.version;
  855. _this.defaultOptions.previewTemplate = _this.defaultOptions.previewTemplate.replace(/\n*/g, "");
  856. _this.clickableElements = [];
  857. _this.listeners = [];
  858. _this.files = []; // All files
  859. if (typeof _this.element === "string") {
  860. _this.element = document.querySelector(_this.element);
  861. }
  862. // Not checking if instance of HTMLElement or Element since IE9 is extremely weird.
  863. if (!_this.element || _this.element.nodeType == null) {
  864. throw new Error("Invalid dropzone element.");
  865. }
  866. if (_this.element.dropzone) {
  867. throw new Error("Dropzone already attached.");
  868. }
  869. // Now add this dropzone to the instances.
  870. Dropzone.instances.push(_this);
  871. // Put the dropzone inside the element itself.
  872. _this.element.dropzone = _this;
  873. var elementOptions = (left = Dropzone.optionsForElement(_this.element)) != null ? left : {};
  874. _this.options = Dropzone.extend({}, _this.defaultOptions, elementOptions, options != null ? options : {});
  875. // If the browser failed, just call the fallback and leave
  876. if (_this.options.forceFallback || !Dropzone.isBrowserSupported()) {
  877. var _ret;
  878. return _ret = _this.options.fallback.call(_this), _possibleConstructorReturn(_this, _ret);
  879. }
  880. // @options.url = @element.getAttribute "action" unless @options.url?
  881. if (_this.options.url == null) {
  882. _this.options.url = _this.element.getAttribute("action");
  883. }
  884. if (!_this.options.url) {
  885. throw new Error("No URL provided.");
  886. }
  887. if (_this.options.acceptedFiles && _this.options.acceptedMimeTypes) {
  888. throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");
  889. }
  890. if (_this.options.uploadMultiple && _this.options.chunking) {
  891. throw new Error('You cannot set both: uploadMultiple and chunking.');
  892. }
  893. // Backwards compatibility
  894. if (_this.options.acceptedMimeTypes) {
  895. _this.options.acceptedFiles = _this.options.acceptedMimeTypes;
  896. delete _this.options.acceptedMimeTypes;
  897. }
  898. // Backwards compatibility
  899. if (_this.options.renameFilename != null) {
  900. _this.options.renameFile = function (file) {
  901. return _this.options.renameFilename.call(_this, file.name, file);
  902. };
  903. }
  904. _this.options.method = _this.options.method.toUpperCase();
  905. if ((fallback = _this.getExistingFallback()) && fallback.parentNode) {
  906. // Remove the fallback
  907. fallback.parentNode.removeChild(fallback);
  908. }
  909. // Display previews in the previewsContainer element or the Dropzone element unless explicitly set to false
  910. if (_this.options.previewsContainer !== false) {
  911. if (_this.options.previewsContainer) {
  912. _this.previewsContainer = Dropzone.getElement(_this.options.previewsContainer, "previewsContainer");
  913. } else {
  914. _this.previewsContainer = _this.element;
  915. }
  916. }
  917. if (_this.options.clickable) {
  918. if (_this.options.clickable === true) {
  919. _this.clickableElements = [_this.element];
  920. } else {
  921. _this.clickableElements = Dropzone.getElements(_this.options.clickable, "clickable");
  922. }
  923. }
  924. _this.init();
  925. return _this;
  926. }
  927. // Returns all files that have been accepted
  928. _createClass(Dropzone, [{
  929. key: "getAcceptedFiles",
  930. value: function getAcceptedFiles() {
  931. return this.files.filter(function (file) {
  932. return file.accepted;
  933. }).map(function (file) {
  934. return file;
  935. });
  936. }
  937. // Returns all files that have been rejected
  938. // Not sure when that's going to be useful, but added for completeness.
  939. }, {
  940. key: "getRejectedFiles",
  941. value: function getRejectedFiles() {
  942. return this.files.filter(function (file) {
  943. return !file.accepted;
  944. }).map(function (file) {
  945. return file;
  946. });
  947. }
  948. }, {
  949. key: "getFilesWithStatus",
  950. value: function getFilesWithStatus(status) {
  951. return this.files.filter(function (file) {
  952. return file.status === status;
  953. }).map(function (file) {
  954. return file;
  955. });
  956. }
  957. // Returns all files that are in the queue
  958. }, {
  959. key: "getQueuedFiles",
  960. value: function getQueuedFiles() {
  961. return this.getFilesWithStatus(Dropzone.QUEUED);
  962. }
  963. }, {
  964. key: "getUploadingFiles",
  965. value: function getUploadingFiles() {
  966. return this.getFilesWithStatus(Dropzone.UPLOADING);
  967. }
  968. }, {
  969. key: "getAddedFiles",
  970. value: function getAddedFiles() {
  971. return this.getFilesWithStatus(Dropzone.ADDED);
  972. }
  973. // Files that are either queued or uploading
  974. }, {
  975. key: "getActiveFiles",
  976. value: function getActiveFiles() {
  977. return this.files.filter(function (file) {
  978. return file.status === Dropzone.UPLOADING || file.status === Dropzone.QUEUED;
  979. }).map(function (file) {
  980. return file;
  981. });
  982. }
  983. // The function that gets called when Dropzone is initialized. You
  984. // can (and should) setup event listeners inside this function.
  985. }, {
  986. key: "init",
  987. value: function init() {
  988. var _this3 = this;
  989. // In case it isn't set already
  990. if (this.element.tagName === "form") {
  991. this.element.setAttribute("enctype", "multipart/form-data");
  992. }
  993. if (this.element.classList.contains("dropzone") && !this.element.querySelector(".dz-message")) {
  994. this.element.appendChild(Dropzone.createElement("<div class=\"dz-default dz-message\"><span>" + this.options.dictDefaultMessage + "</span></div>"));
  995. }
  996. if (this.clickableElements.length) {
  997. var setupHiddenFileInput = function setupHiddenFileInput() {
  998. if (_this3.hiddenFileInput) {
  999. _this3.hiddenFileInput.parentNode.removeChild(_this3.hiddenFileInput);
  1000. }
  1001. _this3.hiddenFileInput = document.createElement("input");
  1002. _this3.hiddenFileInput.setAttribute("type", "file");
  1003. if (_this3.options.maxFiles === null || _this3.options.maxFiles > 1) {
  1004. _this3.hiddenFileInput.setAttribute("multiple", "multiple");
  1005. }
  1006. _this3.hiddenFileInput.className = "dz-hidden-input";
  1007. if (_this3.options.acceptedFiles !== null) {
  1008. _this3.hiddenFileInput.setAttribute("accept", _this3.options.acceptedFiles);
  1009. }
  1010. if (_this3.options.capture !== null) {
  1011. _this3.hiddenFileInput.setAttribute("capture", _this3.options.capture);
  1012. }
  1013. // Not setting `display="none"` because some browsers don't accept clicks
  1014. // on elements that aren't displayed.
  1015. _this3.hiddenFileInput.style.visibility = "hidden";
  1016. _this3.hiddenFileInput.style.position = "absolute";
  1017. _this3.hiddenFileInput.style.top = "0";
  1018. _this3.hiddenFileInput.style.left = "0";
  1019. _this3.hiddenFileInput.style.height = "0";
  1020. _this3.hiddenFileInput.style.width = "0";
  1021. document.querySelector(_this3.options.hiddenInputContainer).appendChild(_this3.hiddenFileInput);
  1022. return _this3.hiddenFileInput.addEventListener("change", function () {
  1023. var files = _this3.hiddenFileInput.files;
  1024. if (files.length) {
  1025. for (var _iterator10 = files, _isArray10 = true, _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) {
  1026. var _ref9;
  1027. if (_isArray10) {
  1028. if (_i10 >= _iterator10.length) break;
  1029. _ref9 = _iterator10[_i10++];
  1030. } else {
  1031. _i10 = _iterator10.next();
  1032. if (_i10.done) break;
  1033. _ref9 = _i10.value;
  1034. }
  1035. var file = _ref9;
  1036. _this3.addFile(file);
  1037. }
  1038. }
  1039. _this3.emit("addedfiles", files);
  1040. return setupHiddenFileInput();
  1041. });
  1042. };
  1043. setupHiddenFileInput();
  1044. }
  1045. this.URL = window.URL !== null ? window.URL : window.webkitURL;
  1046. // Setup all event listeners on the Dropzone object itself.
  1047. // They're not in @setupEventListeners() because they shouldn't be removed
  1048. // again when the dropzone gets disabled.
  1049. for (var _iterator11 = this.events, _isArray11 = true, _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) {
  1050. var _ref10;
  1051. if (_isArray11) {
  1052. if (_i11 >= _iterator11.length) break;
  1053. _ref10 = _iterator11[_i11++];
  1054. } else {
  1055. _i11 = _iterator11.next();
  1056. if (_i11.done) break;
  1057. _ref10 = _i11.value;
  1058. }
  1059. var eventName = _ref10;
  1060. this.on(eventName, this.options[eventName]);
  1061. }
  1062. this.on("uploadprogress", function () {
  1063. return _this3.updateTotalUploadProgress();
  1064. });
  1065. this.on("removedfile", function () {
  1066. return _this3.updateTotalUploadProgress();
  1067. });
  1068. this.on("canceled", function (file) {
  1069. return _this3.emit("complete", file);
  1070. });
  1071. // Emit a `queuecomplete` event if all files finished uploading.
  1072. this.on("complete", function (file) {
  1073. if (_this3.getAddedFiles().length === 0 && _this3.getUploadingFiles().length === 0 && _this3.getQueuedFiles().length === 0) {
  1074. // This needs to be deferred so that `queuecomplete` really triggers after `complete`
  1075. return setTimeout(function () {
  1076. return _this3.emit("queuecomplete");
  1077. }, 0);
  1078. }
  1079. });
  1080. var noPropagation = function noPropagation(e) {
  1081. e.stopPropagation();
  1082. if (e.preventDefault) {
  1083. return e.preventDefault();
  1084. } else {
  1085. return e.returnValue = false;
  1086. }
  1087. };
  1088. // Create the listeners
  1089. this.listeners = [{
  1090. element: this.element,
  1091. events: {
  1092. "dragstart": function dragstart(e) {
  1093. return _this3.emit("dragstart", e);
  1094. },
  1095. "dragenter": function dragenter(e) {
  1096. noPropagation(e);
  1097. return _this3.emit("dragenter", e);
  1098. },
  1099. "dragover": function dragover(e) {
  1100. // Makes it possible to drag files from chrome's download bar
  1101. // http://stackoverflow.com/questions/19526430/drag-and-drop-file-uploads-from-chrome-downloads-bar
  1102. // Try is required to prevent bug in Internet Explorer 11 (SCRIPT65535 exception)
  1103. var efct = void 0;
  1104. try {
  1105. efct = e.dataTransfer.effectAllowed;
  1106. } catch (error) {}
  1107. e.dataTransfer.dropEffect = 'move' === efct || 'linkMove' === efct ? 'move' : 'copy';
  1108. noPropagation(e);
  1109. return _this3.emit("dragover", e);
  1110. },
  1111. "dragleave": function dragleave(e) {
  1112. return _this3.emit("dragleave", e);
  1113. },
  1114. "drop": function drop(e) {
  1115. noPropagation(e);
  1116. return _this3.drop(e);
  1117. },
  1118. "dragend": function dragend(e) {
  1119. return _this3.emit("dragend", e);
  1120. }
  1121. // This is disabled right now, because the browsers don't implement it properly.
  1122. // "paste": (e) =>
  1123. // noPropagation e
  1124. // @paste e
  1125. } }];
  1126. this.clickableElements.forEach(function (clickableElement) {
  1127. return _this3.listeners.push({
  1128. element: clickableElement,
  1129. events: {
  1130. "click": function click(evt) {
  1131. // Only the actual dropzone or the message element should trigger file selection
  1132. if (clickableElement !== _this3.element || evt.target === _this3.element || Dropzone.elementInside(evt.target, _this3.element.querySelector(".dz-message"))) {
  1133. _this3.hiddenFileInput.click(); // Forward the click
  1134. }
  1135. return true;
  1136. }
  1137. }
  1138. });
  1139. });
  1140. this.enable();
  1141. return this.options.init.call(this);
  1142. }
  1143. // Not fully tested yet
  1144. }, {
  1145. key: "destroy",
  1146. value: function destroy() {
  1147. this.disable();
  1148. this.removeAllFiles(true);
  1149. if (this.hiddenFileInput != null ? this.hiddenFileInput.parentNode : undefined) {
  1150. this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput);
  1151. this.hiddenFileInput = null;
  1152. }
  1153. delete this.element.dropzone;
  1154. return Dropzone.instances.splice(Dropzone.instances.indexOf(this), 1);
  1155. }
  1156. }, {
  1157. key: "updateTotalUploadProgress",
  1158. value: function updateTotalUploadProgress() {
  1159. var totalUploadProgress = void 0;
  1160. var totalBytesSent = 0;
  1161. var totalBytes = 0;
  1162. var activeFiles = this.getActiveFiles();
  1163. if (activeFiles.length) {
  1164. for (var _iterator12 = this.getActiveFiles(), _isArray12 = true, _i12 = 0, _iterator12 = _isArray12 ? _iterator12 : _iterator12[Symbol.iterator]();;) {
  1165. var _ref11;
  1166. if (_isArray12) {
  1167. if (_i12 >= _iterator12.length) break;
  1168. _ref11 = _iterator12[_i12++];
  1169. } else {
  1170. _i12 = _iterator12.next();
  1171. if (_i12.done) break;
  1172. _ref11 = _i12.value;
  1173. }
  1174. var file = _ref11;
  1175. totalBytesSent += file.upload.bytesSent;
  1176. totalBytes += file.upload.total;
  1177. }
  1178. totalUploadProgress = 100 * totalBytesSent / totalBytes;
  1179. } else {
  1180. totalUploadProgress = 100;
  1181. }
  1182. return this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent);
  1183. }
  1184. // @options.paramName can be a function taking one parameter rather than a string.
  1185. // A parameter name for a file is obtained simply by calling this with an index number.
  1186. }, {
  1187. key: "_getParamName",
  1188. value: function _getParamName(n) {
  1189. if (typeof this.options.paramName === "function") {
  1190. return this.options.paramName(n);
  1191. } else {
  1192. return "" + this.options.paramName + (this.options.uploadMultiple ? "[" + n + "]" : "");
  1193. }
  1194. }
  1195. // If @options.renameFile is a function,
  1196. // the function will be used to rename the file.name before appending it to the formData
  1197. }, {
  1198. key: "_renameFile",
  1199. value: function _renameFile(file) {
  1200. if (typeof this.options.renameFile !== "function") {
  1201. return file.name;
  1202. }
  1203. return this.options.renameFile(file);
  1204. }
  1205. // Returns a form that can be used as fallback if the browser does not support DragnDrop
  1206. //
  1207. // If the dropzone is already a form, only the input field and button are returned. Otherwise a complete form element is provided.
  1208. // This code has to pass in IE7 :(
  1209. }, {
  1210. key: "getFallbackForm",
  1211. value: function getFallbackForm() {
  1212. var existingFallback = void 0,
  1213. form = void 0;
  1214. if (existingFallback = this.getExistingFallback()) {
  1215. return existingFallback;
  1216. }
  1217. var fieldsString = "<div class=\"dz-fallback\">";
  1218. if (this.options.dictFallbackText) {
  1219. fieldsString += "<p>" + this.options.dictFallbackText + "</p>";
  1220. }
  1221. fieldsString += "<input type=\"file\" name=\"" + this._getParamName(0) + "\" " + (this.options.uploadMultiple ? 'multiple="multiple"' : undefined) + " /><input type=\"submit\" value=\"Upload!\"></div>";
  1222. var fields = Dropzone.createElement(fieldsString);
  1223. if (this.element.tagName !== "FORM") {
  1224. form = Dropzone.createElement("<form action=\"" + this.options.url + "\" enctype=\"multipart/form-data\" method=\"" + this.options.method + "\"></form>");
  1225. form.appendChild(fields);
  1226. } else {
  1227. // Make sure that the enctype and method attributes are set properly
  1228. this.element.setAttribute("enctype", "multipart/form-data");
  1229. this.element.setAttribute("method", this.options.method);
  1230. }
  1231. return form != null ? form : fields;
  1232. }
  1233. // Returns the fallback elements if they exist already
  1234. //
  1235. // This code has to pass in IE7 :(
  1236. }, {
  1237. key: "getExistingFallback",
  1238. value: function getExistingFallback() {
  1239. var getFallback = function getFallback(elements) {
  1240. for (var _iterator13 = elements, _isArray13 = true, _i13 = 0, _iterator13 = _isArray13 ? _iterator13 : _iterator13[Symbol.iterator]();;) {
  1241. var _ref12;
  1242. if (_isArray13) {
  1243. if (_i13 >= _iterator13.length) break;
  1244. _ref12 = _iterator13[_i13++];
  1245. } else {
  1246. _i13 = _iterator13.next();
  1247. if (_i13.done) break;
  1248. _ref12 = _i13.value;
  1249. }
  1250. var el = _ref12;
  1251. if (/(^| )fallback($| )/.test(el.className)) {
  1252. return el;
  1253. }
  1254. }
  1255. };
  1256. var _arr = ["div", "form"];
  1257. for (var _i14 = 0; _i14 < _arr.length; _i14++) {
  1258. var tagName = _arr[_i14];
  1259. var fallback;
  1260. if (fallback = getFallback(this.element.getElementsByTagName(tagName))) {
  1261. return fallback;
  1262. }
  1263. }
  1264. }
  1265. // Activates all listeners stored in @listeners
  1266. }, {
  1267. key: "setupEventListeners",
  1268. value: function setupEventListeners() {
  1269. return this.listeners.map(function (elementListeners) {
  1270. return function () {
  1271. var result = [];
  1272. for (var event in elementListeners.events) {
  1273. var listener = elementListeners.events[event];
  1274. result.push(elementListeners.element.addEventListener(event, listener, false));
  1275. }
  1276. return result;
  1277. }();
  1278. });
  1279. }
  1280. // Deactivates all listeners stored in @listeners
  1281. }, {
  1282. key: "removeEventListeners",
  1283. value: function removeEventListeners() {
  1284. return this.listeners.map(function (elementListeners) {
  1285. return function () {
  1286. var result = [];
  1287. for (var event in elementListeners.events) {
  1288. var listener = elementListeners.events[event];
  1289. result.push(elementListeners.element.removeEventListener(event, listener, false));
  1290. }
  1291. return result;
  1292. }();
  1293. });
  1294. }
  1295. // Removes all event listeners and cancels all files in the queue or being processed.
  1296. }, {
  1297. key: "disable",
  1298. value: function disable() {
  1299. var _this4 = this;
  1300. this.clickableElements.forEach(function (element) {
  1301. return element.classList.remove("dz-clickable");
  1302. });
  1303. this.removeEventListeners();
  1304. this.disabled = true;
  1305. return this.files.map(function (file) {
  1306. return _this4.cancelUpload(file);
  1307. });
  1308. }
  1309. }, {
  1310. key: "enable",
  1311. value: function enable() {
  1312. delete this.disabled;
  1313. this.clickableElements.forEach(function (element) {
  1314. return element.classList.add("dz-clickable");
  1315. });
  1316. return this.setupEventListeners();
  1317. }
  1318. // Returns a nicely formatted filesize
  1319. }, {
  1320. key: "filesize",
  1321. value: function filesize(size) {
  1322. var selectedSize = 0;
  1323. var selectedUnit = "b";
  1324. if (size > 0) {
  1325. var units = ['tb', 'gb', 'mb', 'kb', 'b'];
  1326. for (var i = 0; i < units.length; i++) {
  1327. var unit = units[i];
  1328. var cutoff = Math.pow(this.options.filesizeBase, 4 - i) / 10;
  1329. if (size >= cutoff) {
  1330. selectedSize = size / Math.pow(this.options.filesizeBase, 4 - i);
  1331. selectedUnit = unit;
  1332. break;
  1333. }
  1334. }
  1335. selectedSize = Math.round(10 * selectedSize) / 10; // Cutting of digits
  1336. }
  1337. return "<strong>" + selectedSize + "</strong> " + this.options.dictFileSizeUnits[selectedUnit];
  1338. }
  1339. // Adds or removes the `dz-max-files-reached` class from the form.
  1340. }, {
  1341. key: "_updateMaxFilesReachedClass",
  1342. value: function _updateMaxFilesReachedClass() {
  1343. if (this.options.maxFiles != null && this.getAcceptedFiles().length >= this.options.maxFiles) {
  1344. if (this.getAcceptedFiles().length === this.options.maxFiles) {
  1345. this.emit('maxfilesreached', this.files);
  1346. }
  1347. return this.element.classList.add("dz-max-files-reached");
  1348. } else {
  1349. return this.element.classList.remove("dz-max-files-reached");
  1350. }
  1351. }
  1352. }, {
  1353. key: "drop",
  1354. value: function drop(e) {
  1355. if (!e.dataTransfer) {
  1356. return;
  1357. }
  1358. this.emit("drop", e);
  1359. // Convert the FileList to an Array
  1360. // This is necessary for IE11
  1361. var files = [];
  1362. for (var i = 0; i < e.dataTransfer.files.length; i++) {
  1363. files[i] = e.dataTransfer.files[i];
  1364. }
  1365. this.emit("addedfiles", files);
  1366. // Even if it's a folder, files.length will contain the folders.
  1367. if (files.length) {
  1368. var items = e.dataTransfer.items;
  1369. if (items && items.length && items[0].webkitGetAsEntry != null) {
  1370. // The browser supports dropping of folders, so handle items instead of files
  1371. this._addFilesFromItems(items);
  1372. } else {
  1373. this.handleFiles(files);
  1374. }
  1375. }
  1376. }
  1377. }, {
  1378. key: "paste",
  1379. value: function paste(e) {
  1380. if (__guard__(e != null ? e.clipboardData : undefined, function (x) {
  1381. return x.items;
  1382. }) == null) {
  1383. return;
  1384. }
  1385. this.emit("paste", e);
  1386. var items = e.clipboardData.items;
  1387. if (items.length) {
  1388. return this._addFilesFromItems(items);
  1389. }
  1390. }
  1391. }, {
  1392. key: "handleFiles",
  1393. value: function handleFiles(files) {
  1394. for (var _iterator14 = files, _isArray14 = true, _i15 = 0, _iterator14 = _isArray14 ? _iterator14 : _iterator14[Symbol.iterator]();;) {
  1395. var _ref13;
  1396. if (_isArray14) {
  1397. if (_i15 >= _iterator14.length) break;
  1398. _ref13 = _iterator14[_i15++];
  1399. } else {
  1400. _i15 = _iterator14.next();
  1401. if (_i15.done) break;
  1402. _ref13 = _i15.value;
  1403. }
  1404. var file = _ref13;
  1405. this.addFile(file);
  1406. }
  1407. }
  1408. // When a folder is dropped (or files are pasted), items must be handled
  1409. // instead of files.
  1410. }, {
  1411. key: "_addFilesFromItems",
  1412. value: function _addFilesFromItems(items) {
  1413. var _this5 = this;
  1414. return function () {
  1415. var result = [];
  1416. for (var _iterator15 = items, _isArray15 = true, _i16 = 0, _iterator15 = _isArray15 ? _iterator15 : _iterator15[Symbol.iterator]();;) {
  1417. var _ref14;
  1418. if (_isArray15) {
  1419. if (_i16 >= _iterator15.length) break;
  1420. _ref14 = _iterator15[_i16++];
  1421. } else {
  1422. _i16 = _iterator15.next();
  1423. if (_i16.done) break;
  1424. _ref14 = _i16.value;
  1425. }
  1426. var item = _ref14;
  1427. var entry;
  1428. if (item.webkitGetAsEntry != null && (entry = item.webkitGetAsEntry())) {
  1429. if (entry.isFile) {
  1430. result.push(_this5.addFile(item.getAsFile()));
  1431. } else if (entry.isDirectory) {
  1432. // Append all files from that directory to files
  1433. result.push(_this5._addFilesFromDirectory(entry, entry.name));
  1434. } else {
  1435. result.push(undefined);
  1436. }
  1437. } else if (item.getAsFile != null) {
  1438. if (item.kind == null || item.kind === "file") {
  1439. result.push(_this5.addFile(item.getAsFile()));
  1440. } else {
  1441. result.push(undefined);
  1442. }
  1443. } else {
  1444. result.push(undefined);
  1445. }
  1446. }
  1447. return result;
  1448. }();
  1449. }
  1450. // Goes through the directory, and adds each file it finds recursively
  1451. }, {
  1452. key: "_addFilesFromDirectory",
  1453. value: function _addFilesFromDirectory(directory, path) {
  1454. var _this6 = this;
  1455. var dirReader = directory.createReader();
  1456. var errorHandler = function errorHandler(error) {
  1457. return __guardMethod__(console, 'log', function (o) {
  1458. return o.log(error);
  1459. });
  1460. };
  1461. var readEntries = function readEntries() {
  1462. return dirReader.readEntries(function (entries) {
  1463. if (entries.length > 0) {
  1464. for (var _iterator16 = entries, _isArray16 = true, _i17 = 0, _iterator16 = _isArray16 ? _iterator16 : _iterator16[Symbol.iterator]();;) {
  1465. var _ref15;
  1466. if (_isArray16) {
  1467. if (_i17 >= _iterator16.length) break;
  1468. _ref15 = _iterator16[_i17++];
  1469. } else {
  1470. _i17 = _iterator16.next();
  1471. if (_i17.done) break;
  1472. _ref15 = _i17.value;
  1473. }
  1474. var entry = _ref15;
  1475. if (entry.isFile) {
  1476. entry.file(function (file) {
  1477. if (_this6.options.ignoreHiddenFiles && file.name.substring(0, 1) === '.') {
  1478. return;
  1479. }
  1480. file.fullPath = path + "/" + file.name;
  1481. return _this6.addFile(file);
  1482. });
  1483. } else if (entry.isDirectory) {
  1484. _this6._addFilesFromDirectory(entry, path + "/" + entry.name);
  1485. }
  1486. }
  1487. // Recursively call readEntries() again, since browser only handle
  1488. // the first 100 entries.
  1489. // See: https://developer.mozilla.org/en-US/docs/Web/API/DirectoryReader#readEntries
  1490. readEntries();
  1491. }
  1492. return null;
  1493. }, errorHandler);
  1494. };
  1495. return readEntries();
  1496. }
  1497. // If `done()` is called without argument the file is accepted
  1498. // If you call it with an error message, the file is rejected
  1499. // (This allows for asynchronous validation)
  1500. //
  1501. // This function checks the filesize, and if the file.type passes the
  1502. // `acceptedFiles` check.
  1503. }, {
  1504. key: "accept",
  1505. value: function accept(file, done) {
  1506. if (this.options.maxFilesize && file.size > this.options.maxFilesize * 1024 * 1024) {
  1507. return done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize));
  1508. } else if (!Dropzone.isValidFile(file, this.options.acceptedFiles)) {
  1509. return done(this.options.dictInvalidFileType);
  1510. } else if (this.options.maxFiles != null && this.getAcceptedFiles().length >= this.options.maxFiles) {
  1511. done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}", this.options.maxFiles));
  1512. return this.emit("maxfilesexceeded", file);
  1513. } else {
  1514. return this.options.accept.call(this, file, done);
  1515. }
  1516. }
  1517. }, {
  1518. key: "addFile",
  1519. value: function addFile(file) {
  1520. var _this7 = this;
  1521. file.upload = {
  1522. uuid: Dropzone.uuidv4(),
  1523. progress: 0,
  1524. // Setting the total upload size to file.size for the beginning
  1525. // It's actual different than the size to be transmitted.
  1526. total: file.size,
  1527. bytesSent: 0,
  1528. filename: this._renameFile(file),
  1529. chunked: this.options.chunking && (this.options.forceChunking || file.size > this.options.chunkSize),
  1530. totalChunkCount: Math.ceil(file.size / this.options.chunkSize)
  1531. };
  1532. this.files.push(file);
  1533. file.status = Dropzone.ADDED;
  1534. this.emit("addedfile", file);
  1535. this._enqueueThumbnail(file);
  1536. return this.accept(file, function (error) {
  1537. if (error) {
  1538. file.accepted = false;
  1539. _this7._errorProcessing([file], error); // Will set the file.status
  1540. } else {
  1541. file.accepted = true;
  1542. if (_this7.options.autoQueue) {
  1543. _this7.enqueueFile(file);
  1544. } // Will set .accepted = true
  1545. }
  1546. return _this7._updateMaxFilesReachedClass();
  1547. });
  1548. }
  1549. // Wrapper for enqueueFile
  1550. }, {
  1551. key: "enqueueFiles",
  1552. value: function enqueueFiles(files) {
  1553. for (var _iterator17 = files, _isArray17 = true, _i18 = 0, _iterator17 = _isArray17 ? _iterator17 : _iterator17[Symbol.iterator]();;) {
  1554. var _ref16;
  1555. if (_isArray17) {
  1556. if (_i18 >= _iterator17.length) break;
  1557. _ref16 = _iterator17[_i18++];
  1558. } else {
  1559. _i18 = _iterator17.next();
  1560. if (_i18.done) break;
  1561. _ref16 = _i18.value;
  1562. }
  1563. var file = _ref16;
  1564. this.enqueueFile(file);
  1565. }
  1566. return null;
  1567. }
  1568. }, {
  1569. key: "enqueueFile",
  1570. value: function enqueueFile(file) {
  1571. var _this8 = this;
  1572. if (file.status === Dropzone.ADDED && file.accepted === true) {
  1573. file.status = Dropzone.QUEUED;
  1574. if (this.options.autoProcessQueue) {
  1575. return setTimeout(function () {
  1576. return _this8.processQueue();
  1577. }, 0); // Deferring the call
  1578. }
  1579. } else {
  1580. throw new Error("This file can't be queued because it has already been processed or was rejected.");
  1581. }
  1582. }
  1583. }, {
  1584. key: "_enqueueThumbnail",
  1585. value: function _enqueueThumbnail(file) {
  1586. var _this9 = this;
  1587. if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) {
  1588. this._thumbnailQueue.push(file);
  1589. return setTimeout(function () {
  1590. return _this9._processThumbnailQueue();
  1591. }, 0); // Deferring the call
  1592. }
  1593. }
  1594. }, {
  1595. key: "_processThumbnailQueue",
  1596. value: function _processThumbnailQueue() {
  1597. var _this10 = this;
  1598. if (this._processingThumbnail || this._thumbnailQueue.length === 0) {
  1599. return;
  1600. }
  1601. this._processingThumbnail = true;
  1602. var file = this._thumbnailQueue.shift();
  1603. return this.createThumbnail(file, this.options.thumbnailWidth, this.options.thumbnailHeight, this.options.thumbnailMethod, true, function (dataUrl) {
  1604. _this10.emit("thumbnail", file, dataUrl);
  1605. _this10._processingThumbnail = false;
  1606. return _this10._processThumbnailQueue();
  1607. });
  1608. }
  1609. // Can be called by the user to remove a file
  1610. }, {
  1611. key: "removeFile",
  1612. value: function removeFile(file) {
  1613. if (file.status === Dropzone.UPLOADING) {
  1614. this.cancelUpload(file);
  1615. }
  1616. this.files = without(this.files, file);
  1617. this.emit("removedfile", file);
  1618. if (this.files.length === 0) {
  1619. return this.emit("reset");
  1620. }
  1621. }
  1622. // Removes all files that aren't currently processed from the list
  1623. }, {
  1624. key: "removeAllFiles",
  1625. value: function removeAllFiles(cancelIfNecessary) {
  1626. // Create a copy of files since removeFile() changes the @files array.
  1627. if (cancelIfNecessary == null) {
  1628. cancelIfNecessary = false;
  1629. }
  1630. for (var _iterator18 = this.files.slice(), _isArray18 = true, _i19 = 0, _iterator18 = _isArray18 ? _iterator18 : _iterator18[Symbol.iterator]();;) {
  1631. var _ref17;
  1632. if (_isArray18) {
  1633. if (_i19 >= _iterator18.length) break;
  1634. _ref17 = _iterator18[_i19++];
  1635. } else {
  1636. _i19 = _iterator18.next();
  1637. if (_i19.done) break;
  1638. _ref17 = _i19.value;
  1639. }
  1640. var file = _ref17;
  1641. if (file.status !== Dropzone.UPLOADING || cancelIfNecessary) {
  1642. this.removeFile(file);
  1643. }
  1644. }
  1645. return null;
  1646. }
  1647. // Resizes an image before it gets sent to the server. This function is the default behavior of
  1648. // `options.transformFile` if `resizeWidth` or `resizeHeight` are set. The callback is invoked with
  1649. // the resized blob.
  1650. }, {
  1651. key: "resizeImage",
  1652. value: function resizeImage(file, width, height, resizeMethod, callback) {
  1653. var _this11 = this;
  1654. return this.createThumbnail(file, width, height, resizeMethod, false, function (dataUrl, canvas) {
  1655. if (canvas == null) {
  1656. // The image has not been resized
  1657. return callback(file);
  1658. } else {
  1659. var resizeMimeType = _this11.options.resizeMimeType;
  1660. if (resizeMimeType == null) {
  1661. resizeMimeType = file.type;
  1662. }
  1663. var resizedDataURL = canvas.toDataURL(resizeMimeType, _this11.options.resizeQuality);
  1664. if (resizeMimeType === 'image/jpeg' || resizeMimeType === 'image/jpg') {
  1665. // Now add the original EXIF information
  1666. resizedDataURL = ExifRestore.restore(file.dataURL, resizedDataURL);
  1667. }
  1668. return callback(Dropzone.dataURItoBlob(resizedDataURL));
  1669. }
  1670. });
  1671. }
  1672. }, {
  1673. key: "createThumbnail",
  1674. value: function createThumbnail(file, width, height, resizeMethod, fixOrientation, callback) {
  1675. var _this12 = this;
  1676. var fileReader = new FileReader();
  1677. fileReader.onload = function () {
  1678. file.dataURL = fileReader.result;
  1679. // Don't bother creating a thumbnail for SVG images since they're vector
  1680. if (file.type === "image/svg+xml") {
  1681. if (callback != null) {
  1682. callback(fileReader.result);
  1683. }
  1684. return;
  1685. }
  1686. return _this12.createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback);
  1687. };
  1688. return fileReader.readAsDataURL(file);
  1689. }
  1690. }, {
  1691. key: "createThumbnailFromUrl",
  1692. value: function createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback, crossOrigin) {
  1693. var _this13 = this;
  1694. // Not using `new Image` here because of a bug in latest Chrome versions.
  1695. // See https://github.com/enyo/dropzone/pull/226
  1696. var img = document.createElement("img");
  1697. if (crossOrigin) {
  1698. img.crossOrigin = crossOrigin;
  1699. }
  1700. img.onload = function () {
  1701. var loadExif = function loadExif(callback) {
  1702. return callback(1);
  1703. };
  1704. if (typeof EXIF !== 'undefined' && EXIF !== null && fixOrientation) {
  1705. loadExif = function loadExif(callback) {
  1706. return EXIF.getData(img, function () {
  1707. return callback(EXIF.getTag(this, 'Orientation'));
  1708. });
  1709. };
  1710. }
  1711. return loadExif(function (orientation) {
  1712. file.width = img.width;
  1713. file.height = img.height;
  1714. var resizeInfo = _this13.options.resize.call(_this13, file, width, height, resizeMethod);
  1715. var canvas = document.createElement("canvas");
  1716. var ctx = canvas.getContext("2d");
  1717. canvas.width = resizeInfo.trgWidth;
  1718. canvas.height = resizeInfo.trgHeight;
  1719. if (orientation > 4) {
  1720. canvas.width = resizeInfo.trgHeight;
  1721. canvas.height = resizeInfo.trgWidth;
  1722. }
  1723. switch (orientation) {
  1724. case 2:
  1725. // horizontal flip
  1726. ctx.translate(canvas.width, 0);
  1727. ctx.scale(-1, 1);
  1728. break;
  1729. case 3:
  1730. // 180° rotate left
  1731. ctx.translate(canvas.width, canvas.height);
  1732. ctx.rotate(Math.PI);
  1733. break;
  1734. case 4:
  1735. // vertical flip
  1736. ctx.translate(0, canvas.height);
  1737. ctx.scale(1, -1);
  1738. break;
  1739. case 5:
  1740. // vertical flip + 90 rotate right
  1741. ctx.rotate(0.5 * Math.PI);
  1742. ctx.scale(1, -1);
  1743. break;
  1744. case 6:
  1745. // 90° rotate right
  1746. ctx.rotate(0.5 * Math.PI);
  1747. ctx.translate(0, -canvas.height);
  1748. break;
  1749. case 7:
  1750. // horizontal flip + 90 rotate right
  1751. ctx.rotate(0.5 * Math.PI);
  1752. ctx.translate(canvas.width, -canvas.height);
  1753. ctx.scale(-1, 1);
  1754. break;
  1755. case 8:
  1756. // 90° rotate left
  1757. ctx.rotate(-0.5 * Math.PI);
  1758. ctx.translate(-canvas.width, 0);
  1759. break;
  1760. }
  1761. // This is a bugfix for iOS' scaling bug.
  1762. 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);
  1763. var thumbnail = canvas.toDataURL("image/png");
  1764. if (callback != null) {
  1765. return callback(thumbnail, canvas);
  1766. }
  1767. });
  1768. };
  1769. if (callback != null) {
  1770. img.onerror = callback;
  1771. }
  1772. return img.src = file.dataURL;
  1773. }
  1774. // Goes through the queue and processes files if there aren't too many already.
  1775. }, {
  1776. key: "processQueue",
  1777. value: function processQueue() {
  1778. var parallelUploads = this.options.parallelUploads;
  1779. var processingLength = this.getUploadingFiles().length;
  1780. var i = processingLength;
  1781. // There are already at least as many files uploading than should be
  1782. if (processingLength >= parallelUploads) {
  1783. return;
  1784. }
  1785. var queuedFiles = this.getQueuedFiles();
  1786. if (!(queuedFiles.length > 0)) {
  1787. return;
  1788. }
  1789. if (this.options.uploadMultiple) {
  1790. // The files should be uploaded in one request
  1791. return this.processFiles(queuedFiles.slice(0, parallelUploads - processingLength));
  1792. } else {
  1793. while (i < parallelUploads) {
  1794. if (!queuedFiles.length) {
  1795. return;
  1796. } // Nothing left to process
  1797. this.processFile(queuedFiles.shift());
  1798. i++;
  1799. }
  1800. }
  1801. }
  1802. // Wrapper for `processFiles`
  1803. }, {
  1804. key: "processFile",
  1805. value: function processFile(file) {
  1806. return this.processFiles([file]);
  1807. }
  1808. // Loads the file, then calls finishedLoading()
  1809. }, {
  1810. key: "processFiles",
  1811. value: function processFiles(files) {
  1812. for (var _iterator19 = files, _isArray19 = true, _i20 = 0, _iterator19 = _isArray19 ? _iterator19 : _iterator19[Symbol.iterator]();;) {
  1813. var _ref18;
  1814. if (_isArray19) {
  1815. if (_i20 >= _iterator19.length) break;
  1816. _ref18 = _iterator19[_i20++];
  1817. } else {
  1818. _i20 = _iterator19.next();
  1819. if (_i20.done) break;
  1820. _ref18 = _i20.value;
  1821. }
  1822. var file = _ref18;
  1823. file.processing = true; // Backwards compatibility
  1824. file.status = Dropzone.UPLOADING;
  1825. this.emit("processing", file);
  1826. }
  1827. if (this.options.uploadMultiple) {
  1828. this.emit("processingmultiple", files);
  1829. }
  1830. return this.uploadFiles(files);
  1831. }
  1832. }, {
  1833. key: "_getFilesWithXhr",
  1834. value: function _getFilesWithXhr(xhr) {
  1835. var files = void 0;
  1836. return files = this.files.filter(function (file) {
  1837. return file.xhr === xhr;
  1838. }).map(function (file) {
  1839. return file;
  1840. });
  1841. }
  1842. // Cancels the file upload and sets the status to CANCELED
  1843. // **if** the file is actually being uploaded.
  1844. // If it's still in the queue, the file is being removed from it and the status
  1845. // set to CANCELED.
  1846. }, {
  1847. key: "cancelUpload",
  1848. value: function cancelUpload(file) {
  1849. if (file.status === Dropzone.UPLOADING) {
  1850. var groupedFiles = this._getFilesWithXhr(file.xhr);
  1851. for (var _iterator20 = groupedFiles, _isArray20 = true, _i21 = 0, _iterator20 = _isArray20 ? _iterator20 : _iterator20[Symbol.iterator]();;) {
  1852. var _ref19;
  1853. if (_isArray20) {
  1854. if (_i21 >= _iterator20.length) break;
  1855. _ref19 = _iterator20[_i21++];
  1856. } else {
  1857. _i21 = _iterator20.next();
  1858. if (_i21.done) break;
  1859. _ref19 = _i21.value;
  1860. }
  1861. var groupedFile = _ref19;
  1862. groupedFile.status = Dropzone.CANCELED;
  1863. }
  1864. if (typeof file.xhr !== 'undefined') {
  1865. file.xhr.abort();
  1866. }
  1867. for (var _iterator21 = groupedFiles, _isArray21 = true, _i22 = 0, _iterator21 = _isArray21 ? _iterator21 : _iterator21[Symbol.iterator]();;) {
  1868. var _ref20;
  1869. if (_isArray21) {
  1870. if (_i22 >= _iterator21.length) break;
  1871. _ref20 = _iterator21[_i22++];
  1872. } else {
  1873. _i22 = _iterator21.next();
  1874. if (_i22.done) break;
  1875. _ref20 = _i22.value;
  1876. }
  1877. var _groupedFile = _ref20;
  1878. this.emit("canceled", _groupedFile);
  1879. }
  1880. if (this.options.uploadMultiple) {
  1881. this.emit("canceledmultiple", groupedFiles);
  1882. }
  1883. } else if (file.status === Dropzone.ADDED || file.status === Dropzone.QUEUED) {
  1884. file.status = Dropzone.CANCELED;
  1885. this.emit("canceled", file);
  1886. if (this.options.uploadMultiple) {
  1887. this.emit("canceledmultiple", [file]);
  1888. }
  1889. }
  1890. if (this.options.autoProcessQueue) {
  1891. return this.processQueue();
  1892. }
  1893. }
  1894. }, {
  1895. key: "resolveOption",
  1896. value: function resolveOption(option) {
  1897. if (typeof option === 'function') {
  1898. for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  1899. args[_key3 - 1] = arguments[_key3];
  1900. }
  1901. return option.apply(this, args);
  1902. }
  1903. return option;
  1904. }
  1905. }, {
  1906. key: "uploadFile",
  1907. value: function uploadFile(file) {
  1908. return this.uploadFiles([file]);
  1909. }
  1910. }, {
  1911. key: "uploadFiles",
  1912. value: function uploadFiles(files) {
  1913. var _this14 = this;
  1914. this._transformFiles(files, function (transformedFiles) {
  1915. if (files[0].upload.chunked) {
  1916. // This file should be sent in chunks!
  1917. // If the chunking option is set, we **know** that there can only be **one** file, since
  1918. // uploadMultiple is not allowed with this option.
  1919. var file = files[0];
  1920. var transformedFile = transformedFiles[0];
  1921. var startedChunkCount = 0;
  1922. file.upload.chunks = [];
  1923. var handleNextChunk = function handleNextChunk() {
  1924. var chunkIndex = 0;
  1925. // Find the next item in file.upload.chunks that is not defined yet.
  1926. while (file.upload.chunks[chunkIndex] !== undefined) {
  1927. chunkIndex++;
  1928. }
  1929. // This means, that all chunks have already been started.
  1930. if (chunkIndex >= file.upload.totalChunkCount) return;
  1931. startedChunkCount++;
  1932. var start = chunkIndex * _this14.options.chunkSize;
  1933. var end = Math.min(start + _this14.options.chunkSize, file.size);
  1934. var dataBlock = {
  1935. name: _this14._getParamName(0),
  1936. data: transformedFile.webkitSlice ? transformedFile.webkitSlice(start, end) : transformedFile.slice(start, end),
  1937. filename: file.upload.filename,
  1938. chunkIndex: chunkIndex
  1939. };
  1940. file.upload.chunks[chunkIndex] = {
  1941. file: file,
  1942. index: chunkIndex,
  1943. dataBlock: dataBlock, // In case we want to retry.
  1944. status: Dropzone.UPLOADING,
  1945. progress: 0,
  1946. retries: 0 // The number of times this block has been retried.
  1947. };
  1948. _this14._uploadData(files, [dataBlock]);
  1949. };
  1950. file.upload.finishedChunkUpload = function (chunk) {
  1951. var allFinished = true;
  1952. chunk.status = Dropzone.SUCCESS;
  1953. // Clear the data from the chunk
  1954. chunk.dataBlock = null;
  1955. for (var i = 0; i < file.upload.totalChunkCount; i++) {
  1956. if (file.upload.chunks[i] === undefined) {
  1957. return handleNextChunk();
  1958. }
  1959. if (file.upload.chunks[i].status !== Dropzone.SUCCESS) {
  1960. allFinished = false;
  1961. }
  1962. }
  1963. if (allFinished) {
  1964. _this14.options.chunksUploaded(file, function () {
  1965. _this14._finished(files, '', null);
  1966. });
  1967. }
  1968. };
  1969. if (_this14.options.parallelChunkUploads) {
  1970. for (var i = 0; i < file.upload.totalChunkCount; i++) {
  1971. handleNextChunk();
  1972. }
  1973. } else {
  1974. handleNextChunk();
  1975. }
  1976. } else {
  1977. var dataBlocks = [];
  1978. for (var _i23 = 0; _i23 < files.length; _i23++) {
  1979. dataBlocks[_i23] = {
  1980. name: _this14._getParamName(_i23),
  1981. data: transformedFiles[_i23],
  1982. filename: files[_i23].upload.filename
  1983. };
  1984. }
  1985. _this14._uploadData(files, dataBlocks);
  1986. }
  1987. });
  1988. }
  1989. /// Returns the right chunk for given file and xhr
  1990. }, {
  1991. key: "_getChunk",
  1992. value: function _getChunk(file, xhr) {
  1993. for (var i = 0; i < file.upload.totalChunkCount; i++) {
  1994. if (file.upload.chunks[i] !== undefined && file.upload.chunks[i].xhr === xhr) {
  1995. return file.upload.chunks[i];
  1996. }
  1997. }
  1998. }
  1999. // This function actually uploads the file(s) to the server.
  2000. // If dataBlocks contains the actual data to upload (meaning, that this could either be transformed
  2001. // files, or individual chunks for chunked upload).
  2002. }, {
  2003. key: "_uploadData",
  2004. value: function _uploadData(files, dataBlocks) {
  2005. var _this15 = this;
  2006. var xhr = new XMLHttpRequest();
  2007. // Put the xhr object in the file objects to be able to reference it later.
  2008. for (var _iterator22 = files, _isArray22 = true, _i24 = 0, _iterator22 = _isArray22 ? _iterator22 : _iterator22[Symbol.iterator]();;) {
  2009. var _ref21;
  2010. if (_isArray22) {
  2011. if (_i24 >= _iterator22.length) break;
  2012. _ref21 = _iterator22[_i24++];
  2013. } else {
  2014. _i24 = _iterator22.next();
  2015. if (_i24.done) break;
  2016. _ref21 = _i24.value;
  2017. }
  2018. var file = _ref21;
  2019. file.xhr = xhr;
  2020. }
  2021. if (files[0].upload.chunked) {
  2022. // Put the xhr object in the right chunk object, so it can be associated later, and found with _getChunk
  2023. files[0].upload.chunks[dataBlocks[0].chunkIndex].xhr = xhr;
  2024. }
  2025. var method = this.resolveOption(this.options.method, files);
  2026. var url = this.resolveOption(this.options.url, files);
  2027. xhr.open(method, url, true);
  2028. // Setting the timeout after open because of IE11 issue: https://gitlab.com/meno/dropzone/issues/8
  2029. xhr.timeout = this.resolveOption(this.options.timeout, files);
  2030. // Has to be after `.open()`. See https://github.com/enyo/dropzone/issues/179
  2031. xhr.withCredentials = !!this.options.withCredentials;
  2032. xhr.onload = function (e) {
  2033. _this15._finishedUploading(files, xhr, e);
  2034. };
  2035. xhr.onerror = function () {
  2036. _this15._handleUploadError(files, xhr);
  2037. };
  2038. // Some browsers do not have the .upload property
  2039. var progressObj = xhr.upload != null ? xhr.upload : xhr;
  2040. progressObj.onprogress = function (e) {
  2041. return _this15._updateFilesUploadProgress(files, xhr, e);
  2042. };
  2043. var headers = {
  2044. "Accept": "application/json",
  2045. "Cache-Control": "no-cache",
  2046. "X-Requested-With": "XMLHttpRequest"
  2047. };
  2048. if (this.options.headers) {
  2049. Dropzone.extend(headers, this.options.headers);
  2050. }
  2051. for (var headerName in headers) {
  2052. var headerValue = headers[headerName];
  2053. if (headerValue) {
  2054. xhr.setRequestHeader(headerName, headerValue);
  2055. }
  2056. }
  2057. var formData = new FormData();
  2058. // Adding all @options parameters
  2059. if (this.options.params) {
  2060. var additionalParams = this.options.params;
  2061. if (typeof additionalParams === 'function') {
  2062. additionalParams = additionalParams.call(this, files, xhr, files[0].upload.chunked ? this._getChunk(files[0], xhr) : null);
  2063. }
  2064. for (var key in additionalParams) {
  2065. var value = additionalParams[key];
  2066. formData.append(key, value);
  2067. }
  2068. }
  2069. // Let the user add additional data if necessary
  2070. for (var _iterator23 = files, _isArray23 = true, _i25 = 0, _iterator23 = _isArray23 ? _iterator23 : _iterator23[Symbol.iterator]();;) {
  2071. var _ref22;
  2072. if (_isArray23) {
  2073. if (_i25 >= _iterator23.length) break;
  2074. _ref22 = _iterator23[_i25++];
  2075. } else {
  2076. _i25 = _iterator23.next();
  2077. if (_i25.done) break;
  2078. _ref22 = _i25.value;
  2079. }
  2080. var _file = _ref22;
  2081. this.emit("sending", _file, xhr, formData);
  2082. }
  2083. if (this.options.uploadMultiple) {
  2084. this.emit("sendingmultiple", files, xhr, formData);
  2085. }
  2086. this._addFormElementData(formData);
  2087. // Finally add the files
  2088. // Has to be last because some servers (eg: S3) expect the file to be the last parameter
  2089. for (var i = 0; i < dataBlocks.length; i++) {
  2090. var dataBlock = dataBlocks[i];
  2091. formData.append(dataBlock.name, dataBlock.data, dataBlock.filename);
  2092. }
  2093. this.submitRequest(xhr, formData, files);
  2094. }
  2095. // Transforms all files with this.options.transformFile and invokes done with the transformed files when done.
  2096. }, {
  2097. key: "_transformFiles",
  2098. value: function _transformFiles(files, done) {
  2099. var _this16 = this;
  2100. var transformedFiles = [];
  2101. // Clumsy way of handling asynchronous calls, until I get to add a proper Future library.
  2102. var doneCounter = 0;
  2103. var _loop = function _loop(i) {
  2104. _this16.options.transformFile.call(_this16, files[i], function (transformedFile) {
  2105. transformedFiles[i] = transformedFile;
  2106. if (++doneCounter === files.length) {
  2107. done(transformedFiles);
  2108. }
  2109. });
  2110. };
  2111. for (var i = 0; i < files.length; i++) {
  2112. _loop(i);
  2113. }
  2114. }
  2115. // Takes care of adding other input elements of the form to the AJAX request
  2116. }, {
  2117. key: "_addFormElementData",
  2118. value: function _addFormElementData(formData) {
  2119. // Take care of other input elements
  2120. if (this.element.tagName === "FORM") {
  2121. for (var _iterator24 = this.element.querySelectorAll("input, textarea, select, button"), _isArray24 = true, _i26 = 0, _iterator24 = _isArray24 ? _iterator24 : _iterator24[Symbol.iterator]();;) {
  2122. var _ref23;
  2123. if (_isArray24) {
  2124. if (_i26 >= _iterator24.length) break;
  2125. _ref23 = _iterator24[_i26++];
  2126. } else {
  2127. _i26 = _iterator24.next();
  2128. if (_i26.done) break;
  2129. _ref23 = _i26.value;
  2130. }
  2131. var input = _ref23;
  2132. var inputName = input.getAttribute("name");
  2133. var inputType = input.getAttribute("type");
  2134. if (inputType) inputType = inputType.toLowerCase();
  2135. // If the input doesn't have a name, we can't use it.
  2136. if (typeof inputName === 'undefined' || inputName === null) continue;
  2137. if (input.tagName === "SELECT" && input.hasAttribute("multiple")) {
  2138. // Possibly multiple values
  2139. for (var _iterator25 = input.options, _isArray25 = true, _i27 = 0, _iterator25 = _isArray25 ? _iterator25 : _iterator25[Symbol.iterator]();;) {
  2140. var _ref24;
  2141. if (_isArray25) {
  2142. if (_i27 >= _iterator25.length) break;
  2143. _ref24 = _iterator25[_i27++];
  2144. } else {
  2145. _i27 = _iterator25.next();
  2146. if (_i27.done) break;
  2147. _ref24 = _i27.value;
  2148. }
  2149. var option = _ref24;
  2150. if (option.selected) {
  2151. formData.append(inputName, option.value);
  2152. }
  2153. }
  2154. } else if (!inputType || inputType !== "checkbox" && inputType !== "radio" || input.checked) {
  2155. formData.append(inputName, input.value);
  2156. }
  2157. }
  2158. }
  2159. }
  2160. // Invoked when there is new progress information about given files.
  2161. // If e is not provided, it is assumed that the upload is finished.
  2162. }, {
  2163. key: "_updateFilesUploadProgress",
  2164. value: function _updateFilesUploadProgress(files, xhr, e) {
  2165. var progress = void 0;
  2166. if (typeof e !== 'undefined') {
  2167. progress = 100 * e.loaded / e.total;
  2168. if (files[0].upload.chunked) {
  2169. var file = files[0];
  2170. // Since this is a chunked upload, we need to update the appropriate chunk progress.
  2171. var chunk = this._getChunk(file, xhr);
  2172. chunk.progress = progress;
  2173. chunk.total = e.total;
  2174. chunk.bytesSent = e.loaded;
  2175. var fileProgress = 0,
  2176. fileTotal = void 0,
  2177. fileBytesSent = void 0;
  2178. file.upload.progress = 0;
  2179. file.upload.total = 0;
  2180. file.upload.bytesSent = 0;
  2181. for (var i = 0; i < file.upload.totalChunkCount; i++) {
  2182. if (file.upload.chunks[i] !== undefined && file.upload.chunks[i].progress !== undefined) {
  2183. file.upload.progress += file.upload.chunks[i].progress;
  2184. file.upload.total += file.upload.chunks[i].total;
  2185. file.upload.bytesSent += file.upload.chunks[i].bytesSent;
  2186. }
  2187. }
  2188. file.upload.progress = file.upload.progress / file.upload.totalChunkCount;
  2189. } else {
  2190. for (var _iterator26 = files, _isArray26 = true, _i28 = 0, _iterator26 = _isArray26 ? _iterator26 : _iterator26[Symbol.iterator]();;) {
  2191. var _ref25;
  2192. if (_isArray26) {
  2193. if (_i28 >= _iterator26.length) break;
  2194. _ref25 = _iterator26[_i28++];
  2195. } else {
  2196. _i28 = _iterator26.next();
  2197. if (_i28.done) break;
  2198. _ref25 = _i28.value;
  2199. }
  2200. var _file2 = _ref25;
  2201. _file2.upload.progress = progress;
  2202. _file2.upload.total = e.total;
  2203. _file2.upload.bytesSent = e.loaded;
  2204. }
  2205. }
  2206. for (var _iterator27 = files, _isArray27 = true, _i29 = 0, _iterator27 = _isArray27 ? _iterator27 : _iterator27[Symbol.iterator]();;) {
  2207. var _ref26;
  2208. if (_isArray27) {
  2209. if (_i29 >= _iterator27.length) break;
  2210. _ref26 = _iterator27[_i29++];
  2211. } else {
  2212. _i29 = _iterator27.next();
  2213. if (_i29.done) break;
  2214. _ref26 = _i29.value;
  2215. }
  2216. var _file3 = _ref26;
  2217. this.emit("uploadprogress", _file3, _file3.upload.progress, _file3.upload.bytesSent);
  2218. }
  2219. } else {
  2220. // Called when the file finished uploading
  2221. var allFilesFinished = true;
  2222. progress = 100;
  2223. for (var _iterator28 = files, _isArray28 = true, _i30 = 0, _iterator28 = _isArray28 ? _iterator28 : _iterator28[Symbol.iterator]();;) {
  2224. var _ref27;
  2225. if (_isArray28) {
  2226. if (_i30 >= _iterator28.length) break;
  2227. _ref27 = _iterator28[_i30++];
  2228. } else {
  2229. _i30 = _iterator28.next();
  2230. if (_i30.done) break;
  2231. _ref27 = _i30.value;
  2232. }
  2233. var _file4 = _ref27;
  2234. if (_file4.upload.progress !== 100 || _file4.upload.bytesSent !== _file4.upload.total) {
  2235. allFilesFinished = false;
  2236. }
  2237. _file4.upload.progress = progress;
  2238. _file4.upload.bytesSent = _file4.upload.total;
  2239. }
  2240. // Nothing to do, all files already at 100%
  2241. if (allFilesFinished) {
  2242. return;
  2243. }
  2244. for (var _iterator29 = files, _isArray29 = true, _i31 = 0, _iterator29 = _isArray29 ? _iterator29 : _iterator29[Symbol.iterator]();;) {
  2245. var _ref28;
  2246. if (_isArray29) {
  2247. if (_i31 >= _iterator29.length) break;
  2248. _ref28 = _iterator29[_i31++];
  2249. } else {
  2250. _i31 = _iterator29.next();
  2251. if (_i31.done) break;
  2252. _ref28 = _i31.value;
  2253. }
  2254. var _file5 = _ref28;
  2255. this.emit("uploadprogress", _file5, progress, _file5.upload.bytesSent);
  2256. }
  2257. }
  2258. }
  2259. }, {
  2260. key: "_finishedUploading",
  2261. value: function _finishedUploading(files, xhr, e) {
  2262. var response = void 0;
  2263. if (files[0].status === Dropzone.CANCELED) {
  2264. return;
  2265. }
  2266. if (xhr.readyState !== 4) {
  2267. return;
  2268. }
  2269. if (xhr.responseType !== 'arraybuffer' && xhr.responseType !== 'blob') {
  2270. response = xhr.responseText;
  2271. if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
  2272. try {
  2273. response = JSON.parse(response);
  2274. } catch (error) {
  2275. e = error;
  2276. response = "Invalid JSON response from server.";
  2277. }
  2278. }
  2279. }
  2280. this._updateFilesUploadProgress(files);
  2281. if (!(200 <= xhr.status && xhr.status < 300)) {
  2282. this._handleUploadError(files, xhr, response);
  2283. } else {
  2284. if (files[0].upload.chunked) {
  2285. files[0].upload.finishedChunkUpload(this._getChunk(files[0], xhr));
  2286. } else {
  2287. this._finished(files, response, e);
  2288. }
  2289. }
  2290. }
  2291. }, {
  2292. key: "_handleUploadError",
  2293. value: function _handleUploadError(files, xhr, response) {
  2294. if (files[0].status === Dropzone.CANCELED) {
  2295. return;
  2296. }
  2297. if (files[0].upload.chunked && this.options.retryChunks) {
  2298. var chunk = this._getChunk(files[0], xhr);
  2299. if (chunk.retries++ < this.options.retryChunksLimit) {
  2300. this._uploadData(files, [chunk.dataBlock]);
  2301. return;
  2302. } else {
  2303. console.warn('Retried this chunk too often. Giving up.');
  2304. }
  2305. }
  2306. for (var _iterator30 = files, _isArray30 = true, _i32 = 0, _iterator30 = _isArray30 ? _iterator30 : _iterator30[Symbol.iterator]();;) {
  2307. var _ref29;
  2308. if (_isArray30) {
  2309. if (_i32 >= _iterator30.length) break;
  2310. _ref29 = _iterator30[_i32++];
  2311. } else {
  2312. _i32 = _iterator30.next();
  2313. if (_i32.done) break;
  2314. _ref29 = _i32.value;
  2315. }
  2316. var file = _ref29;
  2317. this._errorProcessing(files, response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr);
  2318. }
  2319. }
  2320. }, {
  2321. key: "submitRequest",
  2322. value: function submitRequest(xhr, formData, files) {
  2323. xhr.send(formData);
  2324. }
  2325. // Called internally when processing is finished.
  2326. // Individual callbacks have to be called in the appropriate sections.
  2327. }, {
  2328. key: "_finished",
  2329. value: function _finished(files, responseText, e) {
  2330. for (var _iterator31 = files, _isArray31 = true, _i33 = 0, _iterator31 = _isArray31 ? _iterator31 : _iterator31[Symbol.iterator]();;) {
  2331. var _ref30;
  2332. if (_isArray31) {
  2333. if (_i33 >= _iterator31.length) break;
  2334. _ref30 = _iterator31[_i33++];
  2335. } else {
  2336. _i33 = _iterator31.next();
  2337. if (_i33.done) break;
  2338. _ref30 = _i33.value;
  2339. }
  2340. var file = _ref30;
  2341. file.status = Dropzone.SUCCESS;
  2342. this.emit("success", file, responseText, e);
  2343. this.emit("complete", file);
  2344. }
  2345. if (this.options.uploadMultiple) {
  2346. this.emit("successmultiple", files, responseText, e);
  2347. this.emit("completemultiple", files);
  2348. }
  2349. if (this.options.autoProcessQueue) {
  2350. return this.processQueue();
  2351. }
  2352. }
  2353. // Called internally when processing is finished.
  2354. // Individual callbacks have to be called in the appropriate sections.
  2355. }, {
  2356. key: "_errorProcessing",
  2357. value: function _errorProcessing(files, message, xhr) {
  2358. for (var _iterator32 = files, _isArray32 = true, _i34 = 0, _iterator32 = _isArray32 ? _iterator32 : _iterator32[Symbol.iterator]();;) {
  2359. var _ref31;
  2360. if (_isArray32) {
  2361. if (_i34 >= _iterator32.length) break;
  2362. _ref31 = _iterator32[_i34++];
  2363. } else {
  2364. _i34 = _iterator32.next();
  2365. if (_i34.done) break;
  2366. _ref31 = _i34.value;
  2367. }
  2368. var file = _ref31;
  2369. file.status = Dropzone.ERROR;
  2370. this.emit("error", file, message, xhr);
  2371. this.emit("complete", file);
  2372. }
  2373. if (this.options.uploadMultiple) {
  2374. this.emit("errormultiple", files, message, xhr);
  2375. this.emit("completemultiple", files);
  2376. }
  2377. if (this.options.autoProcessQueue) {
  2378. return this.processQueue();
  2379. }
  2380. }
  2381. }], [{
  2382. key: "uuidv4",
  2383. value: function uuidv4() {
  2384. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  2385. var r = Math.random() * 16 | 0,
  2386. v = c === 'x' ? r : r & 0x3 | 0x8;
  2387. return v.toString(16);
  2388. });
  2389. }
  2390. }]);
  2391. return Dropzone;
  2392. }(Emitter);
  2393. Dropzone.initClass();
  2394. Dropzone.version = "5.4.0";
  2395. // This is a map of options for your different dropzones. Add configurations
  2396. // to this object for your different dropzone elemens.
  2397. //
  2398. // Example:
  2399. //
  2400. // Dropzone.options.myDropzoneElementId = { maxFilesize: 1 };
  2401. //
  2402. // To disable autoDiscover for a specific element, you can set `false` as an option:
  2403. //
  2404. // Dropzone.options.myDisabledElementId = false;
  2405. //
  2406. // And in html:
  2407. //
  2408. // <form action="/upload" id="my-dropzone-element-id" class="dropzone"></form>
  2409. Dropzone.options = {};
  2410. // Returns the options for an element or undefined if none available.
  2411. Dropzone.optionsForElement = function (element) {
  2412. // Get the `Dropzone.options.elementId` for this element if it exists
  2413. if (element.getAttribute("id")) {
  2414. return Dropzone.options[camelize(element.getAttribute("id"))];
  2415. } else {
  2416. return undefined;
  2417. }
  2418. };
  2419. // Holds a list of all dropzone instances
  2420. Dropzone.instances = [];
  2421. // Returns the dropzone for given element if any
  2422. Dropzone.forElement = function (element) {
  2423. if (typeof element === "string") {
  2424. element = document.querySelector(element);
  2425. }
  2426. if ((element != null ? element.dropzone : undefined) == null) {
  2427. 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.");
  2428. }
  2429. return element.dropzone;
  2430. };
  2431. // Set to false if you don't want Dropzone to automatically find and attach to .dropzone elements.
  2432. Dropzone.autoDiscover = true;
  2433. // Looks for all .dropzone elements and creates a dropzone for them
  2434. Dropzone.discover = function () {
  2435. var dropzones = void 0;
  2436. if (document.querySelectorAll) {
  2437. dropzones = document.querySelectorAll(".dropzone");
  2438. } else {
  2439. dropzones = [];
  2440. // IE :(
  2441. var checkElements = function checkElements(elements) {
  2442. return function () {
  2443. var result = [];
  2444. for (var _iterator33 = elements, _isArray33 = true, _i35 = 0, _iterator33 = _isArray33 ? _iterator33 : _iterator33[Symbol.iterator]();;) {
  2445. var _ref32;
  2446. if (_isArray33) {
  2447. if (_i35 >= _iterator33.length) break;
  2448. _ref32 = _iterator33[_i35++];
  2449. } else {
  2450. _i35 = _iterator33.next();
  2451. if (_i35.done) break;
  2452. _ref32 = _i35.value;
  2453. }
  2454. var el = _ref32;
  2455. if (/(^| )dropzone($| )/.test(el.className)) {
  2456. result.push(dropzones.push(el));
  2457. } else {
  2458. result.push(undefined);
  2459. }
  2460. }
  2461. return result;
  2462. }();
  2463. };
  2464. checkElements(document.getElementsByTagName("div"));
  2465. checkElements(document.getElementsByTagName("form"));
  2466. }
  2467. return function () {
  2468. var result = [];
  2469. for (var _iterator34 = dropzones, _isArray34 = true, _i36 = 0, _iterator34 = _isArray34 ? _iterator34 : _iterator34[Symbol.iterator]();;) {
  2470. var _ref33;
  2471. if (_isArray34) {
  2472. if (_i36 >= _iterator34.length) break;
  2473. _ref33 = _iterator34[_i36++];
  2474. } else {
  2475. _i36 = _iterator34.next();
  2476. if (_i36.done) break;
  2477. _ref33 = _i36.value;
  2478. }
  2479. var dropzone = _ref33;
  2480. // Create a dropzone unless auto discover has been disabled for specific element
  2481. if (Dropzone.optionsForElement(dropzone) !== false) {
  2482. result.push(new Dropzone(dropzone));
  2483. } else {
  2484. result.push(undefined);
  2485. }
  2486. }
  2487. return result;
  2488. }();
  2489. };
  2490. // Since the whole Drag'n'Drop API is pretty new, some browsers implement it,
  2491. // but not correctly.
  2492. // So I created a blacklist of userAgents. Yes, yes. Browser sniffing, I know.
  2493. // But what to do when browsers *theoretically* support an API, but crash
  2494. // when using it.
  2495. //
  2496. // This is a list of regular expressions tested against navigator.userAgent
  2497. //
  2498. // ** It should only be used on browser that *do* support the API, but
  2499. // incorrectly **
  2500. //
  2501. Dropzone.blacklistedBrowsers = [
  2502. // The mac os and windows phone version of opera 12 seems to have a problem with the File drag'n'drop API.
  2503. /opera.*(Macintosh|Windows Phone).*version\/12/i];
  2504. // Checks if the browser is supported
  2505. Dropzone.isBrowserSupported = function () {
  2506. var capableBrowser = true;
  2507. if (window.File && window.FileReader && window.FileList && window.Blob && window.FormData && document.querySelector) {
  2508. if (!("classList" in document.createElement("a"))) {
  2509. capableBrowser = false;
  2510. } else {
  2511. // The browser supports the API, but may be blacklisted.
  2512. for (var _iterator35 = Dropzone.blacklistedBrowsers, _isArray35 = true, _i37 = 0, _iterator35 = _isArray35 ? _iterator35 : _iterator35[Symbol.iterator]();;) {
  2513. var _ref34;
  2514. if (_isArray35) {
  2515. if (_i37 >= _iterator35.length) break;
  2516. _ref34 = _iterator35[_i37++];
  2517. } else {
  2518. _i37 = _iterator35.next();
  2519. if (_i37.done) break;
  2520. _ref34 = _i37.value;
  2521. }
  2522. var regex = _ref34;
  2523. if (regex.test(navigator.userAgent)) {
  2524. capableBrowser = false;
  2525. continue;
  2526. }
  2527. }
  2528. }
  2529. } else {
  2530. capableBrowser = false;
  2531. }
  2532. return capableBrowser;
  2533. };
  2534. Dropzone.dataURItoBlob = function (dataURI) {
  2535. // convert base64 to raw binary data held in a string
  2536. // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
  2537. var byteString = atob(dataURI.split(',')[1]);
  2538. // separate out the mime component
  2539. var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
  2540. // write the bytes of the string to an ArrayBuffer
  2541. var ab = new ArrayBuffer(byteString.length);
  2542. var ia = new Uint8Array(ab);
  2543. for (var i = 0, end = byteString.length, asc = 0 <= end; asc ? i <= end : i >= end; asc ? i++ : i--) {
  2544. ia[i] = byteString.charCodeAt(i);
  2545. }
  2546. // write the ArrayBuffer to a blob
  2547. return new Blob([ab], { type: mimeString });
  2548. };
  2549. // Returns an array without the rejected item
  2550. var without = function without(list, rejectedItem) {
  2551. return list.filter(function (item) {
  2552. return item !== rejectedItem;
  2553. }).map(function (item) {
  2554. return item;
  2555. });
  2556. };
  2557. // abc-def_ghi -> abcDefGhi
  2558. var camelize = function camelize(str) {
  2559. return str.replace(/[\-_](\w)/g, function (match) {
  2560. return match.charAt(1).toUpperCase();
  2561. });
  2562. };
  2563. // Creates an element from string
  2564. Dropzone.createElement = function (string) {
  2565. var div = document.createElement("div");
  2566. div.innerHTML = string;
  2567. return div.childNodes[0];
  2568. };
  2569. // Tests if given element is inside (or simply is) the container
  2570. Dropzone.elementInside = function (element, container) {
  2571. if (element === container) {
  2572. return true;
  2573. } // Coffeescript doesn't support do/while loops
  2574. while (element = element.parentNode) {
  2575. if (element === container) {
  2576. return true;
  2577. }
  2578. }
  2579. return false;
  2580. };
  2581. Dropzone.getElement = function (el, name) {
  2582. var element = void 0;
  2583. if (typeof el === "string") {
  2584. element = document.querySelector(el);
  2585. } else if (el.nodeType != null) {
  2586. element = el;
  2587. }
  2588. if (element == null) {
  2589. throw new Error("Invalid `" + name + "` option provided. Please provide a CSS selector or a plain HTML element.");
  2590. }
  2591. return element;
  2592. };
  2593. Dropzone.getElements = function (els, name) {
  2594. var el = void 0,
  2595. elements = void 0;
  2596. if (els instanceof Array) {
  2597. elements = [];
  2598. try {
  2599. for (var _iterator36 = els, _isArray36 = true, _i38 = 0, _iterator36 = _isArray36 ? _iterator36 : _iterator36[Symbol.iterator]();;) {
  2600. if (_isArray36) {
  2601. if (_i38 >= _iterator36.length) break;
  2602. el = _iterator36[_i38++];
  2603. } else {
  2604. _i38 = _iterator36.next();
  2605. if (_i38.done) break;
  2606. el = _i38.value;
  2607. }
  2608. elements.push(this.getElement(el, name));
  2609. }
  2610. } catch (e) {
  2611. elements = null;
  2612. }
  2613. } else if (typeof els === "string") {
  2614. elements = [];
  2615. for (var _iterator37 = document.querySelectorAll(els), _isArray37 = true, _i39 = 0, _iterator37 = _isArray37 ? _iterator37 : _iterator37[Symbol.iterator]();;) {
  2616. if (_isArray37) {
  2617. if (_i39 >= _iterator37.length) break;
  2618. el = _iterator37[_i39++];
  2619. } else {
  2620. _i39 = _iterator37.next();
  2621. if (_i39.done) break;
  2622. el = _i39.value;
  2623. }
  2624. elements.push(el);
  2625. }
  2626. } else if (els.nodeType != null) {
  2627. elements = [els];
  2628. }
  2629. if (elements == null || !elements.length) {
  2630. throw new Error("Invalid `" + name + "` option provided. Please provide a CSS selector, a plain HTML element or a list of those.");
  2631. }
  2632. return elements;
  2633. };
  2634. // Asks the user the question and calls accepted or rejected accordingly
  2635. //
  2636. // The default implementation just uses `window.confirm` and then calls the
  2637. // appropriate callback.
  2638. Dropzone.confirm = function (question, accepted, rejected) {
  2639. if (window.confirm(question)) {
  2640. return accepted();
  2641. } else if (rejected != null) {
  2642. return rejected();
  2643. }
  2644. };
  2645. // Validates the mime type like this:
  2646. //
  2647. // https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-accept
  2648. Dropzone.isValidFile = function (file, acceptedFiles) {
  2649. if (!acceptedFiles) {
  2650. return true;
  2651. } // If there are no accepted mime types, it's OK
  2652. acceptedFiles = acceptedFiles.split(",");
  2653. var mimeType = file.type;
  2654. var baseMimeType = mimeType.replace(/\/.*$/, "");
  2655. for (var _iterator38 = acceptedFiles, _isArray38 = true, _i40 = 0, _iterator38 = _isArray38 ? _iterator38 : _iterator38[Symbol.iterator]();;) {
  2656. var _ref35;
  2657. if (_isArray38) {
  2658. if (_i40 >= _iterator38.length) break;
  2659. _ref35 = _iterator38[_i40++];
  2660. } else {
  2661. _i40 = _iterator38.next();
  2662. if (_i40.done) break;
  2663. _ref35 = _i40.value;
  2664. }
  2665. var validType = _ref35;
  2666. validType = validType.trim();
  2667. if (validType.charAt(0) === ".") {
  2668. if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) {
  2669. return true;
  2670. }
  2671. } else if (/\/\*$/.test(validType)) {
  2672. // This is something like a image/* mime type
  2673. if (baseMimeType === validType.replace(/\/.*$/, "")) {
  2674. return true;
  2675. }
  2676. } else {
  2677. if (mimeType === validType) {
  2678. return true;
  2679. }
  2680. }
  2681. }
  2682. return false;
  2683. };
  2684. // Augment jQuery
  2685. if (typeof jQuery !== 'undefined' && jQuery !== null) {
  2686. jQuery.fn.dropzone = function (options) {
  2687. return this.each(function () {
  2688. return new Dropzone(this, options);
  2689. });
  2690. };
  2691. }
  2692. if (typeof module !== 'undefined' && module !== null) {
  2693. module.exports = Dropzone;
  2694. } else {
  2695. window.Dropzone = Dropzone;
  2696. }
  2697. // Dropzone file status codes
  2698. Dropzone.ADDED = "added";
  2699. Dropzone.QUEUED = "queued";
  2700. // For backwards compatibility. Now, if a file is accepted, it's either queued
  2701. // or uploading.
  2702. Dropzone.ACCEPTED = Dropzone.QUEUED;
  2703. Dropzone.UPLOADING = "uploading";
  2704. Dropzone.PROCESSING = Dropzone.UPLOADING; // alias
  2705. Dropzone.CANCELED = "canceled";
  2706. Dropzone.ERROR = "error";
  2707. Dropzone.SUCCESS = "success";
  2708. /*
  2709. Bugfix for iOS 6 and 7
  2710. Source: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
  2711. based on the work of https://github.com/stomita/ios-imagefile-megapixel
  2712. */
  2713. // Detecting vertical squash in loaded image.
  2714. // Fixes a bug which squash image vertically while drawing into canvas for some images.
  2715. // This is a bug in iOS6 devices. This function from https://github.com/stomita/ios-imagefile-megapixel
  2716. var detectVerticalSquash = function detectVerticalSquash(img) {
  2717. var iw = img.naturalWidth;
  2718. var ih = img.naturalHeight;
  2719. var canvas = document.createElement("canvas");
  2720. canvas.width = 1;
  2721. canvas.height = ih;
  2722. var ctx = canvas.getContext("2d");
  2723. ctx.drawImage(img, 0, 0);
  2724. var _ctx$getImageData = ctx.getImageData(1, 0, 1, ih),
  2725. data = _ctx$getImageData.data;
  2726. // search image edge pixel position in case it is squashed vertically.
  2727. var sy = 0;
  2728. var ey = ih;
  2729. var py = ih;
  2730. while (py > sy) {
  2731. var alpha = data[(py - 1) * 4 + 3];
  2732. if (alpha === 0) {
  2733. ey = py;
  2734. } else {
  2735. sy = py;
  2736. }
  2737. py = ey + sy >> 1;
  2738. }
  2739. var ratio = py / ih;
  2740. if (ratio === 0) {
  2741. return 1;
  2742. } else {
  2743. return ratio;
  2744. }
  2745. };
  2746. // A replacement for context.drawImage
  2747. // (args are for source and destination).
  2748. var drawImageIOSFix = function drawImageIOSFix(ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) {
  2749. var vertSquashRatio = detectVerticalSquash(img);
  2750. return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);
  2751. };
  2752. // Based on MinifyJpeg
  2753. // Source: http://www.perry.cz/files/ExifRestorer.js
  2754. // http://elicon.blog57.fc2.com/blog-entry-206.html
  2755. var ExifRestore = function () {
  2756. function ExifRestore() {
  2757. _classCallCheck(this, ExifRestore);
  2758. }
  2759. _createClass(ExifRestore, null, [{
  2760. key: "initClass",
  2761. value: function initClass() {
  2762. this.KEY_STR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  2763. }
  2764. }, {
  2765. key: "encode64",
  2766. value: function encode64(input) {
  2767. var output = '';
  2768. var chr1 = undefined;
  2769. var chr2 = undefined;
  2770. var chr3 = '';
  2771. var enc1 = undefined;
  2772. var enc2 = undefined;
  2773. var enc3 = undefined;
  2774. var enc4 = '';
  2775. var i = 0;
  2776. while (true) {
  2777. chr1 = input[i++];
  2778. chr2 = input[i++];
  2779. chr3 = input[i++];
  2780. enc1 = chr1 >> 2;
  2781. enc2 = (chr1 & 3) << 4 | chr2 >> 4;
  2782. enc3 = (chr2 & 15) << 2 | chr3 >> 6;
  2783. enc4 = chr3 & 63;
  2784. if (isNaN(chr2)) {
  2785. enc3 = enc4 = 64;
  2786. } else if (isNaN(chr3)) {
  2787. enc4 = 64;
  2788. }
  2789. output = output + this.KEY_STR.charAt(enc1) + this.KEY_STR.charAt(enc2) + this.KEY_STR.charAt(enc3) + this.KEY_STR.charAt(enc4);
  2790. chr1 = chr2 = chr3 = '';
  2791. enc1 = enc2 = enc3 = enc4 = '';
  2792. if (!(i < input.length)) {
  2793. break;
  2794. }
  2795. }
  2796. return output;
  2797. }
  2798. }, {
  2799. key: "restore",
  2800. value: function restore(origFileBase64, resizedFileBase64) {
  2801. if (!origFileBase64.match('data:image/jpeg;base64,')) {
  2802. return resizedFileBase64;
  2803. }
  2804. var rawImage = this.decode64(origFileBase64.replace('data:image/jpeg;base64,', ''));
  2805. var segments = this.slice2Segments(rawImage);
  2806. var image = this.exifManipulation(resizedFileBase64, segments);
  2807. return "data:image/jpeg;base64," + this.encode64(image);
  2808. }
  2809. }, {
  2810. key: "exifManipulation",
  2811. value: function exifManipulation(resizedFileBase64, segments) {
  2812. var exifArray = this.getExifArray(segments);
  2813. var newImageArray = this.insertExif(resizedFileBase64, exifArray);
  2814. var aBuffer = new Uint8Array(newImageArray);
  2815. return aBuffer;
  2816. }
  2817. }, {
  2818. key: "getExifArray",
  2819. value: function getExifArray(segments) {
  2820. var seg = undefined;
  2821. var x = 0;
  2822. while (x < segments.length) {
  2823. seg = segments[x];
  2824. if (seg[0] === 255 & seg[1] === 225) {
  2825. return seg;
  2826. }
  2827. x++;
  2828. }
  2829. return [];
  2830. }
  2831. }, {
  2832. key: "insertExif",
  2833. value: function insertExif(resizedFileBase64, exifArray) {
  2834. var imageData = resizedFileBase64.replace('data:image/jpeg;base64,', '');
  2835. var buf = this.decode64(imageData);
  2836. var separatePoint = buf.indexOf(255, 3);
  2837. var mae = buf.slice(0, separatePoint);
  2838. var ato = buf.slice(separatePoint);
  2839. var array = mae;
  2840. array = array.concat(exifArray);
  2841. array = array.concat(ato);
  2842. return array;
  2843. }
  2844. }, {
  2845. key: "slice2Segments",
  2846. value: function slice2Segments(rawImageArray) {
  2847. var head = 0;
  2848. var segments = [];
  2849. while (true) {
  2850. var length;
  2851. if (rawImageArray[head] === 255 & rawImageArray[head + 1] === 218) {
  2852. break;
  2853. }
  2854. if (rawImageArray[head] === 255 & rawImageArray[head + 1] === 216) {
  2855. head += 2;
  2856. } else {
  2857. length = rawImageArray[head + 2] * 256 + rawImageArray[head + 3];
  2858. var endPoint = head + length + 2;
  2859. var seg = rawImageArray.slice(head, endPoint);
  2860. segments.push(seg);
  2861. head = endPoint;
  2862. }
  2863. if (head > rawImageArray.length) {
  2864. break;
  2865. }
  2866. }
  2867. return segments;
  2868. }
  2869. }, {
  2870. key: "decode64",
  2871. value: function decode64(input) {
  2872. var output = '';
  2873. var chr1 = undefined;
  2874. var chr2 = undefined;
  2875. var chr3 = '';
  2876. var enc1 = undefined;
  2877. var enc2 = undefined;
  2878. var enc3 = undefined;
  2879. var enc4 = '';
  2880. var i = 0;
  2881. var buf = [];
  2882. // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
  2883. var base64test = /[^A-Za-z0-9\+\/\=]/g;
  2884. if (base64test.exec(input)) {
  2885. 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.');
  2886. }
  2887. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
  2888. while (true) {
  2889. enc1 = this.KEY_STR.indexOf(input.charAt(i++));
  2890. enc2 = this.KEY_STR.indexOf(input.charAt(i++));
  2891. enc3 = this.KEY_STR.indexOf(input.charAt(i++));
  2892. enc4 = this.KEY_STR.indexOf(input.charAt(i++));
  2893. chr1 = enc1 << 2 | enc2 >> 4;
  2894. chr2 = (enc2 & 15) << 4 | enc3 >> 2;
  2895. chr3 = (enc3 & 3) << 6 | enc4;
  2896. buf.push(chr1);
  2897. if (enc3 !== 64) {
  2898. buf.push(chr2);
  2899. }
  2900. if (enc4 !== 64) {
  2901. buf.push(chr3);
  2902. }
  2903. chr1 = chr2 = chr3 = '';
  2904. enc1 = enc2 = enc3 = enc4 = '';
  2905. if (!(i < input.length)) {
  2906. break;
  2907. }
  2908. }
  2909. return buf;
  2910. }
  2911. }]);
  2912. return ExifRestore;
  2913. }();
  2914. ExifRestore.initClass();
  2915. /*
  2916. * contentloaded.js
  2917. *
  2918. * Author: Diego Perini (diego.perini at gmail.com)
  2919. * Summary: cross-browser wrapper for DOMContentLoaded
  2920. * Updated: 20101020
  2921. * License: MIT
  2922. * Version: 1.2
  2923. *
  2924. * URL:
  2925. * http://javascript.nwbox.com/ContentLoaded/
  2926. * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
  2927. */
  2928. // @win window reference
  2929. // @fn function reference
  2930. var contentLoaded = function contentLoaded(win, fn) {
  2931. var done = false;
  2932. var top = true;
  2933. var doc = win.document;
  2934. var root = doc.documentElement;
  2935. var add = doc.addEventListener ? "addEventListener" : "attachEvent";
  2936. var rem = doc.addEventListener ? "removeEventListener" : "detachEvent";
  2937. var pre = doc.addEventListener ? "" : "on";
  2938. var init = function init(e) {
  2939. if (e.type === "readystatechange" && doc.readyState !== "complete") {
  2940. return;
  2941. }
  2942. (e.type === "load" ? win : doc)[rem](pre + e.type, init, false);
  2943. if (!done && (done = true)) {
  2944. return fn.call(win, e.type || e);
  2945. }
  2946. };
  2947. var poll = function poll() {
  2948. try {
  2949. root.doScroll("left");
  2950. } catch (e) {
  2951. setTimeout(poll, 50);
  2952. return;
  2953. }
  2954. return init("poll");
  2955. };
  2956. if (doc.readyState !== "complete") {
  2957. if (doc.createEventObject && root.doScroll) {
  2958. try {
  2959. top = !win.frameElement;
  2960. } catch (error) {}
  2961. if (top) {
  2962. poll();
  2963. }
  2964. }
  2965. doc[add](pre + "DOMContentLoaded", init, false);
  2966. doc[add](pre + "readystatechange", init, false);
  2967. return win[add](pre + "load", init, false);
  2968. }
  2969. };
  2970. // As a single function to be able to write tests.
  2971. Dropzone._autoDiscoverFunction = function () {
  2972. if (Dropzone.autoDiscover) {
  2973. return Dropzone.discover();
  2974. }
  2975. };
  2976. contentLoaded(window, Dropzone._autoDiscoverFunction);
  2977. function __guard__(value, transform) {
  2978. return typeof value !== 'undefined' && value !== null ? transform(value) : undefined;
  2979. }
  2980. function __guardMethod__(obj, methodName, transform) {
  2981. if (typeof obj !== 'undefined' && obj !== null && typeof obj[methodName] === 'function') {
  2982. return transform(obj, methodName);
  2983. } else {
  2984. return undefined;
  2985. }
  2986. }