js: Tolerate the non-existence of some HTML elements

Specifically, the permalinks, the apology, and the resizable div.
This commit is contained in:
Ben Harris
2022-10-29 11:58:37 +01:00
parent ea4ba47662
commit 06f6e878a0
2 changed files with 76 additions and 65 deletions

View File

@ -166,14 +166,17 @@ mergeInto(LibraryManager.library, {
*/
js_update_permalinks: function(desc, seed) {
desc = encodeURI(UTF8ToString(desc)).replace(/#/g, "%23");
permalink_desc.href = "#" + desc;
if (permalink_desc !== null)
permalink_desc.href = "#" + desc;
if (seed == 0) {
permalink_seed.style.display = "none";
} else {
seed = encodeURI(UTF8ToString(seed)).replace(/#/g, "%23");;
permalink_seed.href = "#" + seed;
permalink_seed.style.display = "";
if (permalink_seed !== null) {
if (seed == 0) {
permalink_seed.style.display = "none";
} else {
seed = encodeURI(UTF8ToString(seed)).replace(/#/g, "%23");;
permalink_seed.href = "#" + seed;
permalink_seed.style.display = "";
}
}
},
@ -547,7 +550,9 @@ mergeInto(LibraryManager.library, {
js_canvas_set_size: function(w, h) {
onscreen_canvas.width = w;
offscreen_canvas.width = w;
resizable_div.style.width = w / (window.devicePixelRatio || 1) + "px";
if (resizable_div !== null)
resizable_div.style.width =
w / (window.devicePixelRatio || 1) + "px";
onscreen_canvas.height = h;
offscreen_canvas.height = h;