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.
 
 
 

3069 lines
148 KiB

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