diff --git a/Gemfile.lock b/Gemfile.lock index 9428dc6..9e1f38a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - dropzonejs-rails (0.8.4) + dropzonejs-rails (0.8.5) rails (> 3.1) GEM diff --git a/README.md b/README.md index 17f4d0b..f4f2886 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Integrate [Matias Meno's Dropzone](http://www.dropzonejs.com/) awesome file uplo ## Version -The latest version of this gem bundles **Dropzone v5.5.0**. +The latest version of this gem bundles **Dropzone v5.7.1**. ### Dropzone 4.x @@ -67,6 +67,8 @@ Go to [this secret place](https://github.com/ncuesta/dropzonejs-rails/issues). ## Changelog +* v0.8.5 + * Updates Dropzone to 5.7.1 **(kudos to [@pnghai](https://github.com/pnghai).** * v0.8.4 * Updates Dropzone to 5.5.0 **#52 by [@HuntBurdick](https://github.com/HuntBurdick).** * v0.8.1 @@ -84,7 +86,7 @@ Go to [this secret place](https://github.com/ncuesta/dropzonejs-rails/issues). ## Licence (MIT) -(c) Copyright 2013-2018 José Nahuel Cuesta Luengo +(c) Copyright 2013-2020 José Nahuel Cuesta Luengo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/app/assets/javascripts/dropzone.js b/app/assets/javascripts/dropzone.js index 0abe7a7..b229327 100755 --- a/app/assets/javascripts/dropzone.js +++ b/app/assets/javascripts/dropzone.js @@ -1,13 +1,23 @@ "use strict"; -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + /* * * More info at [www.dropzonejs.com](http://www.dropzonejs.com) @@ -33,27 +43,29 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons * THE SOFTWARE. * */ - // The Emitter class provides the ability to call `.on()` on Dropzone to listen // to events. // It is strongly based on component's emitter class, and I removed the // functionality because of the dependency hell with different frameworks. -var Emitter = function () { +var Emitter = +/*#__PURE__*/ +function () { function Emitter() { _classCallCheck(this, Emitter); } _createClass(Emitter, [{ key: "on", - // Add an event listener for given event value: function on(event, fn) { - this._callbacks = this._callbacks || {}; - // Create namespace for this event + this._callbacks = this._callbacks || {}; // Create namespace for this event + if (!this._callbacks[event]) { this._callbacks[event] = []; } + this._callbacks[event].push(fn); + return this; } }, { @@ -63,32 +75,37 @@ var Emitter = function () { var callbacks = this._callbacks[event]; if (callbacks) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } - for (var _iterator = callbacks, _isArray = true, _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; + try { + for (var _iterator = callbacks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var callback = _step.value; + callback.apply(this, args); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"] != null) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } } - - var callback = _ref; - - callback.apply(this, args); } } return this; - } - - // Remove event listener for given event. If fn is not provided, all event + } // Remove event listener for given event. If fn is not provided, all event // listeners for that event will be removed. If neither is provided, all // event listeners will be removed. @@ -98,23 +115,25 @@ var Emitter = function () { if (!this._callbacks || arguments.length === 0) { this._callbacks = {}; return this; - } + } // specific event + - // specific event var callbacks = this._callbacks[event]; + if (!callbacks) { return this; - } + } // remove all handlers + - // remove all handlers if (arguments.length === 1) { delete this._callbacks[event]; return this; - } + } // remove specific handler + - // remove specific handler for (var i = 0; i < callbacks.length; i++) { var callback = callbacks[i]; + if (callback === fn) { callbacks.splice(i, 1); break; @@ -128,23 +147,23 @@ var Emitter = function () { return Emitter; }(); -var Dropzone = function (_Emitter) { +var Dropzone = +/*#__PURE__*/ +function (_Emitter) { _inherits(Dropzone, _Emitter); _createClass(Dropzone, null, [{ key: "initClass", value: function initClass() { - // Exposing the emitter class, mainly for tests this.prototype.Emitter = Emitter; - /* This is a list of all available events you can register on a dropzone object. You can register an event handler like this: dropzone.on("dragEnter", function() { }); */ - this.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "addedfile", "addedfiles", "removedfile", "thumbnail", "error", "errormultiple", "processing", "processingmultiple", "uploadprogress", "totaluploadprogress", "sending", "sendingmultiple", "success", "successmultiple", "canceled", "canceledmultiple", "complete", "completemultiple", "reset", "maxfilesexceeded", "maxfilesreached", "queuecomplete"]; + this.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "addedfile", "addedfiles", "removedfile", "thumbnail", "error", "errormultiple", "processing", "processingmultiple", "uploadprogress", "totaluploadprogress", "sending", "sendingmultiple", "success", "successmultiple", "canceled", "canceledmultiple", "complete", "completemultiple", "reset", "maxfilesexceeded", "maxfilesreached", "queuecomplete"]; this.prototype.defaultOptions = { /** * Has to be specified on elements other than form (or when the form @@ -172,7 +191,7 @@ var Dropzone = function (_Emitter) { /** * How many file uploads to process in parallel (See the - * Enqueuing file uploads* documentation section for more info) + * Enqueuing file uploads documentation section for more info) */ parallelUploads: 2, @@ -487,14 +506,20 @@ var Dropzone = function (_Emitter) { * Allows you to translate the different units. Starting with `tb` for terabytes and going down to * `b` for bytes. */ - dictFileSizeUnits: { tb: "TB", gb: "GB", mb: "MB", kb: "KB", b: "b" }, + dictFileSizeUnits: { + tb: "TB", + gb: "GB", + mb: "MB", + kb: "KB", + b: "b" + }, + /** * Called when dropzone initialized * You can add event listeners here */ init: function init() {}, - /** * Can be an **object** of additional parameters to transfer to the server, **or** a `Function` * that gets invoked with the `files`, `xhr` and, if it's a chunked upload, `chunk` arguments. In case @@ -518,7 +543,6 @@ var Dropzone = function (_Emitter) { } }, - /** * A function that gets a [file](https://developer.mozilla.org/en-US/docs/DOM/File) * and a `done` function as parameters. @@ -532,7 +556,6 @@ var Dropzone = function (_Emitter) { return done(); }, - /** * The callback that will be invoked when all chunks have been uploaded for a file. * It gets the file for which the chunks have been uploaded as the first parameter, @@ -550,35 +573,45 @@ var Dropzone = function (_Emitter) { */ fallback: function fallback() { // This code should pass in IE7... :( - var messageElement = void 0; - this.element.className = this.element.className + " dz-browser-not-supported"; - - for (var _iterator2 = this.element.getElementsByTagName("div"), _isArray2 = true, _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { - var _ref2; + var messageElement; + this.element.className = "".concat(this.element.className, " dz-browser-not-supported"); + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; - if (_isArray2) { - if (_i2 >= _iterator2.length) break; - _ref2 = _iterator2[_i2++]; - } else { - _i2 = _iterator2.next(); - if (_i2.done) break; - _ref2 = _i2.value; - } + try { + for (var _iterator2 = this.element.getElementsByTagName("div")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var child = _step2.value; - var child = _ref2; + if (/(^| )dz-message($| )/.test(child.className)) { + messageElement = child; + child.className = "dz-message"; // Removes the 'dz-default' class - if (/(^| )dz-message($| )/.test(child.className)) { - messageElement = child; - child.className = "dz-message"; // Removes the 'dz-default' class - break; + break; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } } } + if (!messageElement) { messageElement = Dropzone.createElement("
"); this.element.appendChild(messageElement); } var span = messageElement.getElementsByTagName("span")[0]; + if (span) { if (span.textContent != null) { span.textContent = this.options.dictFallbackMessage; @@ -590,7 +623,6 @@ var Dropzone = function (_Emitter) { return this.element.appendChild(this.getFallbackForm()); }, - /** * Gets called to calculate the thumbnail dimensions. * @@ -610,10 +642,8 @@ var Dropzone = function (_Emitter) { srcWidth: file.width, srcHeight: file.height }; + var srcRatio = file.width / file.height; // Automatically calculate dimensions if not specified - var srcRatio = file.width / file.height; - - // Automatically calculate dimensions if not specified if (width == null && height == null) { width = info.srcWidth; height = info.srcHeight; @@ -621,12 +651,11 @@ var Dropzone = function (_Emitter) { width = height * srcRatio; } else if (height == null) { height = width / srcRatio; - } + } // Make sure images aren't upscaled + - // Make sure images aren't upscaled width = Math.min(width, info.srcWidth); height = Math.min(height, info.srcHeight); - var trgRatio = width / height; if (info.srcWidth > width || info.srcHeight > height) { @@ -647,20 +676,17 @@ var Dropzone = function (_Emitter) { width = height * srcRatio; } } else { - throw new Error("Unknown resizeMethod '" + resizeMethod + "'"); + throw new Error("Unknown resizeMethod '".concat(resizeMethod, "'")); } } info.srcX = (file.width - info.srcWidth) / 2; info.srcY = (file.height - info.srcHeight) / 2; - info.trgWidth = width; info.trgHeight = height; - return info; }, - /** * Can be used to transform the file (for example, resize an image if necessary). * @@ -678,7 +704,6 @@ var Dropzone = function (_Emitter) { } }, - /** * A string that contains the template used for each dropped * file. Change it to fulfill your needs but make sure to properly @@ -693,12 +718,10 @@ var Dropzone = function (_Emitter) { * .innerHTML * */ - previewTemplate: "
\n
\n
\n
\n
\n
\n
\n
\n
\n \n Check\n \n \n \n \n \n
\n
\n \n Error\n \n \n \n \n \n \n \n
\n
", - + previewTemplate: "
\n
\n
\n
\n
\n
\n
\n
\n
\n \n Check\n \n \n \n \n
\n
\n \n Error\n \n \n \n \n \n \n
\n
", // END OPTIONS // (Required by the dropzone documentation parser) - /* Those functions register themselves to the events on init and handle all the user interface specific stuff. Overwriting them won't break the upload @@ -707,7 +730,6 @@ var Dropzone = function (_Emitter) { want to add an additional event handler, register it on the dropzone object and don't overwrite those options. */ - // Those are self explanatory and simply concern the DragnDrop. drop: function drop(e) { return this.element.classList.remove("dz-drag-hover"); @@ -726,15 +748,11 @@ var Dropzone = function (_Emitter) { return this.element.classList.remove("dz-drag-hover"); }, paste: function paste(e) {}, - - // Called whenever there are no files left in the dropzone anymore, and the // dropzone should be displayed as if in the initial state. reset: function reset() { return this.element.classList.remove("dz-started"); }, - - // Called when a file is added to the queue // Receives `file` addedfile: function addedfile(file) { @@ -749,43 +767,63 @@ var Dropzone = function (_Emitter) { file.previewTemplate = file.previewElement; // Backwards compatibility this.previewsContainer.appendChild(file.previewElement); - for (var _iterator3 = file.previewElement.querySelectorAll("[data-dz-name]"), _isArray3 = true, _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { - var _ref3; + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; - if (_isArray3) { - if (_i3 >= _iterator3.length) break; - _ref3 = _iterator3[_i3++]; - } else { - _i3 = _iterator3.next(); - if (_i3.done) break; - _ref3 = _i3.value; + try { + for (var _iterator3 = file.previewElement.querySelectorAll("[data-dz-name]")[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var node = _step3.value; + node.textContent = file.name; + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } } + } - var node = _ref3; + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; - node.textContent = file.name; - } - for (var _iterator4 = file.previewElement.querySelectorAll("[data-dz-size]"), _isArray4 = true, _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { - if (_isArray4) { - if (_i4 >= _iterator4.length) break; - node = _iterator4[_i4++]; - } else { - _i4 = _iterator4.next(); - if (_i4.done) break; - node = _i4.value; + try { + for (var _iterator4 = file.previewElement.querySelectorAll("[data-dz-size]")[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + node = _step4.value; + node.innerHTML = this.filesize(file.size); + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } } - - node.innerHTML = this.filesize(file.size); } if (this.options.addRemoveLinks) { - file._removeLink = Dropzone.createElement("" + this.options.dictRemoveFile + ""); + file._removeLink = Dropzone.createElement("".concat(this.options.dictRemoveFile, "")); file.previewElement.appendChild(file._removeLink); } var removeFileEvent = function removeFileEvent(e) { e.preventDefault(); e.stopPropagation(); + if (file.status === Dropzone.UPLOADING) { return Dropzone.confirm(_this2.options.dictCancelUploadConfirmation, function () { return _this2.removeFile(file); @@ -801,56 +839,67 @@ var Dropzone = function (_Emitter) { } }; - for (var _iterator5 = file.previewElement.querySelectorAll("[data-dz-remove]"), _isArray5 = true, _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { - var _ref4; + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; - if (_isArray5) { - if (_i5 >= _iterator5.length) break; - _ref4 = _iterator5[_i5++]; - } else { - _i5 = _iterator5.next(); - if (_i5.done) break; - _ref4 = _i5.value; + try { + for (var _iterator5 = file.previewElement.querySelectorAll("[data-dz-remove]")[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var removeLink = _step5.value; + removeLink.addEventListener("click", removeFileEvent); + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5["return"] != null) { + _iterator5["return"](); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } } - - var removeLink = _ref4; - - removeLink.addEventListener("click", removeFileEvent); } } }, - - // Called whenever a file is removed. removedfile: function removedfile(file) { if (file.previewElement != null && file.previewElement.parentNode != null) { file.previewElement.parentNode.removeChild(file.previewElement); } + return this._updateMaxFilesReachedClass(); }, - - // Called when a thumbnail has been generated // Receives `file` and `dataUrl` thumbnail: function thumbnail(file, dataUrl) { if (file.previewElement) { file.previewElement.classList.remove("dz-file-preview"); - for (var _iterator6 = file.previewElement.querySelectorAll("[data-dz-thumbnail]"), _isArray6 = true, _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { - var _ref5; + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; - if (_isArray6) { - if (_i6 >= _iterator6.length) break; - _ref5 = _iterator6[_i6++]; - } else { - _i6 = _iterator6.next(); - if (_i6.done) break; - _ref5 = _i6.value; + try { + for (var _iterator6 = file.previewElement.querySelectorAll("[data-dz-thumbnail]")[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var thumbnailElement = _step6.value; + thumbnailElement.alt = file.name; + thumbnailElement.src = dataUrl; + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6["return"] != null) { + _iterator6["return"](); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } } - - var thumbnailElement = _ref5; - - thumbnailElement.alt = file.name; - thumbnailElement.src = dataUrl; } return setTimeout(function () { @@ -858,88 +907,93 @@ var Dropzone = function (_Emitter) { }, 1); } }, - - // Called whenever an error occurs // Receives `file` and `message` error: function error(file, message) { if (file.previewElement) { file.previewElement.classList.add("dz-error"); + if (typeof message !== "String" && message.error) { message = message.error; } - for (var _iterator7 = file.previewElement.querySelectorAll("[data-dz-errormessage]"), _isArray7 = true, _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { - var _ref6; - - if (_isArray7) { - if (_i7 >= _iterator7.length) break; - _ref6 = _iterator7[_i7++]; - } else { - _i7 = _iterator7.next(); - if (_i7.done) break; - _ref6 = _i7.value; - } - var node = _ref6; + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; - node.textContent = message; + try { + for (var _iterator7 = file.previewElement.querySelectorAll("[data-dz-errormessage]")[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var node = _step7.value; + node.textContent = message; + } + } catch (err) { + _didIteratorError7 = true; + _iteratorError7 = err; + } finally { + try { + if (!_iteratorNormalCompletion7 && _iterator7["return"] != null) { + _iterator7["return"](); + } + } finally { + if (_didIteratorError7) { + throw _iteratorError7; + } + } } } }, errormultiple: function errormultiple() {}, - - // Called when a file gets processed. Since there is a cue, not all added // files are processed immediately. // Receives `file` processing: function processing(file) { if (file.previewElement) { file.previewElement.classList.add("dz-processing"); + if (file._removeLink) { return file._removeLink.innerHTML = this.options.dictCancelUpload; } } }, processingmultiple: function processingmultiple() {}, - - // Called whenever the upload progress gets updated. // Receives `file`, `progress` (percentage 0-100) and `bytesSent`. // To get the total number of bytes of the file, use `file.size` uploadprogress: function uploadprogress(file, progress, bytesSent) { if (file.previewElement) { - for (var _iterator8 = file.previewElement.querySelectorAll("[data-dz-uploadprogress]"), _isArray8 = true, _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { - var _ref7; + var _iteratorNormalCompletion8 = true; + var _didIteratorError8 = false; + var _iteratorError8 = undefined; - if (_isArray8) { - if (_i8 >= _iterator8.length) break; - _ref7 = _iterator8[_i8++]; - } else { - _i8 = _iterator8.next(); - if (_i8.done) break; - _ref7 = _i8.value; + try { + for (var _iterator8 = file.previewElement.querySelectorAll("[data-dz-uploadprogress]")[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { + var node = _step8.value; + node.nodeName === 'PROGRESS' ? node.value = progress : node.style.width = "".concat(progress, "%"); + } + } catch (err) { + _didIteratorError8 = true; + _iteratorError8 = err; + } finally { + try { + if (!_iteratorNormalCompletion8 && _iterator8["return"] != null) { + _iterator8["return"](); + } + } finally { + if (_didIteratorError8) { + throw _iteratorError8; + } } - - var node = _ref7; - - node.nodeName === 'PROGRESS' ? node.value = progress : node.style.width = progress + "%"; } } }, - - // Called whenever the total upload progress gets updated. // Called with totalUploadProgress (0-100), totalBytes and totalBytesSent totaluploadprogress: function totaluploadprogress() {}, - - // Called just before the file is sent. Gets the `xhr` object as second // parameter, so you can modify it (for example to add a CSRF token) and a // `formData` object to add additional information. sending: function sending() {}, sendingmultiple: function sendingmultiple() {}, - - // When the complete upload is finished and successful // Receives `file` success: function success(file) { @@ -948,21 +1002,18 @@ var Dropzone = function (_Emitter) { } }, successmultiple: function successmultiple() {}, - - // When the upload is canceled. canceled: function canceled(file) { return this.emit("error", file, this.options.dictUploadCanceled); }, canceledmultiple: function canceledmultiple() {}, - - // When the upload is finished, either with success or an error. // Receives `file` complete: function complete(file) { if (file._removeLink) { file._removeLink.innerHTML = this.options.dictRemoveFile; } + if (file.previewElement) { return file.previewElement.classList.add("dz-complete"); } @@ -973,91 +1024,70 @@ var Dropzone = function (_Emitter) { queuecomplete: function queuecomplete() {}, addedfiles: function addedfiles() {} }; - this.prototype._thumbnailQueue = []; this.prototype._processingThumbnail = false; - } - - // global utility + } // global utility }, { key: "extend", value: function extend(target) { - for (var _len2 = arguments.length, objects = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { + for (var _len2 = arguments.length, objects = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { objects[_key2 - 1] = arguments[_key2]; } - for (var _iterator9 = objects, _isArray9 = true, _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { - var _ref8; - - if (_isArray9) { - if (_i9 >= _iterator9.length) break; - _ref8 = _iterator9[_i9++]; - } else { - _i9 = _iterator9.next(); - if (_i9.done) break; - _ref8 = _i9.value; - } - - var object = _ref8; + for (var _i = 0, _objects = objects; _i < _objects.length; _i++) { + var object = _objects[_i]; for (var key in object) { var val = object[key]; target[key] = val; } } + return target; } }]); function Dropzone(el, options) { + var _this; + _classCallCheck(this, Dropzone); - var _this = _possibleConstructorReturn(this, (Dropzone.__proto__ || Object.getPrototypeOf(Dropzone)).call(this)); + _this = _possibleConstructorReturn(this, _getPrototypeOf(Dropzone).call(this)); + var fallback, left; + _this.element = el; // For backwards compatibility since the version was in the prototype previously - var fallback = void 0, - left = void 0; - _this.element = el; - // For backwards compatibility since the version was in the prototype previously _this.version = Dropzone.version; - _this.defaultOptions.previewTemplate = _this.defaultOptions.previewTemplate.replace(/\n*/g, ""); - _this.clickableElements = []; _this.listeners = []; _this.files = []; // All files if (typeof _this.element === "string") { _this.element = document.querySelector(_this.element); - } + } // Not checking if instance of HTMLElement or Element since IE9 is extremely weird. + - // Not checking if instance of HTMLElement or Element since IE9 is extremely weird. if (!_this.element || _this.element.nodeType == null) { throw new Error("Invalid dropzone element."); } if (_this.element.dropzone) { throw new Error("Dropzone already attached."); - } + } // Now add this dropzone to the instances. - // Now add this dropzone to the instances. - Dropzone.instances.push(_this); - // Put the dropzone inside the element itself. - _this.element.dropzone = _this; + Dropzone.instances.push(_assertThisInitialized(_this)); // Put the dropzone inside the element itself. + _this.element.dropzone = _assertThisInitialized(_this); var elementOptions = (left = Dropzone.optionsForElement(_this.element)) != null ? left : {}; + _this.options = Dropzone.extend({}, _this.defaultOptions, elementOptions, options != null ? options : {}); // If the browser failed, just call the fallback and leave - _this.options = Dropzone.extend({}, _this.defaultOptions, elementOptions, options != null ? options : {}); - - // If the browser failed, just call the fallback and leave if (_this.options.forceFallback || !Dropzone.isBrowserSupported()) { - var _ret; + return _possibleConstructorReturn(_this, _this.options.fallback.call(_assertThisInitialized(_this))); + } // @options.url = @element.getAttribute "action" unless @options.url? - return _ret = _this.options.fallback.call(_this), _possibleConstructorReturn(_this, _ret); - } - // @options.url = @element.getAttribute "action" unless @options.url? if (_this.options.url == null) { _this.options.url = _this.element.getAttribute("action"); } @@ -1072,18 +1102,18 @@ var Dropzone = function (_Emitter) { if (_this.options.uploadMultiple && _this.options.chunking) { throw new Error('You cannot set both: uploadMultiple and chunking.'); - } + } // Backwards compatibility + - // Backwards compatibility if (_this.options.acceptedMimeTypes) { _this.options.acceptedFiles = _this.options.acceptedMimeTypes; delete _this.options.acceptedMimeTypes; - } + } // Backwards compatibility + - // Backwards compatibility if (_this.options.renameFilename != null) { _this.options.renameFile = function (file) { - return _this.options.renameFilename.call(_this, file.name, file); + return _this.options.renameFilename.call(_assertThisInitialized(_this), file.name, file); }; } @@ -1092,9 +1122,9 @@ var Dropzone = function (_Emitter) { if ((fallback = _this.getExistingFallback()) && fallback.parentNode) { // Remove the fallback fallback.parentNode.removeChild(fallback); - } + } // Display previews in the previewsContainer element or the Dropzone element unless explicitly set to false + - // Display previews in the previewsContainer element or the Dropzone element unless explicitly set to false if (_this.options.previewsContainer !== false) { if (_this.options.previewsContainer) { _this.previewsContainer = Dropzone.getElement(_this.options.previewsContainer, "previewsContainer"); @@ -1112,10 +1142,9 @@ var Dropzone = function (_Emitter) { } _this.init(); - return _this; - } - // Returns all files that have been accepted + return _this; + } // Returns all files that have been accepted _createClass(Dropzone, [{ @@ -1126,9 +1155,7 @@ var Dropzone = function (_Emitter) { }).map(function (file) { return file; }); - } - - // Returns all files that have been rejected + } // Returns all files that have been rejected // Not sure when that's going to be useful, but added for completeness. }, { @@ -1148,9 +1175,7 @@ var Dropzone = function (_Emitter) { }).map(function (file) { return file; }); - } - - // Returns all files that are in the queue + } // Returns all files that are in the queue }, { key: "getQueuedFiles", @@ -1166,9 +1191,7 @@ var Dropzone = function (_Emitter) { key: "getAddedFiles", value: function getAddedFiles() { return this.getFilesWithStatus(Dropzone.ADDED); - } - - // Files that are either queued or uploading + } // Files that are either queued or uploading }, { key: "getActiveFiles", @@ -1178,9 +1201,7 @@ var Dropzone = function (_Emitter) { }).map(function (file) { return file; }); - } - - // The function that gets called when Dropzone is initialized. You + } // The function that gets called when Dropzone is initialized. You // can (and should) setup event listeners inside this function. }, { @@ -1194,7 +1215,7 @@ var Dropzone = function (_Emitter) { } if (this.element.classList.contains("dropzone") && !this.element.querySelector(".dz-message")) { - this.element.appendChild(Dropzone.createElement("
" + this.options.dictDefaultMessage + "
")); + this.element.appendChild(Dropzone.createElement("
"))); } if (this.clickableElements.length) { @@ -1202,22 +1223,27 @@ var Dropzone = function (_Emitter) { if (_this3.hiddenFileInput) { _this3.hiddenFileInput.parentNode.removeChild(_this3.hiddenFileInput); } + _this3.hiddenFileInput = document.createElement("input"); + _this3.hiddenFileInput.setAttribute("type", "file"); + if (_this3.options.maxFiles === null || _this3.options.maxFiles > 1) { _this3.hiddenFileInput.setAttribute("multiple", "multiple"); } + _this3.hiddenFileInput.className = "dz-hidden-input"; if (_this3.options.acceptedFiles !== null) { _this3.hiddenFileInput.setAttribute("accept", _this3.options.acceptedFiles); } + if (_this3.options.capture !== null) { _this3.hiddenFileInput.setAttribute("capture", _this3.options.capture); - } - - // Not setting `display="none"` because some browsers don't accept clicks + } // Not setting `display="none"` because some browsers don't accept clicks // on elements that aren't displayed. + + _this3.hiddenFileInput.style.visibility = "hidden"; _this3.hiddenFileInput.style.position = "absolute"; _this3.hiddenFileInput.style.top = "0"; @@ -1229,65 +1255,79 @@ var Dropzone = function (_Emitter) { var files = _this3.hiddenFileInput.files; if (files.length) { - for (var _iterator10 = files, _isArray10 = true, _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) { - var _ref9; - - if (_isArray10) { - if (_i10 >= _iterator10.length) break; - _ref9 = _iterator10[_i10++]; - } else { - _i10 = _iterator10.next(); - if (_i10.done) break; - _ref9 = _i10.value; - } + var _iteratorNormalCompletion9 = true; + var _didIteratorError9 = false; + var _iteratorError9 = undefined; - var file = _ref9; + try { + for (var _iterator9 = files[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { + var file = _step9.value; - _this3.addFile(file); + _this3.addFile(file); + } + } catch (err) { + _didIteratorError9 = true; + _iteratorError9 = err; + } finally { + try { + if (!_iteratorNormalCompletion9 && _iterator9["return"] != null) { + _iterator9["return"](); + } + } finally { + if (_didIteratorError9) { + throw _iteratorError9; + } + } } } + _this3.emit("addedfiles", files); + return setupHiddenFileInput(); }); }; + setupHiddenFileInput(); } - this.URL = window.URL !== null ? window.URL : window.webkitURL; - - // Setup all event listeners on the Dropzone object itself. + this.URL = window.URL !== null ? window.URL : window.webkitURL; // Setup all event listeners on the Dropzone object itself. // They're not in @setupEventListeners() because they shouldn't be removed // again when the dropzone gets disabled. - for (var _iterator11 = this.events, _isArray11 = true, _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) { - var _ref10; - - if (_isArray11) { - if (_i11 >= _iterator11.length) break; - _ref10 = _iterator11[_i11++]; - } else { - _i11 = _iterator11.next(); - if (_i11.done) break; - _ref10 = _i11.value; - } - var eventName = _ref10; + var _iteratorNormalCompletion10 = true; + var _didIteratorError10 = false; + var _iteratorError10 = undefined; - this.on(eventName, this.options[eventName]); + try { + for (var _iterator10 = this.events[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { + var eventName = _step10.value; + this.on(eventName, this.options[eventName]); + } + } catch (err) { + _didIteratorError10 = true; + _iteratorError10 = err; + } finally { + try { + if (!_iteratorNormalCompletion10 && _iterator10["return"] != null) { + _iterator10["return"](); + } + } finally { + if (_didIteratorError10) { + throw _iteratorError10; + } + } } this.on("uploadprogress", function () { return _this3.updateTotalUploadProgress(); }); - this.on("removedfile", function () { return _this3.updateTotalUploadProgress(); }); - this.on("canceled", function (file) { return _this3.emit("complete", file); - }); + }); // Emit a `queuecomplete` event if all files finished uploading. - // Emit a `queuecomplete` event if all files finished uploading. this.on("complete", function (file) { 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` @@ -1297,16 +1337,34 @@ var Dropzone = function (_Emitter) { } }); + var containsFiles = function containsFiles(e) { + if (e.dataTransfer.types) { + // Because e.dataTransfer.types is an Object in + // IE, we need to iterate like this instead of + // using e.dataTransfer.types.some() + for (var i = 0; i < e.dataTransfer.types.length; i++) { + if (e.dataTransfer.types[i] === "Files") return true; + } + } + + return false; + }; + var noPropagation = function noPropagation(e) { + // If there are no files, we don't want to stop + // propagation so we don't interfere with other + // drag and drop behaviour. + if (!containsFiles(e)) return; e.stopPropagation(); + if (e.preventDefault) { return e.preventDefault(); } else { return e.returnValue = false; } - }; + }; // Create the listeners + - // Create the listeners this.listeners = [{ element: this.element, events: { @@ -1321,12 +1379,13 @@ var Dropzone = function (_Emitter) { // Makes it possible to drag files from chrome's download bar // http://stackoverflow.com/questions/19526430/drag-and-drop-file-uploads-from-chrome-downloads-bar // Try is required to prevent bug in Internet Explorer 11 (SCRIPT65535 exception) - var efct = void 0; + var efct; + try { efct = e.dataTransfer.effectAllowed; } catch (error) {} - e.dataTransfer.dropEffect = 'move' === efct || 'linkMove' === efct ? 'move' : 'copy'; + e.dataTransfer.dropEffect = 'move' === efct || 'linkMove' === efct ? 'move' : 'copy'; noPropagation(e); return _this3.emit("dragover", e); }, @@ -1340,13 +1399,12 @@ var Dropzone = function (_Emitter) { "dragend": function dragend(e) { return _this3.emit("dragend", e); } + } // This is disabled right now, because the browsers don't implement it properly. + // "paste": (e) => + // noPropagation e + // @paste e - // This is disabled right now, because the browsers don't implement it properly. - // "paste": (e) => - // noPropagation e - // @paste e - } }]; - + }]; this.clickableElements.forEach(function (clickableElement) { return _this3.listeners.push({ element: clickableElement, @@ -1355,68 +1413,73 @@ var Dropzone = function (_Emitter) { // Only the actual dropzone or the message element should trigger file selection if (clickableElement !== _this3.element || evt.target === _this3.element || Dropzone.elementInside(evt.target, _this3.element.querySelector(".dz-message"))) { _this3.hiddenFileInput.click(); // Forward the click + } + return true; } } }); }); - this.enable(); - return this.options.init.call(this); - } - - // Not fully tested yet + } // Not fully tested yet }, { key: "destroy", value: function destroy() { this.disable(); this.removeAllFiles(true); + if (this.hiddenFileInput != null ? this.hiddenFileInput.parentNode : undefined) { this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput); this.hiddenFileInput = null; } + delete this.element.dropzone; return Dropzone.instances.splice(Dropzone.instances.indexOf(this), 1); } }, { key: "updateTotalUploadProgress", value: function updateTotalUploadProgress() { - var totalUploadProgress = void 0; + var totalUploadProgress; var totalBytesSent = 0; var totalBytes = 0; - var activeFiles = this.getActiveFiles(); if (activeFiles.length) { - for (var _iterator12 = this.getActiveFiles(), _isArray12 = true, _i12 = 0, _iterator12 = _isArray12 ? _iterator12 : _iterator12[Symbol.iterator]();;) { - var _ref11; - - if (_isArray12) { - if (_i12 >= _iterator12.length) break; - _ref11 = _iterator12[_i12++]; - } else { - _i12 = _iterator12.next(); - if (_i12.done) break; - _ref11 = _i12.value; + var _iteratorNormalCompletion11 = true; + var _didIteratorError11 = false; + var _iteratorError11 = undefined; + + try { + for (var _iterator11 = this.getActiveFiles()[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { + var file = _step11.value; + totalBytesSent += file.upload.bytesSent; + totalBytes += file.upload.total; + } + } catch (err) { + _didIteratorError11 = true; + _iteratorError11 = err; + } finally { + try { + if (!_iteratorNormalCompletion11 && _iterator11["return"] != null) { + _iterator11["return"](); + } + } finally { + if (_didIteratorError11) { + throw _iteratorError11; + } } - - var file = _ref11; - - totalBytesSent += file.upload.bytesSent; - totalBytes += file.upload.total; } + totalUploadProgress = 100 * totalBytesSent / totalBytes; } else { totalUploadProgress = 100; } return this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent); - } - - // @options.paramName can be a function taking one parameter rather than a string. + } // @options.paramName can be a function taking one parameter rather than a string. // A parameter name for a file is obtained simply by calling this with an index number. }, { @@ -1425,11 +1488,9 @@ var Dropzone = function (_Emitter) { if (typeof this.options.paramName === "function") { return this.options.paramName(n); } else { - return "" + this.options.paramName + (this.options.uploadMultiple ? "[" + n + "]" : ""); + return "".concat(this.options.paramName).concat(this.options.uploadMultiple ? "[".concat(n, "]") : ""); } - } - - // If @options.renameFile is a function, + } // If @options.renameFile is a function, // the function will be used to rename the file.name before appending it to the formData }, { @@ -1438,10 +1499,9 @@ var Dropzone = function (_Emitter) { if (typeof this.options.renameFile !== "function") { return file.name; } - return this.options.renameFile(file); - } - // Returns a form that can be used as fallback if the browser does not support DragnDrop + return this.options.renameFile(file); + } // Returns a form that can be used as fallback if the browser does not support DragnDrop // // If the dropzone is already a form, only the input field and button are returned. Otherwise a complete form element is provided. // This code has to pass in IE7 :( @@ -1449,31 +1509,32 @@ var Dropzone = function (_Emitter) { }, { key: "getFallbackForm", value: function getFallbackForm() { - var existingFallback = void 0, - form = void 0; + var existingFallback, form; + if (existingFallback = this.getExistingFallback()) { return existingFallback; } var fieldsString = "
"; + if (this.options.dictFallbackText) { - fieldsString += "

" + this.options.dictFallbackText + "

"; + fieldsString += "

".concat(this.options.dictFallbackText, "

"); } - fieldsString += "
"; + fieldsString += ""); var fields = Dropzone.createElement(fieldsString); + if (this.element.tagName !== "FORM") { - form = Dropzone.createElement("
"); + form = Dropzone.createElement("
")); form.appendChild(fields); } else { // Make sure that the enctype and method attributes are set properly this.element.setAttribute("enctype", "multipart/form-data"); this.element.setAttribute("method", this.options.method); } - return form != null ? form : fields; - } - // Returns the fallback elements if they exist already + return form != null ? form : fields; + } // Returns the fallback elements if they exist already // // This code has to pass in IE7 :( @@ -1481,37 +1542,43 @@ var Dropzone = function (_Emitter) { key: "getExistingFallback", value: function getExistingFallback() { var getFallback = function getFallback(elements) { - for (var _iterator13 = elements, _isArray13 = true, _i13 = 0, _iterator13 = _isArray13 ? _iterator13 : _iterator13[Symbol.iterator]();;) { - var _ref12; - - if (_isArray13) { - if (_i13 >= _iterator13.length) break; - _ref12 = _iterator13[_i13++]; - } else { - _i13 = _iterator13.next(); - if (_i13.done) break; - _ref12 = _i13.value; - } + var _iteratorNormalCompletion12 = true; + var _didIteratorError12 = false; + var _iteratorError12 = undefined; - var el = _ref12; + try { + for (var _iterator12 = elements[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { + var el = _step12.value; - if (/(^| )fallback($| )/.test(el.className)) { - return el; + if (/(^| )fallback($| )/.test(el.className)) { + return el; + } + } + } catch (err) { + _didIteratorError12 = true; + _iteratorError12 = err; + } finally { + try { + if (!_iteratorNormalCompletion12 && _iterator12["return"] != null) { + _iterator12["return"](); + } + } finally { + if (_didIteratorError12) { + throw _iteratorError12; + } } } }; - var _arr = ["div", "form"]; - for (var _i14 = 0; _i14 < _arr.length; _i14++) { - var tagName = _arr[_i14]; + for (var _i2 = 0, _arr = ["div", "form"]; _i2 < _arr.length; _i2++) { + var tagName = _arr[_i2]; var fallback; + if (fallback = getFallback(this.element.getElementsByTagName(tagName))) { return fallback; } } - } - - // Activates all listeners stored in @listeners + } // Activates all listeners stored in @listeners }, { key: "setupEventListeners", @@ -1519,16 +1586,16 @@ var Dropzone = function (_Emitter) { return this.listeners.map(function (elementListeners) { return function () { var result = []; + for (var event in elementListeners.events) { var listener = elementListeners.events[event]; result.push(elementListeners.element.addEventListener(event, listener, false)); } + return result; }(); }); - } - - // Deactivates all listeners stored in @listeners + } // Deactivates all listeners stored in @listeners }, { key: "removeEventListeners", @@ -1536,16 +1603,16 @@ var Dropzone = function (_Emitter) { return this.listeners.map(function (elementListeners) { return function () { var result = []; + for (var event in elementListeners.events) { var listener = elementListeners.events[event]; result.push(elementListeners.element.removeEventListener(event, listener, false)); } + return result; }(); }); - } - - // Removes all event listeners and cancels all files in the queue or being processed. + } // Removes all event listeners and cancels all files in the queue or being processed. }, { key: "disable", @@ -1557,7 +1624,6 @@ var Dropzone = function (_Emitter) { }); this.removeEventListeners(); this.disabled = true; - return this.files.map(function (file) { return _this4.cancelUpload(file); }); @@ -1570,9 +1636,7 @@ var Dropzone = function (_Emitter) { return element.classList.add("dz-clickable"); }); return this.setupEventListeners(); - } - - // Returns a nicely formatted filesize + } // Returns a nicely formatted filesize }, { key: "filesize", @@ -1597,10 +1661,8 @@ var Dropzone = function (_Emitter) { selectedSize = Math.round(10 * selectedSize) / 10; // Cutting of digits } - return "" + selectedSize + " " + this.options.dictFileSizeUnits[selectedUnit]; - } - - // Adds or removes the `dz-max-files-reached` class from the form. + return "".concat(selectedSize, " ").concat(this.options.dictFileSizeUnits[selectedUnit]); + } // Adds or removes the `dz-max-files-reached` class from the form. }, { key: "_updateMaxFilesReachedClass", @@ -1609,6 +1671,7 @@ var Dropzone = function (_Emitter) { if (this.getAcceptedFiles().length === this.options.maxFiles) { this.emit('maxfilesreached', this.files); } + return this.element.classList.add("dz-max-files-reached"); } else { return this.element.classList.remove("dz-max-files-reached"); @@ -1620,18 +1683,17 @@ var Dropzone = function (_Emitter) { if (!e.dataTransfer) { return; } - this.emit("drop", e); - // Convert the FileList to an Array + this.emit("drop", e); // Convert the FileList to an Array // This is necessary for IE11 + var files = []; + for (var i = 0; i < e.dataTransfer.files.length; i++) { files[i] = e.dataTransfer.files[i]; - } + } // Even if it's a folder, files.length will contain the folders. - this.emit("addedfiles", files); - // Even if it's a folder, files.length will contain the folders. if (files.length) { var items = e.dataTransfer.items; @@ -1642,6 +1704,8 @@ var Dropzone = function (_Emitter) { this.handleFiles(files); } } + + this.emit("addedfiles", files); } }, { key: "paste", @@ -1655,7 +1719,6 @@ var Dropzone = function (_Emitter) { this.emit("paste", e); var items = e.clipboardData.items; - if (items.length) { return this._addFilesFromItems(items); } @@ -1663,25 +1726,30 @@ var Dropzone = function (_Emitter) { }, { key: "handleFiles", value: function handleFiles(files) { - for (var _iterator14 = files, _isArray14 = true, _i15 = 0, _iterator14 = _isArray14 ? _iterator14 : _iterator14[Symbol.iterator]();;) { - var _ref13; + var _iteratorNormalCompletion13 = true; + var _didIteratorError13 = false; + var _iteratorError13 = undefined; - if (_isArray14) { - if (_i15 >= _iterator14.length) break; - _ref13 = _iterator14[_i15++]; - } else { - _i15 = _iterator14.next(); - if (_i15.done) break; - _ref13 = _i15.value; + try { + for (var _iterator13 = files[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { + var file = _step13.value; + this.addFile(file); + } + } catch (err) { + _didIteratorError13 = true; + _iteratorError13 = err; + } finally { + try { + if (!_iteratorNormalCompletion13 && _iterator13["return"] != null) { + _iterator13["return"](); + } + } finally { + if (_didIteratorError13) { + throw _iteratorError13; + } } - - var file = _ref13; - - this.addFile(file); } - } - - // When a folder is dropped (or files are pasted), items must be handled + } // When a folder is dropped (or files are pasted), items must be handled // instead of files. }, { @@ -1691,45 +1759,52 @@ var Dropzone = function (_Emitter) { return function () { var result = []; - for (var _iterator15 = items, _isArray15 = true, _i16 = 0, _iterator15 = _isArray15 ? _iterator15 : _iterator15[Symbol.iterator]();;) { - var _ref14; + var _iteratorNormalCompletion14 = true; + var _didIteratorError14 = false; + var _iteratorError14 = undefined; - if (_isArray15) { - if (_i16 >= _iterator15.length) break; - _ref14 = _iterator15[_i16++]; - } else { - _i16 = _iterator15.next(); - if (_i16.done) break; - _ref14 = _i16.value; - } + try { + for (var _iterator14 = items[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { + var item = _step14.value; + var entry; - var item = _ref14; - - var entry; - if (item.webkitGetAsEntry != null && (entry = item.webkitGetAsEntry())) { - if (entry.isFile) { - result.push(_this5.addFile(item.getAsFile())); - } else if (entry.isDirectory) { - // Append all files from that directory to files - result.push(_this5._addFilesFromDirectory(entry, entry.name)); + if (item.webkitGetAsEntry != null && (entry = item.webkitGetAsEntry())) { + if (entry.isFile) { + result.push(_this5.addFile(item.getAsFile())); + } else if (entry.isDirectory) { + // Append all files from that directory to files + result.push(_this5._addFilesFromDirectory(entry, entry.name)); + } else { + result.push(undefined); + } + } else if (item.getAsFile != null) { + if (item.kind == null || item.kind === "file") { + result.push(_this5.addFile(item.getAsFile())); + } else { + result.push(undefined); + } } else { result.push(undefined); } - } else if (item.getAsFile != null) { - if (item.kind == null || item.kind === "file") { - result.push(_this5.addFile(item.getAsFile())); - } else { - result.push(undefined); + } + } catch (err) { + _didIteratorError14 = true; + _iteratorError14 = err; + } finally { + try { + if (!_iteratorNormalCompletion14 && _iterator14["return"] != null) { + _iterator14["return"](); + } + } finally { + if (_didIteratorError14) { + throw _iteratorError14; } - } else { - result.push(undefined); } } + return result; }(); - } - - // Goes through the directory, and adds each file it finds recursively + } // Goes through the directory, and adds each file it finds recursively }, { key: "_addFilesFromDirectory", @@ -1747,46 +1822,54 @@ var Dropzone = function (_Emitter) { var readEntries = function readEntries() { return dirReader.readEntries(function (entries) { if (entries.length > 0) { - for (var _iterator16 = entries, _isArray16 = true, _i17 = 0, _iterator16 = _isArray16 ? _iterator16 : _iterator16[Symbol.iterator]();;) { - var _ref15; + var _iteratorNormalCompletion15 = true; + var _didIteratorError15 = false; + var _iteratorError15 = undefined; - if (_isArray16) { - if (_i17 >= _iterator16.length) break; - _ref15 = _iterator16[_i17++]; - } else { - _i17 = _iterator16.next(); - if (_i17.done) break; - _ref15 = _i17.value; - } + try { + for (var _iterator15 = entries[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) { + var entry = _step15.value; - var entry = _ref15; + if (entry.isFile) { + entry.file(function (file) { + if (_this6.options.ignoreHiddenFiles && file.name.substring(0, 1) === '.') { + return; + } - if (entry.isFile) { - entry.file(function (file) { - if (_this6.options.ignoreHiddenFiles && file.name.substring(0, 1) === '.') { - return; - } - file.fullPath = path + "/" + file.name; - return _this6.addFile(file); - }); - } else if (entry.isDirectory) { - _this6._addFilesFromDirectory(entry, path + "/" + entry.name); + file.fullPath = "".concat(path, "/").concat(file.name); + return _this6.addFile(file); + }); + } else if (entry.isDirectory) { + _this6._addFilesFromDirectory(entry, "".concat(path, "/").concat(entry.name)); + } + } // Recursively call readEntries() again, since browser only handle + // the first 100 entries. + // See: https://developer.mozilla.org/en-US/docs/Web/API/DirectoryReader#readEntries + + } catch (err) { + _didIteratorError15 = true; + _iteratorError15 = err; + } finally { + try { + if (!_iteratorNormalCompletion15 && _iterator15["return"] != null) { + _iterator15["return"](); + } + } finally { + if (_didIteratorError15) { + throw _iteratorError15; + } } } - // Recursively call readEntries() again, since browser only handle - // the first 100 entries. - // See: https://developer.mozilla.org/en-US/docs/Web/API/DirectoryReader#readEntries readEntries(); } + return null; }, errorHandler); }; return readEntries(); - } - - // If `done()` is called without argument the file is accepted + } // If `done()` is called without argument the file is accepted // If you call it with an error message, the file is rejected // (This allows for asynchronous validation) // @@ -1797,14 +1880,14 @@ var Dropzone = function (_Emitter) { key: "accept", value: function accept(file, done) { if (this.options.maxFilesize && file.size > this.options.maxFilesize * 1024 * 1024) { - return done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize)); + done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize)); } else if (!Dropzone.isValidFile(file, this.options.acceptedFiles)) { - return done(this.options.dictInvalidFileType); + done(this.options.dictInvalidFileType); } else if (this.options.maxFiles != null && this.getAcceptedFiles().length >= this.options.maxFiles) { done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}", this.options.maxFiles)); - return this.emit("maxfilesexceeded", file); + this.emit("maxfilesexceeded", file); } else { - return this.options.accept.call(this, file, done); + this.options.accept.call(this, file, done); } } }, { @@ -1819,53 +1902,63 @@ var Dropzone = function (_Emitter) { // It's actual different than the size to be transmitted. total: file.size, bytesSent: 0, - filename: this._renameFile(file), - chunked: this.options.chunking && (this.options.forceChunking || file.size > this.options.chunkSize), - totalChunkCount: Math.ceil(file.size / this.options.chunkSize) + filename: this._renameFile(file) // Not setting chunking information here, because the acutal data — and + // thus the chunks — might change if `options.transformFile` is set + // and does something to the data. + }; this.files.push(file); - file.status = Dropzone.ADDED; - this.emit("addedfile", file); this._enqueueThumbnail(file); - return this.accept(file, function (error) { + this.accept(file, function (error) { if (error) { file.accepted = false; + _this7._errorProcessing([file], error); // Will set the file.status + } else { file.accepted = true; + if (_this7.options.autoQueue) { _this7.enqueueFile(file); } // Will set .accepted = true + } - return _this7._updateMaxFilesReachedClass(); - }); - } - // Wrapper for enqueueFile + _this7._updateMaxFilesReachedClass(); + }); + } // Wrapper for enqueueFile }, { key: "enqueueFiles", value: function enqueueFiles(files) { - for (var _iterator17 = files, _isArray17 = true, _i18 = 0, _iterator17 = _isArray17 ? _iterator17 : _iterator17[Symbol.iterator]();;) { - var _ref16; + var _iteratorNormalCompletion16 = true; + var _didIteratorError16 = false; + var _iteratorError16 = undefined; - if (_isArray17) { - if (_i18 >= _iterator17.length) break; - _ref16 = _iterator17[_i18++]; - } else { - _i18 = _iterator17.next(); - if (_i18.done) break; - _ref16 = _i18.value; + try { + for (var _iterator16 = files[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) { + var file = _step16.value; + this.enqueueFile(file); + } + } catch (err) { + _didIteratorError16 = true; + _iteratorError16 = err; + } finally { + try { + if (!_iteratorNormalCompletion16 && _iterator16["return"] != null) { + _iterator16["return"](); + } + } finally { + if (_didIteratorError16) { + throw _iteratorError16; + } } - - var file = _ref16; - - this.enqueueFile(file); } + return null; } }, { @@ -1875,6 +1968,7 @@ var Dropzone = function (_Emitter) { if (file.status === Dropzone.ADDED && file.accepted === true) { file.status = Dropzone.QUEUED; + if (this.options.autoProcessQueue) { return setTimeout(function () { return _this8.processQueue(); @@ -1891,6 +1985,7 @@ var Dropzone = function (_Emitter) { if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) { this._thumbnailQueue.push(file); + return setTimeout(function () { return _this9._processThumbnailQueue(); }, 0); // Deferring the call @@ -1906,15 +2001,16 @@ var Dropzone = function (_Emitter) { } this._processingThumbnail = true; + var file = this._thumbnailQueue.shift(); + return this.createThumbnail(file, this.options.thumbnailWidth, this.options.thumbnailHeight, this.options.thumbnailMethod, true, function (dataUrl) { _this10.emit("thumbnail", file, dataUrl); + _this10._processingThumbnail = false; return _this10._processThumbnailQueue(); }); - } - - // Can be called by the user to remove a file + } // Can be called by the user to remove a file }, { key: "removeFile", @@ -1922,15 +2018,14 @@ var Dropzone = function (_Emitter) { if (file.status === Dropzone.UPLOADING) { this.cancelUpload(file); } - this.files = without(this.files, file); + this.files = without(this.files, file); this.emit("removedfile", file); + if (this.files.length === 0) { return this.emit("reset"); } - } - - // Removes all files that aren't currently processed from the list + } // Removes all files that aren't currently processed from the list }, { key: "removeAllFiles", @@ -1939,28 +2034,36 @@ var Dropzone = function (_Emitter) { if (cancelIfNecessary == null) { cancelIfNecessary = false; } - for (var _iterator18 = this.files.slice(), _isArray18 = true, _i19 = 0, _iterator18 = _isArray18 ? _iterator18 : _iterator18[Symbol.iterator]();;) { - var _ref17; - if (_isArray18) { - if (_i19 >= _iterator18.length) break; - _ref17 = _iterator18[_i19++]; - } else { - _i19 = _iterator18.next(); - if (_i19.done) break; - _ref17 = _i19.value; - } + var _iteratorNormalCompletion17 = true; + var _didIteratorError17 = false; + var _iteratorError17 = undefined; - var file = _ref17; + try { + for (var _iterator17 = this.files.slice()[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) { + var file = _step17.value; - if (file.status !== Dropzone.UPLOADING || cancelIfNecessary) { - this.removeFile(file); + if (file.status !== Dropzone.UPLOADING || cancelIfNecessary) { + this.removeFile(file); + } + } + } catch (err) { + _didIteratorError17 = true; + _iteratorError17 = err; + } finally { + try { + if (!_iteratorNormalCompletion17 && _iterator17["return"] != null) { + _iterator17["return"](); + } + } finally { + if (_didIteratorError17) { + throw _iteratorError17; + } } } - return null; - } - // Resizes an image before it gets sent to the server. This function is the default behavior of + return null; + } // Resizes an image before it gets sent to the server. This function is the default behavior of // `options.transformFile` if `resizeWidth` or `resizeHeight` are set. The callback is invoked with // the resized blob. @@ -1979,11 +2082,14 @@ var Dropzone = function (_Emitter) { if (resizeMimeType == null) { resizeMimeType = file.type; } + var resizedDataURL = canvas.toDataURL(resizeMimeType, _this11.options.resizeQuality); + if (resizeMimeType === 'image/jpeg' || resizeMimeType === 'image/jpg') { // Now add the original EXIF information resizedDataURL = ExifRestore.restore(file.dataURL, resizedDataURL); } + return callback(Dropzone.dataURItoBlob(resizedDataURL)); } }); @@ -1996,26 +2102,54 @@ var Dropzone = function (_Emitter) { var fileReader = new FileReader(); fileReader.onload = function () { + file.dataURL = fileReader.result; // Don't bother creating a thumbnail for SVG images since they're vector - file.dataURL = fileReader.result; - - // Don't bother creating a thumbnail for SVG images since they're vector if (file.type === "image/svg+xml") { if (callback != null) { callback(fileReader.result); } + return; } - return _this12.createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback); + _this12.createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback); }; - return fileReader.readAsDataURL(file); + fileReader.readAsDataURL(file); + } // `mockFile` needs to have these attributes: + // + // { name: 'name', size: 12345, imageUrl: '' } + // + // `callback` will be invoked when the image has been downloaded and displayed. + // `crossOrigin` will be added to the `img` tag when accessing the file. + + }, { + key: "displayExistingFile", + value: function displayExistingFile(mockFile, imageUrl, callback, crossOrigin) { + var _this13 = this; + + var resizeThumbnail = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; + this.emit("addedfile", mockFile); + this.emit("complete", mockFile); + + if (!resizeThumbnail) { + this.emit("thumbnail", mockFile, imageUrl); + if (callback) callback(); + } else { + var onDone = function onDone(thumbnail) { + _this13.emit('thumbnail', mockFile, thumbnail); + + if (callback) callback(); + }; + + mockFile.dataURL = imageUrl; + this.createThumbnailFromUrl(mockFile, this.options.thumbnailWidth, this.options.thumbnailHeight, this.options.resizeMethod, this.options.fixOrientation, onDone, crossOrigin); + } } }, { key: "createThumbnailFromUrl", value: function createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback, crossOrigin) { - var _this13 = this; + var _this14 = this; // Not using `new Image` here because of a bug in latest Chrome versions. // See https://github.com/enyo/dropzone/pull/226 @@ -2029,6 +2163,7 @@ var Dropzone = function (_Emitter) { var loadExif = function loadExif(callback) { return callback(1); }; + if (typeof EXIF !== 'undefined' && EXIF !== null && fixOrientation) { loadExif = function loadExif(callback) { return EXIF.getData(img, function () { @@ -2041,11 +2176,10 @@ var Dropzone = function (_Emitter) { file.width = img.width; file.height = img.height; - var resizeInfo = _this13.options.resize.call(_this13, file, width, height, resizeMethod); + var resizeInfo = _this14.options.resize.call(_this14, file, width, height, resizeMethod); var canvas = document.createElement("canvas"); var ctx = canvas.getContext("2d"); - canvas.width = resizeInfo.trgWidth; canvas.height = resizeInfo.trgHeight; @@ -2060,42 +2194,47 @@ var Dropzone = function (_Emitter) { ctx.translate(canvas.width, 0); ctx.scale(-1, 1); break; + case 3: // 180° rotate left ctx.translate(canvas.width, canvas.height); ctx.rotate(Math.PI); break; + case 4: // vertical flip ctx.translate(0, canvas.height); ctx.scale(1, -1); break; + case 5: // vertical flip + 90 rotate right ctx.rotate(0.5 * Math.PI); ctx.scale(1, -1); break; + case 6: // 90° rotate right ctx.rotate(0.5 * Math.PI); ctx.translate(0, -canvas.width); break; + case 7: // horizontal flip + 90 rotate right ctx.rotate(0.5 * Math.PI); ctx.translate(canvas.height, -canvas.width); ctx.scale(-1, 1); break; + case 8: // 90° rotate left ctx.rotate(-0.5 * Math.PI); ctx.translate(-canvas.height, 0); break; - } + } // This is a bugfix for iOS' scaling bug. - // This is a bugfix for iOS' scaling bug. - 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); + 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); var thumbnail = canvas.toDataURL("image/png"); if (callback != null) { @@ -2109,19 +2248,15 @@ var Dropzone = function (_Emitter) { } return img.src = file.dataURL; - } - - // Goes through the queue and processes files if there aren't too many already. + } // Goes through the queue and processes files if there aren't too many already. }, { key: "processQueue", value: function processQueue() { var parallelUploads = this.options.parallelUploads; - var processingLength = this.getUploadingFiles().length; - var i = processingLength; + var i = processingLength; // There are already at least as many files uploading than should be - // There are already at least as many files uploading than should be if (processingLength >= parallelUploads) { return; } @@ -2140,43 +2275,48 @@ var Dropzone = function (_Emitter) { if (!queuedFiles.length) { return; } // Nothing left to process + + this.processFile(queuedFiles.shift()); i++; } } - } - - // Wrapper for `processFiles` + } // Wrapper for `processFiles` }, { key: "processFile", value: function processFile(file) { return this.processFiles([file]); - } - - // Loads the file, then calls finishedLoading() + } // Loads the file, then calls finishedLoading() }, { key: "processFiles", value: function processFiles(files) { - for (var _iterator19 = files, _isArray19 = true, _i20 = 0, _iterator19 = _isArray19 ? _iterator19 : _iterator19[Symbol.iterator]();;) { - var _ref18; + var _iteratorNormalCompletion18 = true; + var _didIteratorError18 = false; + var _iteratorError18 = undefined; - if (_isArray19) { - if (_i20 >= _iterator19.length) break; - _ref18 = _iterator19[_i20++]; - } else { - _i20 = _iterator19.next(); - if (_i20.done) break; - _ref18 = _i20.value; + try { + for (var _iterator18 = files[Symbol.iterator](), _step18; !(_iteratorNormalCompletion18 = (_step18 = _iterator18.next()).done); _iteratorNormalCompletion18 = true) { + var file = _step18.value; + file.processing = true; // Backwards compatibility + + file.status = Dropzone.UPLOADING; + this.emit("processing", file); + } + } catch (err) { + _didIteratorError18 = true; + _iteratorError18 = err; + } finally { + try { + if (!_iteratorNormalCompletion18 && _iterator18["return"] != null) { + _iterator18["return"](); + } + } finally { + if (_didIteratorError18) { + throw _iteratorError18; + } } - - var file = _ref18; - - file.processing = true; // Backwards compatibility - file.status = Dropzone.UPLOADING; - - this.emit("processing", file); } if (this.options.uploadMultiple) { @@ -2188,15 +2328,13 @@ var Dropzone = function (_Emitter) { }, { key: "_getFilesWithXhr", value: function _getFilesWithXhr(xhr) { - var files = void 0; + var files; return files = this.files.filter(function (file) { return file.xhr === xhr; }).map(function (file) { return file; }); - } - - // Cancels the file upload and sets the status to CANCELED + } // Cancels the file upload and sets the status to CANCELED // **if** the file is actually being uploaded. // If it's still in the queue, the file is being removed from it and the status // set to CANCELED. @@ -2206,47 +2344,66 @@ var Dropzone = function (_Emitter) { value: function cancelUpload(file) { if (file.status === Dropzone.UPLOADING) { var groupedFiles = this._getFilesWithXhr(file.xhr); - for (var _iterator20 = groupedFiles, _isArray20 = true, _i21 = 0, _iterator20 = _isArray20 ? _iterator20 : _iterator20[Symbol.iterator]();;) { - var _ref19; - if (_isArray20) { - if (_i21 >= _iterator20.length) break; - _ref19 = _iterator20[_i21++]; - } else { - _i21 = _iterator20.next(); - if (_i21.done) break; - _ref19 = _i21.value; - } + var _iteratorNormalCompletion19 = true; + var _didIteratorError19 = false; + var _iteratorError19 = undefined; - var groupedFile = _ref19; - - groupedFile.status = Dropzone.CANCELED; + try { + for (var _iterator19 = groupedFiles[Symbol.iterator](), _step19; !(_iteratorNormalCompletion19 = (_step19 = _iterator19.next()).done); _iteratorNormalCompletion19 = true) { + var groupedFile = _step19.value; + groupedFile.status = Dropzone.CANCELED; + } + } catch (err) { + _didIteratorError19 = true; + _iteratorError19 = err; + } finally { + try { + if (!_iteratorNormalCompletion19 && _iterator19["return"] != null) { + _iterator19["return"](); + } + } finally { + if (_didIteratorError19) { + throw _iteratorError19; + } + } } + if (typeof file.xhr !== 'undefined') { file.xhr.abort(); } - for (var _iterator21 = groupedFiles, _isArray21 = true, _i22 = 0, _iterator21 = _isArray21 ? _iterator21 : _iterator21[Symbol.iterator]();;) { - var _ref20; - if (_isArray21) { - if (_i22 >= _iterator21.length) break; - _ref20 = _iterator21[_i22++]; - } else { - _i22 = _iterator21.next(); - if (_i22.done) break; - _ref20 = _i22.value; - } + var _iteratorNormalCompletion20 = true; + var _didIteratorError20 = false; + var _iteratorError20 = undefined; - var _groupedFile = _ref20; - - this.emit("canceled", _groupedFile); + try { + for (var _iterator20 = groupedFiles[Symbol.iterator](), _step20; !(_iteratorNormalCompletion20 = (_step20 = _iterator20.next()).done); _iteratorNormalCompletion20 = true) { + var _groupedFile = _step20.value; + this.emit("canceled", _groupedFile); + } + } catch (err) { + _didIteratorError20 = true; + _iteratorError20 = err; + } finally { + try { + if (!_iteratorNormalCompletion20 && _iterator20["return"] != null) { + _iterator20["return"](); + } + } finally { + if (_didIteratorError20) { + throw _iteratorError20; + } + } } + if (this.options.uploadMultiple) { this.emit("canceledmultiple", groupedFiles); } } else if (file.status === Dropzone.ADDED || file.status === Dropzone.QUEUED) { file.status = Dropzone.CANCELED; this.emit("canceled", file); + if (this.options.uploadMultiple) { this.emit("canceledmultiple", [file]); } @@ -2260,12 +2417,13 @@ var Dropzone = function (_Emitter) { key: "resolveOption", value: function resolveOption(option) { if (typeof option === 'function') { - for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { + for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { args[_key3 - 1] = arguments[_key3]; } return option.apply(this, args); } + return option; } }, { @@ -2276,81 +2434,84 @@ var Dropzone = function (_Emitter) { }, { key: "uploadFiles", value: function uploadFiles(files) { - var _this14 = this; + var _this15 = this; this._transformFiles(files, function (transformedFiles) { + if (_this15.options.chunking) { + // Chunking is not allowed to be used with `uploadMultiple` so we know + // that there is only __one__file. + var transformedFile = transformedFiles[0]; + files[0].upload.chunked = _this15.options.chunking && (_this15.options.forceChunking || transformedFile.size > _this15.options.chunkSize); + files[0].upload.totalChunkCount = Math.ceil(transformedFile.size / _this15.options.chunkSize); + } + if (files[0].upload.chunked) { // This file should be sent in chunks! - // If the chunking option is set, we **know** that there can only be **one** file, since // uploadMultiple is not allowed with this option. var file = files[0]; - var transformedFile = transformedFiles[0]; + var _transformedFile = transformedFiles[0]; var startedChunkCount = 0; - file.upload.chunks = []; var handleNextChunk = function handleNextChunk() { - var chunkIndex = 0; + var chunkIndex = 0; // Find the next item in file.upload.chunks that is not defined yet. - // Find the next item in file.upload.chunks that is not defined yet. while (file.upload.chunks[chunkIndex] !== undefined) { chunkIndex++; - } + } // This means, that all chunks have already been started. - // This means, that all chunks have already been started. - if (chunkIndex >= file.upload.totalChunkCount) return; + if (chunkIndex >= file.upload.totalChunkCount) return; startedChunkCount++; - - var start = chunkIndex * _this14.options.chunkSize; - var end = Math.min(start + _this14.options.chunkSize, file.size); - + var start = chunkIndex * _this15.options.chunkSize; + var end = Math.min(start + _this15.options.chunkSize, file.size); var dataBlock = { - name: _this14._getParamName(0), - data: transformedFile.webkitSlice ? transformedFile.webkitSlice(start, end) : transformedFile.slice(start, end), + name: _this15._getParamName(0), + data: _transformedFile.webkitSlice ? _transformedFile.webkitSlice(start, end) : _transformedFile.slice(start, end), filename: file.upload.filename, chunkIndex: chunkIndex }; - file.upload.chunks[chunkIndex] = { file: file, index: chunkIndex, - dataBlock: dataBlock, // In case we want to retry. + dataBlock: dataBlock, + // In case we want to retry. status: Dropzone.UPLOADING, progress: 0, retries: 0 // The number of times this block has been retried. + }; - _this14._uploadData(files, [dataBlock]); + _this15._uploadData(files, [dataBlock]); }; file.upload.finishedChunkUpload = function (chunk) { var allFinished = true; - chunk.status = Dropzone.SUCCESS; + chunk.status = Dropzone.SUCCESS; // Clear the data from the chunk + + chunk.dataBlock = null; // Leaving this reference to xhr intact here will cause memory leaks in some browsers - // Clear the data from the chunk - chunk.dataBlock = null; - // Leaving this reference to xhr intact here will cause memory leaks in some browsers chunk.xhr = null; for (var i = 0; i < file.upload.totalChunkCount; i++) { if (file.upload.chunks[i] === undefined) { return handleNextChunk(); } + if (file.upload.chunks[i].status !== Dropzone.SUCCESS) { allFinished = false; } } if (allFinished) { - _this14.options.chunksUploaded(file, function () { - _this14._finished(files, '', null); + _this15.options.chunksUploaded(file, function () { + _this15._finished(files, '', null); }); } }; - if (_this14.options.parallelChunkUploads) { + if (_this15.options.parallelChunkUploads) { for (var i = 0; i < file.upload.totalChunkCount; i++) { handleNextChunk(); } @@ -2359,19 +2520,19 @@ var Dropzone = function (_Emitter) { } } else { var dataBlocks = []; - for (var _i23 = 0; _i23 < files.length; _i23++) { - dataBlocks[_i23] = { - name: _this14._getParamName(_i23), - data: transformedFiles[_i23], - filename: files[_i23].upload.filename + + for (var _i3 = 0; _i3 < files.length; _i3++) { + dataBlocks[_i3] = { + name: _this15._getParamName(_i3), + data: transformedFiles[_i3], + filename: files[_i3].upload.filename }; } - _this14._uploadData(files, dataBlocks); + + _this15._uploadData(files, dataBlocks); } }); - } - - /// Returns the right chunk for given file and xhr + } /// Returns the right chunk for given file and xhr }, { key: "_getChunk", @@ -2381,36 +2542,41 @@ var Dropzone = function (_Emitter) { return file.upload.chunks[i]; } } - } - - // This function actually uploads the file(s) to the server. + } // This function actually uploads the file(s) to the server. // If dataBlocks contains the actual data to upload (meaning, that this could either be transformed // files, or individual chunks for chunked upload). }, { key: "_uploadData", value: function _uploadData(files, dataBlocks) { - var _this15 = this; + var _this16 = this; - var xhr = new XMLHttpRequest(); + var xhr = new XMLHttpRequest(); // Put the xhr object in the file objects to be able to reference it later. - // Put the xhr object in the file objects to be able to reference it later. - for (var _iterator22 = files, _isArray22 = true, _i24 = 0, _iterator22 = _isArray22 ? _iterator22 : _iterator22[Symbol.iterator]();;) { - var _ref21; + var _iteratorNormalCompletion21 = true; + var _didIteratorError21 = false; + var _iteratorError21 = undefined; - if (_isArray22) { - if (_i24 >= _iterator22.length) break; - _ref21 = _iterator22[_i24++]; - } else { - _i24 = _iterator22.next(); - if (_i24.done) break; - _ref21 = _i24.value; + try { + for (var _iterator21 = files[Symbol.iterator](), _step21; !(_iteratorNormalCompletion21 = (_step21 = _iterator21.next()).done); _iteratorNormalCompletion21 = true) { + var file = _step21.value; + file.xhr = xhr; + } + } catch (err) { + _didIteratorError21 = true; + _iteratorError21 = err; + } finally { + try { + if (!_iteratorNormalCompletion21 && _iterator21["return"] != null) { + _iterator21["return"](); + } + } finally { + if (_didIteratorError21) { + throw _iteratorError21; + } } - - var file = _ref21; - - file.xhr = xhr; } + if (files[0].upload.chunked) { // Put the xhr object in the right chunk object, so it can be associated later, and found with _getChunk files[0].upload.chunks[dataBlocks[0].chunkIndex].xhr = xhr; @@ -2418,26 +2584,29 @@ var Dropzone = function (_Emitter) { var method = this.resolveOption(this.options.method, files); var url = this.resolveOption(this.options.url, files); - xhr.open(method, url, true); + xhr.open(method, url, true); // Setting the timeout after open because of IE11 issue: https://gitlab.com/meno/dropzone/issues/8 - // Setting the timeout after open because of IE11 issue: https://gitlab.com/meno/dropzone/issues/8 - xhr.timeout = this.resolveOption(this.options.timeout, files); + xhr.timeout = this.resolveOption(this.options.timeout, files); // Has to be after `.open()`. See https://github.com/enyo/dropzone/issues/179 - // Has to be after `.open()`. See https://github.com/enyo/dropzone/issues/179 xhr.withCredentials = !!this.options.withCredentials; xhr.onload = function (e) { - _this15._finishedUploading(files, xhr, e); + _this16._finishedUploading(files, xhr, e); }; - xhr.onerror = function () { - _this15._handleUploadError(files, xhr); + xhr.ontimeout = function () { + _this16._handleUploadError(files, xhr, "Request timedout after ".concat(_this16.options.timeout, " seconds")); }; - // Some browsers do not have the .upload property + xhr.onerror = function () { + _this16._handleUploadError(files, xhr); + }; // Some browsers do not have the .upload property + + var progressObj = xhr.upload != null ? xhr.upload : xhr; + progressObj.onprogress = function (e) { - return _this15._updateFilesUploadProgress(files, xhr, e); + return _this16._updateFilesUploadProgress(files, xhr, e); }; var headers = { @@ -2452,16 +2621,17 @@ var Dropzone = function (_Emitter) { for (var headerName in headers) { var headerValue = headers[headerName]; + if (headerValue) { xhr.setRequestHeader(headerName, headerValue); } } - var formData = new FormData(); + var formData = new FormData(); // Adding all @options parameters - // Adding all @options parameters if (this.options.params) { var additionalParams = this.options.params; + if (typeof additionalParams === 'function') { additionalParams = additionalParams.call(this, files, xhr, files[0].upload.chunked ? this._getChunk(files[0], xhr) : null); } @@ -2470,55 +2640,62 @@ var Dropzone = function (_Emitter) { var value = additionalParams[key]; formData.append(key, value); } - } + } // Let the user add additional data if necessary - // Let the user add additional data if necessary - for (var _iterator23 = files, _isArray23 = true, _i25 = 0, _iterator23 = _isArray23 ? _iterator23 : _iterator23[Symbol.iterator]();;) { - var _ref22; - - if (_isArray23) { - if (_i25 >= _iterator23.length) break; - _ref22 = _iterator23[_i25++]; - } else { - _i25 = _iterator23.next(); - if (_i25.done) break; - _ref22 = _i25.value; - } - var _file = _ref22; + var _iteratorNormalCompletion22 = true; + var _didIteratorError22 = false; + var _iteratorError22 = undefined; - this.emit("sending", _file, xhr, formData); + try { + for (var _iterator22 = files[Symbol.iterator](), _step22; !(_iteratorNormalCompletion22 = (_step22 = _iterator22.next()).done); _iteratorNormalCompletion22 = true) { + var _file = _step22.value; + this.emit("sending", _file, xhr, formData); + } + } catch (err) { + _didIteratorError22 = true; + _iteratorError22 = err; + } finally { + try { + if (!_iteratorNormalCompletion22 && _iterator22["return"] != null) { + _iterator22["return"](); + } + } finally { + if (_didIteratorError22) { + throw _iteratorError22; + } + } } + if (this.options.uploadMultiple) { this.emit("sendingmultiple", files, xhr, formData); } - this._addFormElementData(formData); - - // Finally add the files + this._addFormElementData(formData); // Finally add the files // Has to be last because some servers (eg: S3) expect the file to be the last parameter + + for (var i = 0; i < dataBlocks.length; i++) { var dataBlock = dataBlocks[i]; formData.append(dataBlock.name, dataBlock.data, dataBlock.filename); } this.submitRequest(xhr, formData, files); - } - - // Transforms all files with this.options.transformFile and invokes done with the transformed files when done. + } // Transforms all files with this.options.transformFile and invokes done with the transformed files when done. }, { key: "_transformFiles", value: function _transformFiles(files, done) { - var _this16 = this; + var _this17 = this; + + var transformedFiles = []; // Clumsy way of handling asynchronous calls, until I get to add a proper Future library. - var transformedFiles = []; - // Clumsy way of handling asynchronous calls, until I get to add a proper Future library. var doneCounter = 0; var _loop = function _loop(i) { - _this16.options.transformFile.call(_this16, files[i], function (transformedFile) { + _this17.options.transformFile.call(_this17, files[i], function (transformedFile) { transformedFiles[i] = transformedFile; + if (++doneCounter === files.length) { done(transformedFiles); } @@ -2528,86 +2705,99 @@ var Dropzone = function (_Emitter) { for (var i = 0; i < files.length; i++) { _loop(i); } - } - - // Takes care of adding other input elements of the form to the AJAX request + } // Takes care of adding other input elements of the form to the AJAX request }, { key: "_addFormElementData", value: function _addFormElementData(formData) { // Take care of other input elements if (this.element.tagName === "FORM") { - for (var _iterator24 = this.element.querySelectorAll("input, textarea, select, button"), _isArray24 = true, _i26 = 0, _iterator24 = _isArray24 ? _iterator24 : _iterator24[Symbol.iterator]();;) { - var _ref23; - - if (_isArray24) { - if (_i26 >= _iterator24.length) break; - _ref23 = _iterator24[_i26++]; - } else { - _i26 = _iterator24.next(); - if (_i26.done) break; - _ref23 = _i26.value; - } - - var input = _ref23; - - var inputName = input.getAttribute("name"); - var inputType = input.getAttribute("type"); - if (inputType) inputType = inputType.toLowerCase(); - - // If the input doesn't have a name, we can't use it. - if (typeof inputName === 'undefined' || inputName === null) continue; - - if (input.tagName === "SELECT" && input.hasAttribute("multiple")) { - // Possibly multiple values - for (var _iterator25 = input.options, _isArray25 = true, _i27 = 0, _iterator25 = _isArray25 ? _iterator25 : _iterator25[Symbol.iterator]();;) { - var _ref24; - - if (_isArray25) { - if (_i27 >= _iterator25.length) break; - _ref24 = _iterator25[_i27++]; - } else { - _i27 = _iterator25.next(); - if (_i27.done) break; - _ref24 = _i27.value; - } - - var option = _ref24; - - if (option.selected) { - formData.append(inputName, option.value); + var _iteratorNormalCompletion23 = true; + var _didIteratorError23 = false; + var _iteratorError23 = undefined; + + try { + for (var _iterator23 = this.element.querySelectorAll("input, textarea, select, button")[Symbol.iterator](), _step23; !(_iteratorNormalCompletion23 = (_step23 = _iterator23.next()).done); _iteratorNormalCompletion23 = true) { + var input = _step23.value; + var inputName = input.getAttribute("name"); + var inputType = input.getAttribute("type"); + if (inputType) inputType = inputType.toLowerCase(); // If the input doesn't have a name, we can't use it. + + if (typeof inputName === 'undefined' || inputName === null) continue; + + if (input.tagName === "SELECT" && input.hasAttribute("multiple")) { + // Possibly multiple values + var _iteratorNormalCompletion24 = true; + var _didIteratorError24 = false; + var _iteratorError24 = undefined; + + try { + for (var _iterator24 = input.options[Symbol.iterator](), _step24; !(_iteratorNormalCompletion24 = (_step24 = _iterator24.next()).done); _iteratorNormalCompletion24 = true) { + var option = _step24.value; + + if (option.selected) { + formData.append(inputName, option.value); + } + } + } catch (err) { + _didIteratorError24 = true; + _iteratorError24 = err; + } finally { + try { + if (!_iteratorNormalCompletion24 && _iterator24["return"] != null) { + _iterator24["return"](); + } + } finally { + if (_didIteratorError24) { + throw _iteratorError24; + } + } } + } else if (!inputType || inputType !== "checkbox" && inputType !== "radio" || input.checked) { + formData.append(inputName, input.value); + } + } + } catch (err) { + _didIteratorError23 = true; + _iteratorError23 = err; + } finally { + try { + if (!_iteratorNormalCompletion23 && _iterator23["return"] != null) { + _iterator23["return"](); + } + } finally { + if (_didIteratorError23) { + throw _iteratorError23; } - } else if (!inputType || inputType !== "checkbox" && inputType !== "radio" || input.checked) { - formData.append(inputName, input.value); } } } - } - - // Invoked when there is new progress information about given files. + } // Invoked when there is new progress information about given files. // If e is not provided, it is assumed that the upload is finished. }, { key: "_updateFilesUploadProgress", value: function _updateFilesUploadProgress(files, xhr, e) { - var progress = void 0; + var progress; + if (typeof e !== 'undefined') { progress = 100 * e.loaded / e.total; if (files[0].upload.chunked) { - var file = files[0]; - // Since this is a chunked upload, we need to update the appropriate chunk progress. + var file = files[0]; // Since this is a chunked upload, we need to update the appropriate chunk progress. + var chunk = this._getChunk(file, xhr); + chunk.progress = progress; chunk.total = e.total; chunk.bytesSent = e.loaded; var fileProgress = 0, - fileTotal = void 0, - fileBytesSent = void 0; + fileTotal, + fileBytesSent; file.upload.progress = 0; file.upload.total = 0; file.upload.bytesSent = 0; + for (var i = 0; i < file.upload.totalChunkCount; i++) { if (file.upload.chunks[i] !== undefined && file.upload.chunks[i].progress !== undefined) { file.upload.progress += file.upload.chunks[i].progress; @@ -2615,98 +2805,127 @@ var Dropzone = function (_Emitter) { file.upload.bytesSent += file.upload.chunks[i].bytesSent; } } + file.upload.progress = file.upload.progress / file.upload.totalChunkCount; } else { - for (var _iterator26 = files, _isArray26 = true, _i28 = 0, _iterator26 = _isArray26 ? _iterator26 : _iterator26[Symbol.iterator]();;) { - var _ref25; + var _iteratorNormalCompletion25 = true; + var _didIteratorError25 = false; + var _iteratorError25 = undefined; - if (_isArray26) { - if (_i28 >= _iterator26.length) break; - _ref25 = _iterator26[_i28++]; - } else { - _i28 = _iterator26.next(); - if (_i28.done) break; - _ref25 = _i28.value; + try { + for (var _iterator25 = files[Symbol.iterator](), _step25; !(_iteratorNormalCompletion25 = (_step25 = _iterator25.next()).done); _iteratorNormalCompletion25 = true) { + var _file2 = _step25.value; + _file2.upload.progress = progress; + _file2.upload.total = e.total; + _file2.upload.bytesSent = e.loaded; + } + } catch (err) { + _didIteratorError25 = true; + _iteratorError25 = err; + } finally { + try { + if (!_iteratorNormalCompletion25 && _iterator25["return"] != null) { + _iterator25["return"](); + } + } finally { + if (_didIteratorError25) { + throw _iteratorError25; + } } - - var _file2 = _ref25; - - _file2.upload.progress = progress; - _file2.upload.total = e.total; - _file2.upload.bytesSent = e.loaded; } } - for (var _iterator27 = files, _isArray27 = true, _i29 = 0, _iterator27 = _isArray27 ? _iterator27 : _iterator27[Symbol.iterator]();;) { - var _ref26; - - if (_isArray27) { - if (_i29 >= _iterator27.length) break; - _ref26 = _iterator27[_i29++]; - } else { - _i29 = _iterator27.next(); - if (_i29.done) break; - _ref26 = _i29.value; - } - var _file3 = _ref26; + var _iteratorNormalCompletion26 = true; + var _didIteratorError26 = false; + var _iteratorError26 = undefined; - this.emit("uploadprogress", _file3, _file3.upload.progress, _file3.upload.bytesSent); + try { + for (var _iterator26 = files[Symbol.iterator](), _step26; !(_iteratorNormalCompletion26 = (_step26 = _iterator26.next()).done); _iteratorNormalCompletion26 = true) { + var _file3 = _step26.value; + this.emit("uploadprogress", _file3, _file3.upload.progress, _file3.upload.bytesSent); + } + } catch (err) { + _didIteratorError26 = true; + _iteratorError26 = err; + } finally { + try { + if (!_iteratorNormalCompletion26 && _iterator26["return"] != null) { + _iterator26["return"](); + } + } finally { + if (_didIteratorError26) { + throw _iteratorError26; + } + } } } else { // Called when the file finished uploading - var allFilesFinished = true; - progress = 100; + var _iteratorNormalCompletion27 = true; + var _didIteratorError27 = false; + var _iteratorError27 = undefined; - for (var _iterator28 = files, _isArray28 = true, _i30 = 0, _iterator28 = _isArray28 ? _iterator28 : _iterator28[Symbol.iterator]();;) { - var _ref27; + try { + for (var _iterator27 = files[Symbol.iterator](), _step27; !(_iteratorNormalCompletion27 = (_step27 = _iterator27.next()).done); _iteratorNormalCompletion27 = true) { + var _file4 = _step27.value; - if (_isArray28) { - if (_i30 >= _iterator28.length) break; - _ref27 = _iterator28[_i30++]; - } else { - _i30 = _iterator28.next(); - if (_i30.done) break; - _ref27 = _i30.value; - } + if (_file4.upload.progress !== 100 || _file4.upload.bytesSent !== _file4.upload.total) { + allFilesFinished = false; + } - var _file4 = _ref27; + _file4.upload.progress = progress; + _file4.upload.bytesSent = _file4.upload.total; + } // Nothing to do, all files already at 100% - if (_file4.upload.progress !== 100 || _file4.upload.bytesSent !== _file4.upload.total) { - allFilesFinished = false; + } catch (err) { + _didIteratorError27 = true; + _iteratorError27 = err; + } finally { + try { + if (!_iteratorNormalCompletion27 && _iterator27["return"] != null) { + _iterator27["return"](); + } + } finally { + if (_didIteratorError27) { + throw _iteratorError27; + } } - _file4.upload.progress = progress; - _file4.upload.bytesSent = _file4.upload.total; } - // Nothing to do, all files already at 100% if (allFilesFinished) { return; } - for (var _iterator29 = files, _isArray29 = true, _i31 = 0, _iterator29 = _isArray29 ? _iterator29 : _iterator29[Symbol.iterator]();;) { - var _ref28; + var _iteratorNormalCompletion28 = true; + var _didIteratorError28 = false; + var _iteratorError28 = undefined; - if (_isArray29) { - if (_i31 >= _iterator29.length) break; - _ref28 = _iterator29[_i31++]; - } else { - _i31 = _iterator29.next(); - if (_i31.done) break; - _ref28 = _i31.value; + try { + for (var _iterator28 = files[Symbol.iterator](), _step28; !(_iteratorNormalCompletion28 = (_step28 = _iterator28.next()).done); _iteratorNormalCompletion28 = true) { + var _file5 = _step28.value; + this.emit("uploadprogress", _file5, progress, _file5.upload.bytesSent); + } + } catch (err) { + _didIteratorError28 = true; + _iteratorError28 = err; + } finally { + try { + if (!_iteratorNormalCompletion28 && _iterator28["return"] != null) { + _iterator28["return"](); + } + } finally { + if (_didIteratorError28) { + throw _iteratorError28; + } } - - var _file5 = _ref28; - - this.emit("uploadprogress", _file5, progress, _file5.upload.bytesSent); } } } }, { key: "_finishedUploading", value: function _finishedUploading(files, xhr, e) { - var response = void 0; + var response; if (files[0].status === Dropzone.CANCELED) { return; @@ -2750,61 +2969,54 @@ var Dropzone = function (_Emitter) { if (files[0].upload.chunked && this.options.retryChunks) { var chunk = this._getChunk(files[0], xhr); + if (chunk.retries++ < this.options.retryChunksLimit) { this._uploadData(files, [chunk.dataBlock]); + return; } else { console.warn('Retried this chunk too often. Giving up.'); } } - for (var _iterator30 = files, _isArray30 = true, _i32 = 0, _iterator30 = _isArray30 ? _iterator30 : _iterator30[Symbol.iterator]();;) { - var _ref29; - - if (_isArray30) { - if (_i32 >= _iterator30.length) break; - _ref29 = _iterator30[_i32++]; - } else { - _i32 = _iterator30.next(); - if (_i32.done) break; - _ref29 = _i32.value; - } - - var file = _ref29; - - this._errorProcessing(files, response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr); - } + this._errorProcessing(files, response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr); } }, { key: "submitRequest", value: function submitRequest(xhr, formData, files) { xhr.send(formData); - } - - // Called internally when processing is finished. + } // Called internally when processing is finished. // Individual callbacks have to be called in the appropriate sections. }, { key: "_finished", value: function _finished(files, responseText, e) { - for (var _iterator31 = files, _isArray31 = true, _i33 = 0, _iterator31 = _isArray31 ? _iterator31 : _iterator31[Symbol.iterator]();;) { - var _ref30; + var _iteratorNormalCompletion29 = true; + var _didIteratorError29 = false; + var _iteratorError29 = undefined; - if (_isArray31) { - if (_i33 >= _iterator31.length) break; - _ref30 = _iterator31[_i33++]; - } else { - _i33 = _iterator31.next(); - if (_i33.done) break; - _ref30 = _i33.value; + try { + for (var _iterator29 = files[Symbol.iterator](), _step29; !(_iteratorNormalCompletion29 = (_step29 = _iterator29.next()).done); _iteratorNormalCompletion29 = true) { + var file = _step29.value; + file.status = Dropzone.SUCCESS; + this.emit("success", file, responseText, e); + this.emit("complete", file); + } + } catch (err) { + _didIteratorError29 = true; + _iteratorError29 = err; + } finally { + try { + if (!_iteratorNormalCompletion29 && _iterator29["return"] != null) { + _iterator29["return"](); + } + } finally { + if (_didIteratorError29) { + throw _iteratorError29; + } } - - var file = _ref30; - - file.status = Dropzone.SUCCESS; - this.emit("success", file, responseText, e); - this.emit("complete", file); } + if (this.options.uploadMultiple) { this.emit("successmultiple", files, responseText, e); this.emit("completemultiple", files); @@ -2813,32 +3025,38 @@ var Dropzone = function (_Emitter) { if (this.options.autoProcessQueue) { return this.processQueue(); } - } - - // Called internally when processing is finished. + } // Called internally when processing is finished. // Individual callbacks have to be called in the appropriate sections. }, { key: "_errorProcessing", value: function _errorProcessing(files, message, xhr) { - for (var _iterator32 = files, _isArray32 = true, _i34 = 0, _iterator32 = _isArray32 ? _iterator32 : _iterator32[Symbol.iterator]();;) { - var _ref31; + var _iteratorNormalCompletion30 = true; + var _didIteratorError30 = false; + var _iteratorError30 = undefined; - if (_isArray32) { - if (_i34 >= _iterator32.length) break; - _ref31 = _iterator32[_i34++]; - } else { - _i34 = _iterator32.next(); - if (_i34.done) break; - _ref31 = _i34.value; + try { + for (var _iterator30 = files[Symbol.iterator](), _step30; !(_iteratorNormalCompletion30 = (_step30 = _iterator30.next()).done); _iteratorNormalCompletion30 = true) { + var file = _step30.value; + file.status = Dropzone.ERROR; + this.emit("error", file, message, xhr); + this.emit("complete", file); + } + } catch (err) { + _didIteratorError30 = true; + _iteratorError30 = err; + } finally { + try { + if (!_iteratorNormalCompletion30 && _iterator30["return"] != null) { + _iterator30["return"](); + } + } finally { + if (_didIteratorError30) { + throw _iteratorError30; + } } - - var file = _ref31; - - file.status = Dropzone.ERROR; - this.emit("error", file, message, xhr); - this.emit("complete", file); } + if (this.options.uploadMultiple) { this.emit("errormultiple", files, message, xhr); this.emit("completemultiple", files); @@ -2863,10 +3081,7 @@ var Dropzone = function (_Emitter) { }(Emitter); Dropzone.initClass(); - -Dropzone.version = "5.5.0"; - -// This is a map of options for your different dropzones. Add configurations +Dropzone.version = "5.7.1"; // This is a map of options for your different dropzones. Add configurations // to this object for your different dropzone elemens. // // Example: @@ -2880,9 +3095,9 @@ Dropzone.version = "5.5.0"; // And in html: // //
-Dropzone.options = {}; -// Returns the options for an element or undefined if none available. +Dropzone.options = {}; // Returns the options for an element or undefined if none available. + Dropzone.optionsForElement = function (element) { // Get the `Dropzone.options.elementId` for this element if it exists if (element.getAttribute("id")) { @@ -2890,91 +3105,109 @@ Dropzone.optionsForElement = function (element) { } else { return undefined; } -}; +}; // Holds a list of all dropzone instances + -// Holds a list of all dropzone instances -Dropzone.instances = []; +Dropzone.instances = []; // Returns the dropzone for given element if any -// Returns the dropzone for given element if any Dropzone.forElement = function (element) { if (typeof element === "string") { element = document.querySelector(element); } + 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."); } + return element.dropzone; -}; +}; // Set to false if you don't want Dropzone to automatically find and attach to .dropzone elements. -// Set to false if you don't want Dropzone to automatically find and attach to .dropzone elements. -Dropzone.autoDiscover = true; -// Looks for all .dropzone elements and creates a dropzone for them +Dropzone.autoDiscover = true; // Looks for all .dropzone elements and creates a dropzone for them + Dropzone.discover = function () { - var dropzones = void 0; + var dropzones; + if (document.querySelectorAll) { dropzones = document.querySelectorAll(".dropzone"); } else { - dropzones = []; - // IE :( + dropzones = []; // IE :( + var checkElements = function checkElements(elements) { return function () { var result = []; - for (var _iterator33 = elements, _isArray33 = true, _i35 = 0, _iterator33 = _isArray33 ? _iterator33 : _iterator33[Symbol.iterator]();;) { - var _ref32; + var _iteratorNormalCompletion31 = true; + var _didIteratorError31 = false; + var _iteratorError31 = undefined; - if (_isArray33) { - if (_i35 >= _iterator33.length) break; - _ref32 = _iterator33[_i35++]; - } else { - _i35 = _iterator33.next(); - if (_i35.done) break; - _ref32 = _i35.value; - } - - var el = _ref32; + try { + for (var _iterator31 = elements[Symbol.iterator](), _step31; !(_iteratorNormalCompletion31 = (_step31 = _iterator31.next()).done); _iteratorNormalCompletion31 = true) { + var el = _step31.value; - if (/(^| )dropzone($| )/.test(el.className)) { - result.push(dropzones.push(el)); - } else { - result.push(undefined); + if (/(^| )dropzone($| )/.test(el.className)) { + result.push(dropzones.push(el)); + } else { + result.push(undefined); + } + } + } catch (err) { + _didIteratorError31 = true; + _iteratorError31 = err; + } finally { + try { + if (!_iteratorNormalCompletion31 && _iterator31["return"] != null) { + _iterator31["return"](); + } + } finally { + if (_didIteratorError31) { + throw _iteratorError31; + } } } + return result; }(); }; + checkElements(document.getElementsByTagName("div")); checkElements(document.getElementsByTagName("form")); } return function () { var result = []; - for (var _iterator34 = dropzones, _isArray34 = true, _i36 = 0, _iterator34 = _isArray34 ? _iterator34 : _iterator34[Symbol.iterator]();;) { - var _ref33; - - if (_isArray34) { - if (_i36 >= _iterator34.length) break; - _ref33 = _iterator34[_i36++]; - } else { - _i36 = _iterator34.next(); - if (_i36.done) break; - _ref33 = _i36.value; - } + var _iteratorNormalCompletion32 = true; + var _didIteratorError32 = false; + var _iteratorError32 = undefined; - var dropzone = _ref33; + try { + for (var _iterator32 = dropzones[Symbol.iterator](), _step32; !(_iteratorNormalCompletion32 = (_step32 = _iterator32.next()).done); _iteratorNormalCompletion32 = true) { + var dropzone = _step32.value; - // Create a dropzone unless auto discover has been disabled for specific element - if (Dropzone.optionsForElement(dropzone) !== false) { - result.push(new Dropzone(dropzone)); - } else { - result.push(undefined); + // Create a dropzone unless auto discover has been disabled for specific element + if (Dropzone.optionsForElement(dropzone) !== false) { + result.push(new Dropzone(dropzone)); + } else { + result.push(undefined); + } + } + } catch (err) { + _didIteratorError32 = true; + _iteratorError32 = err; + } finally { + try { + if (!_iteratorNormalCompletion32 && _iterator32["return"] != null) { + _iterator32["return"](); + } + } finally { + if (_didIteratorError32) { + throw _iteratorError32; + } } } + return result; }(); -}; - -// Since the whole Drag'n'Drop API is pretty new, some browsers implement it, +}; // Since the whole Drag'n'Drop API is pretty new, some browsers implement it, // but not correctly. // So I created a blacklist of userAgents. Yes, yes. Browser sniffing, I know. // But what to do when browsers *theoretically* support an API, but crash @@ -2985,11 +3218,11 @@ Dropzone.discover = function () { // ** It should only be used on browser that *do* support the API, but // incorrectly ** // -Dropzone.blacklistedBrowsers = [ -// The mac os and windows phone version of opera 12 seems to have a problem with the File drag'n'drop API. -/opera.*(Macintosh|Windows Phone).*version\/12/i]; -// Checks if the browser is supported + +Dropzone.blacklistedBrowsers = [// The mac os and windows phone version of opera 12 seems to have a problem with the File drag'n'drop API. +/opera.*(Macintosh|Windows Phone).*version\/12/i]; // Checks if the browser is supported + Dropzone.isBrowserSupported = function () { var capableBrowser = true; @@ -2998,23 +3231,31 @@ Dropzone.isBrowserSupported = function () { capableBrowser = false; } else { // The browser supports the API, but may be blacklisted. - for (var _iterator35 = Dropzone.blacklistedBrowsers, _isArray35 = true, _i37 = 0, _iterator35 = _isArray35 ? _iterator35 : _iterator35[Symbol.iterator]();;) { - var _ref34; + var _iteratorNormalCompletion33 = true; + var _didIteratorError33 = false; + var _iteratorError33 = undefined; - if (_isArray35) { - if (_i37 >= _iterator35.length) break; - _ref34 = _iterator35[_i37++]; - } else { - _i37 = _iterator35.next(); - if (_i37.done) break; - _ref34 = _i37.value; - } - - var regex = _ref34; + try { + for (var _iterator33 = Dropzone.blacklistedBrowsers[Symbol.iterator](), _step33; !(_iteratorNormalCompletion33 = (_step33 = _iterator33.next()).done); _iteratorNormalCompletion33 = true) { + var regex = _step33.value; - if (regex.test(navigator.userAgent)) { - capableBrowser = false; - continue; + if (regex.test(navigator.userAgent)) { + capableBrowser = false; + continue; + } + } + } catch (err) { + _didIteratorError33 = true; + _iteratorError33 = err; + } finally { + try { + if (!_iteratorNormalCompletion33 && _iterator33["return"] != null) { + _iterator33["return"](); + } + } finally { + if (_didIteratorError33) { + throw _iteratorError33; + } } } } @@ -3028,176 +3269,214 @@ Dropzone.isBrowserSupported = function () { Dropzone.dataURItoBlob = function (dataURI) { // convert base64 to raw binary data held in a string // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this - var byteString = atob(dataURI.split(',')[1]); + var byteString = atob(dataURI.split(',')[1]); // separate out the mime component - // separate out the mime component - var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; + var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; // write the bytes of the string to an ArrayBuffer - // write the bytes of the string to an ArrayBuffer var ab = new ArrayBuffer(byteString.length); var ia = new Uint8Array(ab); + for (var i = 0, end = byteString.length, asc = 0 <= end; asc ? i <= end : i >= end; asc ? i++ : i--) { ia[i] = byteString.charCodeAt(i); - } + } // write the ArrayBuffer to a blob + + + return new Blob([ab], { + type: mimeString + }); +}; // Returns an array without the rejected item - // write the ArrayBuffer to a blob - return new Blob([ab], { type: mimeString }); -}; -// Returns an array without the rejected item var without = function without(list, rejectedItem) { return list.filter(function (item) { return item !== rejectedItem; }).map(function (item) { return item; }); -}; +}; // abc-def_ghi -> abcDefGhi + -// abc-def_ghi -> abcDefGhi var camelize = function camelize(str) { return str.replace(/[\-_](\w)/g, function (match) { return match.charAt(1).toUpperCase(); }); -}; +}; // Creates an element from string + -// Creates an element from string Dropzone.createElement = function (string) { var div = document.createElement("div"); div.innerHTML = string; return div.childNodes[0]; -}; +}; // Tests if given element is inside (or simply is) the container + -// Tests if given element is inside (or simply is) the container Dropzone.elementInside = function (element, container) { if (element === container) { return true; } // Coffeescript doesn't support do/while loops + + while (element = element.parentNode) { if (element === container) { return true; } } + return false; }; Dropzone.getElement = function (el, name) { - var element = void 0; + var element; + if (typeof el === "string") { element = document.querySelector(el); } else if (el.nodeType != null) { element = el; } + if (element == null) { - throw new Error("Invalid `" + name + "` option provided. Please provide a CSS selector or a plain HTML element."); + throw new Error("Invalid `".concat(name, "` option provided. Please provide a CSS selector or a plain HTML element.")); } + return element; }; Dropzone.getElements = function (els, name) { - var el = void 0, - elements = void 0; + var el, elements; + if (els instanceof Array) { elements = []; + try { - for (var _iterator36 = els, _isArray36 = true, _i38 = 0, _iterator36 = _isArray36 ? _iterator36 : _iterator36[Symbol.iterator]();;) { - if (_isArray36) { - if (_i38 >= _iterator36.length) break; - el = _iterator36[_i38++]; - } else { - _i38 = _iterator36.next(); - if (_i38.done) break; - el = _i38.value; - } + var _iteratorNormalCompletion34 = true; + var _didIteratorError34 = false; + var _iteratorError34 = undefined; - elements.push(this.getElement(el, name)); + try { + for (var _iterator34 = els[Symbol.iterator](), _step34; !(_iteratorNormalCompletion34 = (_step34 = _iterator34.next()).done); _iteratorNormalCompletion34 = true) { + el = _step34.value; + elements.push(this.getElement(el, name)); + } + } catch (err) { + _didIteratorError34 = true; + _iteratorError34 = err; + } finally { + try { + if (!_iteratorNormalCompletion34 && _iterator34["return"] != null) { + _iterator34["return"](); + } + } finally { + if (_didIteratorError34) { + throw _iteratorError34; + } + } } } catch (e) { elements = null; } } else if (typeof els === "string") { elements = []; - for (var _iterator37 = document.querySelectorAll(els), _isArray37 = true, _i39 = 0, _iterator37 = _isArray37 ? _iterator37 : _iterator37[Symbol.iterator]();;) { - if (_isArray37) { - if (_i39 >= _iterator37.length) break; - el = _iterator37[_i39++]; - } else { - _i39 = _iterator37.next(); - if (_i39.done) break; - el = _i39.value; - } + var _iteratorNormalCompletion35 = true; + var _didIteratorError35 = false; + var _iteratorError35 = undefined; - elements.push(el); + try { + for (var _iterator35 = document.querySelectorAll(els)[Symbol.iterator](), _step35; !(_iteratorNormalCompletion35 = (_step35 = _iterator35.next()).done); _iteratorNormalCompletion35 = true) { + el = _step35.value; + elements.push(el); + } + } catch (err) { + _didIteratorError35 = true; + _iteratorError35 = err; + } finally { + try { + if (!_iteratorNormalCompletion35 && _iterator35["return"] != null) { + _iterator35["return"](); + } + } finally { + if (_didIteratorError35) { + throw _iteratorError35; + } + } } } else if (els.nodeType != null) { elements = [els]; } if (elements == null || !elements.length) { - throw new Error("Invalid `" + name + "` option provided. Please provide a CSS selector, a plain HTML element or a list of those."); + throw new Error("Invalid `".concat(name, "` option provided. Please provide a CSS selector, a plain HTML element or a list of those.")); } return elements; -}; - -// Asks the user the question and calls accepted or rejected accordingly +}; // Asks the user the question and calls accepted or rejected accordingly // // The default implementation just uses `window.confirm` and then calls the // appropriate callback. + + Dropzone.confirm = function (question, accepted, rejected) { if (window.confirm(question)) { return accepted(); } else if (rejected != null) { return rejected(); } -}; - -// Validates the mime type like this: +}; // Validates the mime type like this: // // https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-accept + + Dropzone.isValidFile = function (file, acceptedFiles) { if (!acceptedFiles) { return true; } // If there are no accepted mime types, it's OK - acceptedFiles = acceptedFiles.split(","); + + acceptedFiles = acceptedFiles.split(","); var mimeType = file.type; var baseMimeType = mimeType.replace(/\/.*$/, ""); + var _iteratorNormalCompletion36 = true; + var _didIteratorError36 = false; + var _iteratorError36 = undefined; - for (var _iterator38 = acceptedFiles, _isArray38 = true, _i40 = 0, _iterator38 = _isArray38 ? _iterator38 : _iterator38[Symbol.iterator]();;) { - var _ref35; - - if (_isArray38) { - if (_i40 >= _iterator38.length) break; - _ref35 = _iterator38[_i40++]; - } else { - _i40 = _iterator38.next(); - if (_i40.done) break; - _ref35 = _i40.value; - } - - var validType = _ref35; + try { + for (var _iterator36 = acceptedFiles[Symbol.iterator](), _step36; !(_iteratorNormalCompletion36 = (_step36 = _iterator36.next()).done); _iteratorNormalCompletion36 = true) { + var validType = _step36.value; + validType = validType.trim(); - validType = validType.trim(); - if (validType.charAt(0) === ".") { - if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) { - return true; + if (validType.charAt(0) === ".") { + if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) { + return true; + } + } else if (/\/\*$/.test(validType)) { + // This is something like a image/* mime type + if (baseMimeType === validType.replace(/\/.*$/, "")) { + return true; + } + } else { + if (mimeType === validType) { + return true; + } } - } else if (/\/\*$/.test(validType)) { - // This is something like a image/* mime type - if (baseMimeType === validType.replace(/\/.*$/, "")) { - return true; + } + } catch (err) { + _didIteratorError36 = true; + _iteratorError36 = err; + } finally { + try { + if (!_iteratorNormalCompletion36 && _iterator36["return"] != null) { + _iterator36["return"](); } - } else { - if (mimeType === validType) { - return true; + } finally { + if (_didIteratorError36) { + throw _iteratorError36; } } } return false; -}; +}; // Augment jQuery + -// Augment jQuery if (typeof jQuery !== 'undefined' && jQuery !== null) { jQuery.fn.dropzone = function (options) { return this.each(function () { @@ -3210,23 +3489,20 @@ if (typeof module !== 'undefined' && module !== null) { module.exports = Dropzone; } else { window.Dropzone = Dropzone; -} +} // Dropzone file status codes -// Dropzone file status codes -Dropzone.ADDED = "added"; -Dropzone.QUEUED = "queued"; -// For backwards compatibility. Now, if a file is accepted, it's either queued +Dropzone.ADDED = "added"; +Dropzone.QUEUED = "queued"; // For backwards compatibility. Now, if a file is accepted, it's either queued // or uploading. -Dropzone.ACCEPTED = Dropzone.QUEUED; +Dropzone.ACCEPTED = Dropzone.QUEUED; Dropzone.UPLOADING = "uploading"; Dropzone.PROCESSING = Dropzone.UPLOADING; // alias Dropzone.CANCELED = "canceled"; Dropzone.ERROR = "error"; Dropzone.SUCCESS = "success"; - /* Bugfix for iOS 6 and 7 @@ -3234,10 +3510,10 @@ Dropzone.SUCCESS = "success"; based on the work of https://github.com/stomita/ios-imagefile-megapixel */ - // Detecting vertical squash in loaded image. // Fixes a bug which squash image vertically while drawing into canvas for some images. // This is a bug in iOS6 devices. This function from https://github.com/stomita/ios-imagefile-megapixel + var detectVerticalSquash = function detectVerticalSquash(img) { var iw = img.naturalWidth; var ih = img.naturalHeight; @@ -3248,14 +3524,13 @@ var detectVerticalSquash = function detectVerticalSquash(img) { ctx.drawImage(img, 0, 0); var _ctx$getImageData = ctx.getImageData(1, 0, 1, ih), - data = _ctx$getImageData.data; - - // search image edge pixel position in case it is squashed vertically. + data = _ctx$getImageData.data; // search image edge pixel position in case it is squashed vertically. var sy = 0; var ey = ih; var py = ih; + while (py > sy) { var alpha = data[(py - 1) * 4 + 3]; @@ -3267,6 +3542,7 @@ var detectVerticalSquash = function detectVerticalSquash(img) { py = ey + sy >> 1; } + var ratio = py / ih; if (ratio === 0) { @@ -3274,20 +3550,21 @@ var detectVerticalSquash = function detectVerticalSquash(img) { } else { return ratio; } -}; - -// A replacement for context.drawImage +}; // A replacement for context.drawImage // (args are for source and destination). + + var drawImageIOSFix = function drawImageIOSFix(ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) { var vertSquashRatio = detectVerticalSquash(img); return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio); -}; - -// Based on MinifyJpeg +}; // Based on MinifyJpeg // Source: http://www.perry.cz/files/ExifRestorer.js // http://elicon.blog57.fc2.com/blog-entry-206.html -var ExifRestore = function () { + +var ExifRestore = +/*#__PURE__*/ +function () { function ExifRestore() { _classCallCheck(this, ExifRestore); } @@ -3309,6 +3586,7 @@ var ExifRestore = function () { var enc3 = undefined; var enc4 = ''; var i = 0; + while (true) { chr1 = input[i++]; chr2 = input[i++]; @@ -3317,18 +3595,22 @@ var ExifRestore = function () { enc2 = (chr1 & 3) << 4 | chr2 >> 4; enc3 = (chr2 & 15) << 2 | chr3 >> 6; enc4 = chr3 & 63; + if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } + output = output + this.KEY_STR.charAt(enc1) + this.KEY_STR.charAt(enc2) + this.KEY_STR.charAt(enc3) + this.KEY_STR.charAt(enc4); chr1 = chr2 = chr3 = ''; enc1 = enc2 = enc3 = enc4 = ''; + if (!(i < input.length)) { break; } } + return output; } }, { @@ -3337,10 +3619,11 @@ var ExifRestore = function () { if (!origFileBase64.match('data:image/jpeg;base64,')) { return resizedFileBase64; } + var rawImage = this.decode64(origFileBase64.replace('data:image/jpeg;base64,', '')); var segments = this.slice2Segments(rawImage); var image = this.exifManipulation(resizedFileBase64, segments); - return "data:image/jpeg;base64," + this.encode64(image); + return "data:image/jpeg;base64,".concat(this.encode64(image)); } }, { key: "exifManipulation", @@ -3355,13 +3638,17 @@ var ExifRestore = function () { value: function getExifArray(segments) { var seg = undefined; var x = 0; + while (x < segments.length) { seg = segments[x]; + if (seg[0] === 255 & seg[1] === 225) { return seg; } + x++; } + return []; } }, { @@ -3382,11 +3669,14 @@ var ExifRestore = function () { value: function slice2Segments(rawImageArray) { var head = 0; var segments = []; + while (true) { var length; + if (rawImageArray[head] === 255 & rawImageArray[head + 1] === 218) { break; } + if (rawImageArray[head] === 255 & rawImageArray[head + 1] === 216) { head += 2; } else { @@ -3396,10 +3686,12 @@ var ExifRestore = function () { segments.push(seg); head = endPoint; } + if (head > rawImageArray.length) { break; } } + return segments; } }, { @@ -3414,13 +3706,16 @@ var ExifRestore = function () { var enc3 = undefined; var enc4 = ''; var i = 0; - var buf = []; - // remove all characters that are not A-Z, a-z, 0-9, +, /, or = + var buf = []; // remove all characters that are not A-Z, a-z, 0-9, +, /, or = + var base64test = /[^A-Za-z0-9\+\/\=]/g; + 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.'); } + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ''); + while (true) { enc1 = this.KEY_STR.indexOf(input.charAt(i++)); enc2 = this.KEY_STR.indexOf(input.charAt(i++)); @@ -3430,18 +3725,23 @@ var ExifRestore = function () { chr2 = (enc2 & 15) << 4 | enc3 >> 2; chr3 = (enc3 & 3) << 6 | enc4; buf.push(chr1); + if (enc3 !== 64) { buf.push(chr2); } + if (enc4 !== 64) { buf.push(chr3); } + chr1 = chr2 = chr3 = ''; enc1 = enc2 = enc3 = enc4 = ''; + if (!(i < input.length)) { break; } } + return buf; } }]); @@ -3450,7 +3750,6 @@ var ExifRestore = function () { }(); ExifRestore.initClass(); - /* * contentloaded.js * @@ -3464,9 +3763,9 @@ ExifRestore.initClass(); * http://javascript.nwbox.com/ContentLoaded/ * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE */ - // @win window reference // @fn function reference + var contentLoaded = function contentLoaded(win, fn) { var done = false; var top = true; @@ -3475,11 +3774,14 @@ var contentLoaded = function contentLoaded(win, fn) { var add = doc.addEventListener ? "addEventListener" : "attachEvent"; var rem = doc.addEventListener ? "removeEventListener" : "detachEvent"; var pre = doc.addEventListener ? "" : "on"; + var init = function init(e) { if (e.type === "readystatechange" && doc.readyState !== "complete") { return; } + (e.type === "load" ? win : doc)[rem](pre + e.type, init, false); + if (!done && (done = true)) { return fn.call(win, e.type || e); } @@ -3492,6 +3794,7 @@ var contentLoaded = function contentLoaded(win, fn) { setTimeout(poll, 50); return; } + return init("poll"); }; @@ -3500,27 +3803,31 @@ var contentLoaded = function contentLoaded(win, fn) { try { top = !win.frameElement; } catch (error) {} + if (top) { poll(); } } + doc[add](pre + "DOMContentLoaded", init, false); doc[add](pre + "readystatechange", init, false); return win[add](pre + "load", init, false); } -}; +}; // As a single function to be able to write tests. + -// As a single function to be able to write tests. Dropzone._autoDiscoverFunction = function () { if (Dropzone.autoDiscover) { return Dropzone.discover(); } }; + contentLoaded(window, Dropzone._autoDiscoverFunction); function __guard__(value, transform) { return typeof value !== 'undefined' && value !== null ? transform(value) : undefined; } + function __guardMethod__(obj, methodName, transform) { if (typeof obj !== 'undefined' && obj !== null && typeof obj[methodName] === 'function') { return transform(obj, methodName); diff --git a/app/assets/stylesheets/dropzone/dropzone.scss b/app/assets/stylesheets/dropzone/dropzone.scss index 0494d1c..93a9146 100755 --- a/app/assets/stylesheets/dropzone/dropzone.scss +++ b/app/assets/stylesheets/dropzone/dropzone.scss @@ -193,6 +193,14 @@ .dropzone .dz-message { text-align: center; margin: 2em 0; } + .dropzone .dz-message .dz-button { + background: none; + color: inherit; + border: none; + padding: 0; + font: inherit; + cursor: pointer; + outline: inherit; } .dropzone .dz-preview { position: relative; display: inline-block; diff --git a/lib/dropzonejs-rails/version.rb b/lib/dropzonejs-rails/version.rb index f7eecc5..1a5623f 100644 --- a/lib/dropzonejs-rails/version.rb +++ b/lib/dropzonejs-rails/version.rb @@ -1,4 +1,4 @@ module DropzonejsRails - VERSION = '0.8.4' - DROPZONE_VERSION = '5.5.0' + VERSION = '0.8.5' + DROPZONE_VERSION = '5.7.1' end