aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-11-20 18:01:19 +0000
committerBen Harris <bjh21@bjh21.me.uk>2022-11-20 19:10:23 +0000
commit77c8b50834a8978fbbebe2f6701448aff5d9f08e (patch)
treec9bcb533e2199dfb5c2c739edc5a31c8c8dc2af5
parentf86623bbd93e703f1be6432cc221319543a304e6 (diff)
downloadpuzzles-77c8b50834a8978fbbebe2f6701448aff5d9f08e.zip
puzzles-77c8b50834a8978fbbebe2f6701448aff5d9f08e.tar.gz
puzzles-77c8b50834a8978fbbebe2f6701448aff5d9f08e.tar.bz2
puzzles-77c8b50834a8978fbbebe2f6701448aff5d9f08e.tar.xz
js: Allow status bar to be present in the HTML
I'm generally in favour of putting HTML in HTML rather the constructing it in JavaScript, and this will allow for simplifying the code eventually. This only changes the JavaScript to make sure that's in people's caches before I change the HTML itself.
-rw-r--r--emcc.c3
-rw-r--r--emcclib.js27
-rw-r--r--emccpre.js3
3 files changed, 24 insertions, 9 deletions
diff --git a/emcc.c b/emcc.c
index 3f009ef..453637b 100644
--- a/emcc.c
+++ b/emcc.c
@@ -80,6 +80,7 @@ extern void js_canvas_free_blitter(int id);
extern void js_canvas_copy_to_blitter(int id, int x, int y, int w, int h);
extern void js_canvas_copy_from_blitter(int id, int x, int y, int w, int h);
extern void js_canvas_make_statusbar(void);
+extern void js_canvas_remove_statusbar(void);
extern void js_canvas_set_statusbar(const char *text);
extern void js_canvas_set_size(int w, int h);
extern double js_get_device_pixel_ratio();
@@ -958,6 +959,8 @@ int main(int argc, char **argv)
*/
if (midend_wants_statusbar(me))
js_canvas_make_statusbar();
+ else
+ js_canvas_remove_statusbar();
/*
* Set up the game-type dropdown with presets and/or the Custom
diff --git a/emcclib.js b/emcclib.js
index dad1475..d2316f1 100644
--- a/emcclib.js
+++ b/emcclib.js
@@ -518,11 +518,24 @@ mergeInto(LibraryManager.library, {
* back end turns out to want one.
*/
js_canvas_make_statusbar: function() {
- var statusholder = document.getElementById("statusbarholder");
- statusbar = document.createElement("div");
- statusbar.id = "statusbar";
- statusbar.appendChild(document.createTextNode(" "));
- statusholder.appendChild(statusbar);
+ if (statusbar === null) {
+ var statusholder = document.getElementById("statusbarholder");
+ statusbar = document.createElement("div");
+ statusbar.id = "statusbar";
+ statusbar.appendChild(document.createTextNode(" "));
+ statusholder.appendChild(statusbar);
+ }
+ },
+
+ /*
+ * void js_canvas_remove_statusbar(void);
+ *
+ * Cause a status bar not to exist. Called at setup time if the
+ * puzzle back end turns out not to want one.
+ */
+ js_canvas_remove_statusbar: function() {
+ if (statusbar !== null)
+ statusbar.parentNode.removeChild(statusbar);
},
/*
@@ -531,9 +544,7 @@ mergeInto(LibraryManager.library, {
* Set the text in the status bar.
*/
js_canvas_set_statusbar: function(ptr) {
- var text = UTF8ToString(ptr);
- statusbar.replaceChild(document.createTextNode(text),
- statusbar.lastChild);
+ statusbar.textContent = UTF8ToString(ptr);
},
/*
diff --git a/emccpre.js b/emccpre.js
index 78e949e..61ce21e 100644
--- a/emccpre.js
+++ b/emccpre.js
@@ -443,9 +443,10 @@ function initPuzzle() {
['number','number']);
timer_callback = Module.cwrap('timer_callback', 'void', ['number']);
- // Save references to the two permalinks.
+ // Save references to the two permalinks and the status bar.
permalink_desc = document.getElementById("permalink-desc");
permalink_seed = document.getElementById("permalink-seed");
+ statusbar = document.getElementById("statusbar");
resizable_div = document.getElementById("resizable");
if (resizable_div !== null) {