- this.timeoutMessage = this.$opts.timeoutMessage;
-
- const _this = this;
- this.dz = new DropZoneLib(this.container, {
- addRemoveLinks: true,
- dictRemoveFile: this.removeMessage,
- timeout: Number(window.uploadTimeout) || 60000,
- maxFilesize: Number(window.uploadLimit) || 256,
- url: this.url,
- withCredentials: true,
- init() {
- this.dz = this;
- this.dz.on('sending', _this.onSending.bind(_this));
- this.dz.on('success', _this.onSuccess.bind(_this));
- this.dz.on('error', _this.onError.bind(_this));
+ this.zoneText = this.$opts.zoneText;
+ this.fileAcceptTypes = this.$opts.fileAccept;
+ this.allowMultiple = this.$opts.allowMultiple === 'true';
+
+ this.setupListeners();
+ }
+
+ /**
+ * Public method to allow external disabling/enabling of this drag+drop dropzone.
+ * @param {Boolean} active
+ */
+ toggleActive(active) {
+ this.isActive = active;
+ }
+
+ setupListeners() {
+ onSelect(this.selectButtons, this.manualSelectHandler.bind(this));
+ this.setupDropTargetHandlers();
+ }
+
+ setupDropTargetHandlers() {
+ let depth = 0;
+
+ const reset = () => {
+ this.hideOverlay();
+ depth = 0;
+ };
+
+ this.dropTarget.addEventListener('dragenter', event => {
+ event.preventDefault();
+ depth += 1;
+
+ if (depth === 1 && this.isActive) {
+ this.showOverlay();
+ }
+ });
+
+ this.dropTarget.addEventListener('dragover', event => {
+ event.preventDefault();
+ });
+
+ this.dropTarget.addEventListener('dragend', reset);
+ this.dropTarget.addEventListener('dragleave', () => {
+ depth -= 1;
+ if (depth === 0) {
+ reset();
+ }
+ });
+ this.dropTarget.addEventListener('drop', event => {
+ event.preventDefault();
+ reset();
+
+ if (!this.isActive) {
+ return;
+ }
+
+ const clipboard = new Clipboard(event.dataTransfer);
+ const files = clipboard.getFiles();
+ for (const file of files) {
+ this.createUploadFromFile(file);