aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-12-03 23:51:12 +0000
committerBen Harris <bjh21@bjh21.me.uk>2022-12-05 14:07:03 +0000
commitf8ed76f815494de031c86441bf392f8658ff383d (patch)
tree1974c92a0d69cb4dc8301ee05d51a8116c8dfd06
parentdb5d3bf10e934e86fcdb792f49ae5cf28e1a2a8c (diff)
downloadpuzzles-f8ed76f815494de031c86441bf392f8658ff383d.zip
puzzles-f8ed76f815494de031c86441bf392f8658ff383d.tar.gz
puzzles-f8ed76f815494de031c86441bf392f8658ff383d.tar.bz2
puzzles-f8ed76f815494de031c86441bf392f8658ff383d.tar.xz
js: Bypass our own dialogue box when loading
By constructing the <input type=file> off screen and activating it from JavaScript, we can jump straight to the browser's upload dialogue box without interposing our own one. This gives a smoother experience, and also avoids the difficult-to-handle <input type=file> ever being visible.
-rw-r--r--emccpre.js10
1 files changed, 3 insertions, 7 deletions
diff --git a/emccpre.js b/emccpre.js
index f384222..4cd5787 100644
--- a/emccpre.js
+++ b/emccpre.js
@@ -391,13 +391,10 @@ function initPuzzle() {
document.getElementById("load").onclick = function(event) {
if (dlg_dimmer === null) {
- dialog_init("Upload saved-game file");
var input = document.createElement("input");
input.type = "file";
input.multiple = false;
- dlg_form.appendChild(input);
- dlg_form.appendChild(document.createElement("br"));
- dialog_launch(function(event) {
+ input.addEventListener("change", function(event) {
if (input.files.length == 1) {
var file = input.files.item(0);
var reader = new FileReader();
@@ -407,10 +404,9 @@ function initPuzzle() {
});
reader.readAsText(file);
}
- dialog_cleanup();
- }, function(event) {
- dialog_cleanup();
});
+ input.click();
+ onscreen_canvas.focus();
}
};