mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-22 08:25:45 -07:00
js: use the "load" event for loading save files
This is in place of the "loadend" event. In Chromium, (and in the specification), "loadend" is triggered not only when the file is loaded but also when loading fails. Obviously when loading fails we don't want to try to parse the (nonexistent) resulting file. Using the "load" event works better, since it's only fired on success, and we can also have an "error" handler to report problems with loading files, albeit with no detail at all. This doesn't seem to make any difference in Firefox, which in my testing fires "load" and "loadend" on success and nothing at all on failure.
This commit is contained in:
@ -462,7 +462,7 @@ function initPuzzle() {
|
||||
if (input.files.length == 1) {
|
||||
var file = input.files.item(0);
|
||||
var reader = new FileReader();
|
||||
reader.addEventListener("loadend", function() {
|
||||
reader.addEventListener("load", function() {
|
||||
var pos = 0;
|
||||
savefile_read_callback = function(buf, len) {
|
||||
if (pos + len > reader.result.byteLength)
|
||||
@ -475,6 +475,9 @@ function initPuzzle() {
|
||||
load_game();
|
||||
savefile_read_callback = null;
|
||||
});
|
||||
reader.addEventListener("error", function() {
|
||||
alert("An error occured while loading the file");
|
||||
});
|
||||
reader.readAsArrayBuffer(file);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user