diff --git a/src/web/InputWaiter.mjs b/src/web/InputWaiter.mjs index 37f1134..17b48b6 100755 --- a/src/web/InputWaiter.mjs +++ b/src/web/InputWaiter.mjs @@ -243,14 +243,22 @@ class InputWaiter { } if (file) { - this.closeFile(); - this.loaderWorker = new LoaderWorker(); - this.loaderWorker.addEventListener("message", this.handleLoaderMessage.bind(this)); - this.loaderWorker.postMessage({"file": file}); - this.set(file); + this.loadFile(file); } } + /** + * Handler for open input button events + * Loads the opened data into the input textarea + * + * @param {event} e + */ + inputOpen(e) { + e.preventDefault(); + const file = e.srcElement.files[0]; + this.loadFile(file); + } + /** * Handler for messages sent back by the LoaderWorker. @@ -306,6 +314,22 @@ class InputWaiter { } + /** + * Loads a file into the input. + * + * @param {File} file + */ + loadFile(file) { + if (file) { + this.closeFile(); + this.loaderWorker = new LoaderWorker(); + this.loaderWorker.addEventListener("message", this.handleLoaderMessage.bind(this)); + this.loaderWorker.postMessage({"file": file}); + this.set(file); + } + } + + /** * Handler for clear IO events. * Resets the input, output and info areas. diff --git a/src/web/Manager.mjs b/src/web/Manager.mjs index 3f4af77..30cb494 100755 --- a/src/web/Manager.mjs +++ b/src/web/Manager.mjs @@ -146,6 +146,7 @@ class Manager { this.addMultiEventListener("#input-text", "paste", this.input.inputPaste, this.input); document.getElementById("reset-layout").addEventListener("click", this.app.resetLayout.bind(this.app)); document.getElementById("clr-io").addEventListener("click", this.input.clearIoClick.bind(this.input)); + this.addListeners("#open-file", "change", this.input.inputOpen, this.input); this.addListeners("#input-text,#input-file", "dragover", this.input.inputDragover, this.input); this.addListeners("#input-text,#input-file", "dragleave", this.input.inputDragleave, this.input); this.addListeners("#input-text,#input-file", "drop", this.input.inputDrop, this.input); diff --git a/src/web/html/index.html b/src/web/html/index.html index f03590a..74eb0ed 100755 --- a/src/web/html/index.html +++ b/src/web/html/index.html @@ -225,6 +225,10 @@