summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web/static/dartboat.js11
-rw-r--r--web/web_control.c4
-rw-r--r--web/web_dom.c5
-rw-r--r--web/web_dom.h2
4 files changed, 22 insertions, 0 deletions
diff --git a/web/static/dartboat.js b/web/static/dartboat.js
index aacb1bc..b2b8481 100644
--- a/web/static/dartboat.js
+++ b/web/static/dartboat.js
@@ -123,6 +123,17 @@ function storeOpt(opt, val) {
localStorage.setItem(UTF8ToString(opt), UTF8ToString(val));
}
+function prevDef(e) {
+ e.preventDefault();
+}
+
+function enableExitDialogue(enable) {
+ if (enable)
+ window.addEventListener('beforeunload', prevDef);
+ else
+ window.removeEventListener('beforeunload', prevDef);
+}
+
function boatAfloat() {
if (document.readyState === 'loading')
document.addEventListener('DOMContentLoaded', () => _init());
diff --git a/web/web_control.c b/web/web_control.c
index 4495d51..e75b703 100644
--- a/web/web_control.c
+++ b/web/web_control.c
@@ -1,4 +1,5 @@
#include "web_control.h"
+#include "web_dom.h"
#include "web_match.h"
#include "web_opts.h"
#include "web_prompt.h"
@@ -7,6 +8,7 @@
#include "comp.h"
+#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -286,12 +288,14 @@ void start_match()
update_player_avg(2, 0);
}
+ dom_enable_exit_dialogue(true);
draw_visits();
handle_next();
}
void end_match()
{
+ dom_enable_exit_dialogue(false);
if (state) free_state();
handle_next();
}
diff --git a/web/web_dom.c b/web/web_dom.c
index cff0459..6aa50ed 100644
--- a/web/web_dom.c
+++ b/web/web_dom.c
@@ -149,3 +149,8 @@ inline void dom_scroll_to_bottom(char *sel)
{
EM_ASM({elemScrollToBottom($0)}, sel);
}
+
+inline void dom_enable_exit_dialogue(bool enable)
+{
+ EM_ASM({enableExitDialogue($0)}, enable);
+}
diff --git a/web/web_dom.h b/web/web_dom.h
index e89b5ba..12d173d 100644
--- a/web/web_dom.h
+++ b/web/web_dom.h
@@ -32,4 +32,6 @@ void dom_set_uniq_class(char *sel, char *class, char *sel_set);
void dom_scroll_to_bottom(char *sel);
+void dom_enable_exit_dialogue(bool enable);
+
#endif