mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-25 18:33:11 +00:00
get rid of Safari error (DOM operation aborted when changing URL)
This commit is contained in:
parent
1fa51ae5d4
commit
a7afff1ea6
51
src/ui.js
51
src/ui.js
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// catch errors
|
// catch errors
|
||||||
|
function installErrorHandler() {
|
||||||
if (typeof window.onerror == "object") {
|
if (typeof window.onerror == "object") {
|
||||||
window.onerror = function (msgevent, url, line, col, error) {
|
window.onerror = function (msgevent, url, line, col, error) {
|
||||||
console.log(msgevent, url, line, col);
|
console.log(msgevent, url, line, col);
|
||||||
@ -15,6 +16,16 @@ if (typeof window.onerror == "object") {
|
|||||||
alert(msgevent+"");
|
alert(msgevent+"");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function uninstallErrorHandler() {
|
||||||
|
window.onerror = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function gotoNewLocation() {
|
||||||
|
uninstallErrorHandler();
|
||||||
|
window.location = "?" + $.param(qs);
|
||||||
|
}
|
||||||
|
|
||||||
// make sure VCS doesn't start
|
// make sure VCS doesn't start
|
||||||
Javatari.AUTO_START = false;
|
Javatari.AUTO_START = false;
|
||||||
@ -196,13 +207,13 @@ function loadPreset(preset_id) {
|
|||||||
function gotoPresetAt(index) {
|
function gotoPresetAt(index) {
|
||||||
var index = (index + PRESETS.length) % PRESETS.length;
|
var index = (index + PRESETS.length) % PRESETS.length;
|
||||||
qs['file'] = PRESETS[index].id;
|
qs['file'] = PRESETS[index].id;
|
||||||
window.location = "?" + $.param(qs);
|
gotoNewLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function gotoPresetNamed(id) {
|
function gotoPresetNamed(id) {
|
||||||
qs['platform'] = platform_id;
|
qs['platform'] = platform_id;
|
||||||
qs['file'] = id;
|
qs['file'] = id;
|
||||||
window.location = "?" + $.param(qs);
|
gotoNewLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function _createNewFile(e) {
|
function _createNewFile(e) {
|
||||||
@ -212,7 +223,7 @@ function _createNewFile(e) {
|
|||||||
filename += ".a";
|
filename += ".a";
|
||||||
}
|
}
|
||||||
qs['file'] = "local/" + filename;
|
qs['file'] = "local/" + filename;
|
||||||
window.location = "?" + $.param(qs);
|
gotoNewLocation();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -249,7 +260,7 @@ function _resetPreset(e) {
|
|||||||
alert("Can only reset built-in file examples.")
|
alert("Can only reset built-in file examples.")
|
||||||
} else if (confirm("Reset '" + PRESETS[current_preset_index].name + "' to default?")) {
|
} else if (confirm("Reset '" + PRESETS[current_preset_index].name + "' to default?")) {
|
||||||
qs['reset'] = '1';
|
qs['reset'] = '1';
|
||||||
window.location = "?" + $.param(qs);
|
gotoNewLocation();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -319,6 +330,17 @@ function arrayCompare(a,b) {
|
|||||||
worker.onmessage = function(e) {
|
worker.onmessage = function(e) {
|
||||||
// errors?
|
// errors?
|
||||||
var toolbar = $("#controls_top");
|
var toolbar = $("#controls_top");
|
||||||
|
function addErrorMarker(line, msg) {
|
||||||
|
var div = document.createElement("div");
|
||||||
|
div.setAttribute("class", "tooltipbox tooltiperror");
|
||||||
|
div.style.color = '#ff3333'; // TODO
|
||||||
|
div.appendChild(document.createTextNode("\u24cd"));
|
||||||
|
var tooltip = document.createElement("span");
|
||||||
|
tooltip.setAttribute("class", "tooltiptext");
|
||||||
|
tooltip.appendChild(document.createTextNode(msg));
|
||||||
|
div.appendChild(tooltip);
|
||||||
|
editor.setGutterMarker(line, "gutter-info", div);
|
||||||
|
}
|
||||||
sourcefile = new SourceFile(e.data.lines);
|
sourcefile = new SourceFile(e.data.lines);
|
||||||
if (e.data.asmlines) {
|
if (e.data.asmlines) {
|
||||||
assemblyfile = new SourceFile(e.data.asmlines, e.data.intermediate.listing);
|
assemblyfile = new SourceFile(e.data.asmlines, e.data.intermediate.listing);
|
||||||
@ -327,19 +349,10 @@ worker.onmessage = function(e) {
|
|||||||
toolbar.addClass("has-errors");
|
toolbar.addClass("has-errors");
|
||||||
editor.clearGutter("gutter-info");
|
editor.clearGutter("gutter-info");
|
||||||
for (info of e.data.errors) {
|
for (info of e.data.errors) {
|
||||||
var div = document.createElement("div");
|
addErrorMarker(info.line-1, info.msg);
|
||||||
div.setAttribute("class", "tooltipbox tooltiperror");
|
|
||||||
div.style.color = '#ff3333'; // TODO
|
|
||||||
div.appendChild(document.createTextNode("\u24cd"));
|
|
||||||
var tooltip = document.createElement("span");
|
|
||||||
tooltip.setAttribute("class", "tooltiptext");
|
|
||||||
tooltip.appendChild(document.createTextNode(info.msg));
|
|
||||||
div.appendChild(tooltip);
|
|
||||||
editor.setGutterMarker(info.line-1, "gutter-info", div);
|
|
||||||
}
|
}
|
||||||
current_output = null;
|
current_output = null;
|
||||||
} else {
|
} else {
|
||||||
toolbar.removeClass("has-errors");
|
|
||||||
updatePreset(current_preset_id, editor.getValue()); // update persisted entry
|
updatePreset(current_preset_id, editor.getValue()); // update persisted entry
|
||||||
// load ROM
|
// load ROM
|
||||||
var rom = e.data.output;
|
var rom = e.data.output;
|
||||||
@ -349,12 +362,13 @@ worker.onmessage = function(e) {
|
|||||||
//console.log("Loading ROM length", rom.length);
|
//console.log("Loading ROM length", rom.length);
|
||||||
platform.loadROM(getCurrentPresetTitle(), rom);
|
platform.loadROM(getCurrentPresetTitle(), rom);
|
||||||
resume();
|
resume();
|
||||||
// TODO: what if loadROM fails?
|
|
||||||
current_output = rom;
|
current_output = rom;
|
||||||
pcvisits = {};
|
pcvisits = {};
|
||||||
|
toolbar.removeClass("has-errors");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e); // TODO: show error
|
console.log(e); // TODO: show error
|
||||||
alert("Could not load ROM: " + e);
|
toolbar.addClass("has-errors");
|
||||||
|
addErrorMarker(0, e+"");
|
||||||
current_output = null;
|
current_output = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -887,6 +901,7 @@ function startPlatform() {
|
|||||||
|
|
||||||
// start
|
// start
|
||||||
function startUI(loadplatform) {
|
function startUI(loadplatform) {
|
||||||
|
installErrorHandler();
|
||||||
// parse query string
|
// parse query string
|
||||||
// is this a share URL?
|
// is this a share URL?
|
||||||
if (qs['sharekey']) {
|
if (qs['sharekey']) {
|
||||||
@ -898,14 +913,14 @@ function startUI(loadplatform) {
|
|||||||
updatePreset(newid, result['text']);
|
updatePreset(newid, result['text']);
|
||||||
qs['file'] = newid;
|
qs['file'] = newid;
|
||||||
delete qs['sharekey'];
|
delete qs['sharekey'];
|
||||||
window.location = "?" + $.param(qs);
|
gotoNewLocation();
|
||||||
}, 'text');
|
}, 'text');
|
||||||
} else {
|
} else {
|
||||||
// reset file?
|
// reset file?
|
||||||
if (qs['file'] && qs['reset']) {
|
if (qs['file'] && qs['reset']) {
|
||||||
store.deleteFile(qs['file']);
|
store.deleteFile(qs['file']);
|
||||||
qs['reset'] = '';
|
qs['reset'] = '';
|
||||||
window.location = "?" + $.param(qs);
|
gotoNewLocation();
|
||||||
} else {
|
} else {
|
||||||
// add default platform?
|
// add default platform?
|
||||||
platform_id = qs['platform'] || localStorage.getItem("__lastplatform");
|
platform_id = qs['platform'] || localStorage.getItem("__lastplatform");
|
||||||
|
Loading…
Reference in New Issue
Block a user