aboutsummaryrefslogtreecommitdiff
path: root/client/js/controls/file_dropper_control.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/js/controls/file_dropper_control.js')
-rw-r--r--client/js/controls/file_dropper_control.js94
1 files changed, 52 insertions, 42 deletions
diff --git a/client/js/controls/file_dropper_control.js b/client/js/controls/file_dropper_control.js
index a618720..2dfb492 100644
--- a/client/js/controls/file_dropper_control.js
+++ b/client/js/controls/file_dropper_control.js
@@ -1,9 +1,9 @@
-'use strict';
+"use strict";
-const events = require('../events.js');
-const views = require('../util/views.js');
+const events = require("../events.js");
+const views = require("../util/views.js");
-const template = views.getTemplate('file-dropper');
+const template = views.getTemplate("file-dropper");
const KEY_RETURN = 13;
@@ -17,37 +17,42 @@ class FileDropperControl extends events.EventTarget {
allowMultiple: options.allowMultiple,
allowUrls: options.allowUrls,
lock: options.lock,
- id: 'file-' + Math.random().toString(36).substring(7),
+ id: "file-" + Math.random().toString(36).substring(7),
urlPlaceholder:
- options.urlPlaceholder || 'Alternatively, paste an URL here.',
+ options.urlPlaceholder || "Alternatively, paste an URL here.",
});
- this._dropperNode = source.querySelector('.file-dropper');
- this._urlInputNode = source.querySelector('input[type=text]');
- this._urlConfirmButtonNode = source.querySelector('button');
- this._fileInputNode = source.querySelector('input[type=file]');
- this._fileInputNode.style.display = 'none';
+ this._dropperNode = source.querySelector(".file-dropper");
+ this._urlInputNode = source.querySelector("input[type=text]");
+ this._urlConfirmButtonNode = source.querySelector("button");
+ this._fileInputNode = source.querySelector("input[type=file]");
+ this._fileInputNode.style.display = "none";
this._fileInputNode.multiple = options.allowMultiple || false;
this._counter = 0;
- this._dropperNode.addEventListener(
- 'dragenter', e => this._evtDragEnter(e));
- this._dropperNode.addEventListener(
- 'dragleave', e => this._evtDragLeave(e));
- this._dropperNode.addEventListener(
- 'dragover', e => this._evtDragOver(e));
- this._dropperNode.addEventListener(
- 'drop', e => this._evtDrop(e));
- this._fileInputNode.addEventListener(
- 'change', e => this._evtFileChange(e));
+ this._dropperNode.addEventListener("dragenter", (e) =>
+ this._evtDragEnter(e)
+ );
+ this._dropperNode.addEventListener("dragleave", (e) =>
+ this._evtDragLeave(e)
+ );
+ this._dropperNode.addEventListener("dragover", (e) =>
+ this._evtDragOver(e)
+ );
+ this._dropperNode.addEventListener("drop", (e) => this._evtDrop(e));
+ this._fileInputNode.addEventListener("change", (e) =>
+ this._evtFileChange(e)
+ );
if (this._urlInputNode) {
- this._urlInputNode.addEventListener(
- 'keydown', e => this._evtUrlInputKeyDown(e));
+ this._urlInputNode.addEventListener("keydown", (e) =>
+ this._evtUrlInputKeyDown(e)
+ );
}
if (this._urlConfirmButtonNode) {
- this._urlConfirmButtonNode.addEventListener(
- 'click', e => this._evtUrlConfirmButtonClick(e));
+ this._urlConfirmButtonNode.addEventListener("click", (e) =>
+ this._evtUrlConfirmButtonClick(e)
+ );
}
this._originalHtml = this._dropperNode.innerHTML;
@@ -56,24 +61,27 @@ class FileDropperControl extends events.EventTarget {
reset() {
this._dropperNode.innerHTML = this._originalHtml;
- this.dispatchEvent(new CustomEvent('reset'));
+ this.dispatchEvent(new CustomEvent("reset"));
}
_emitFiles(files) {
files = Array.from(files);
if (this._options.lock) {
- this._dropperNode.innerText =
- files.map(file => file.name).join(', ');
+ this._dropperNode.innerText = files
+ .map((file) => file.name)
+ .join(", ");
}
this.dispatchEvent(
- new CustomEvent('fileadd', {detail: {files: files}}));
+ new CustomEvent("fileadd", { detail: { files: files } })
+ );
}
_emitUrls(urls) {
- urls = Array.from(urls).map(url => url.trim());
+ urls = Array.from(urls).map((url) => url.trim());
if (this._options.lock) {
- this._dropperNode.innerText =
- urls.map(url => url.split(/\//).reverse()[0]).join(', ');
+ this._dropperNode.innerText = urls
+ .map((url) => url.split(/\//).reverse()[0])
+ .join(", ");
}
for (let url of urls) {
if (!url) {
@@ -84,18 +92,20 @@ class FileDropperControl extends events.EventTarget {
return;
}
}
- this.dispatchEvent(new CustomEvent('urladd', {detail: {urls: urls}}));
+ this.dispatchEvent(
+ new CustomEvent("urladd", { detail: { urls: urls } })
+ );
}
_evtDragEnter(e) {
- this._dropperNode.classList.add('active');
+ this._dropperNode.classList.add("active");
this._counter++;
}
_evtDragLeave(e) {
this._counter--;
if (this._counter === 0) {
- this._dropperNode.classList.remove('active');
+ this._dropperNode.classList.remove("active");
}
}
@@ -109,12 +119,12 @@ class FileDropperControl extends events.EventTarget {
_evtDrop(e) {
e.preventDefault();
- this._dropperNode.classList.remove('active');
+ this._dropperNode.classList.remove("active");
if (!e.dataTransfer.files.length) {
- window.alert('Only files are supported.');
+ window.alert("Only files are supported.");
}
if (!this._options.allowMultiple && e.dataTransfer.files.length > 1) {
- window.alert('Cannot select multiple files.');
+ window.alert("Cannot select multiple files.");
}
this._emitFiles(e.dataTransfer.files);
}
@@ -124,16 +134,16 @@ class FileDropperControl extends events.EventTarget {
return;
}
e.preventDefault();
- this._dropperNode.classList.remove('active');
+ this._dropperNode.classList.remove("active");
this._emitUrls(this._urlInputNode.value.split(/[\r\n]/));
- this._urlInputNode.value = '';
+ this._urlInputNode.value = "";
}
_evtUrlConfirmButtonClick(e) {
e.preventDefault();
- this._dropperNode.classList.remove('active');
+ this._dropperNode.classList.remove("active");
this._emitUrls(this._urlInputNode.value.split(/[\r\n]/));
- this._urlInputNode.value = '';
+ this._urlInputNode.value = "";
}
}

© 2015 - 2026 Jakob L. Kreuze