mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
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.
This commit is contained in:
10
emccpre.js
10
emccpre.js
@ -391,13 +391,10 @@ function initPuzzle() {
|
|||||||
|
|
||||||
document.getElementById("load").onclick = function(event) {
|
document.getElementById("load").onclick = function(event) {
|
||||||
if (dlg_dimmer === null) {
|
if (dlg_dimmer === null) {
|
||||||
dialog_init("Upload saved-game file");
|
|
||||||
var input = document.createElement("input");
|
var input = document.createElement("input");
|
||||||
input.type = "file";
|
input.type = "file";
|
||||||
input.multiple = false;
|
input.multiple = false;
|
||||||
dlg_form.appendChild(input);
|
input.addEventListener("change", function(event) {
|
||||||
dlg_form.appendChild(document.createElement("br"));
|
|
||||||
dialog_launch(function(event) {
|
|
||||||
if (input.files.length == 1) {
|
if (input.files.length == 1) {
|
||||||
var file = input.files.item(0);
|
var file = input.files.item(0);
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
@ -407,10 +404,9 @@ function initPuzzle() {
|
|||||||
});
|
});
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
}
|
}
|
||||||
dialog_cleanup();
|
|
||||||
}, function(event) {
|
|
||||||
dialog_cleanup();
|
|
||||||
});
|
});
|
||||||
|
input.click();
|
||||||
|
onscreen_canvas.focus();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user