summaryrefslogtreecommitdiff
path: root/web/static/dartboat.js
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-24 19:44:43 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-24 19:44:43 -0700
commit860fed5d03faa3e88ddd2357803e6b5a440efc8f (patch)
tree87d92b97affd78eed4b085961aaf15ed1251da0c /web/static/dartboat.js
parentabe6abebf502b2c3aebdbe5a8311fe6e2a35053f (diff)
downloaddartboat-860fed5d03faa3e88ddd2357803e6b5a440efc8f.tar.gz
dartboat-860fed5d03faa3e88ddd2357803e6b5a440efc8f.tar.xz
web: enforce double out; hide suggested for bot; ui updates
Diffstat (limited to 'web/static/dartboat.js')
-rw-r--r--web/static/dartboat.js98
1 files changed, 50 insertions, 48 deletions
diff --git a/web/static/dartboat.js b/web/static/dartboat.js
index e03151d..f3c5849 100644
--- a/web/static/dartboat.js
+++ b/web/static/dartboat.js
@@ -29,54 +29,48 @@ function scheduleCCall(f, ms, ...args) {
let prompt_handler;
let prompt_handlers = {
default: {
+ _get() {
+ return document.getElementById('prompt-input').textContent;
+ },
+
+ _get_and_clear() {
+ let val = this._get();
+ this.clear();
+ return val;
+ },
+
+ _pre(action) {
+ clearOi();
+ },
+
append(val) {
let e = document.getElementById('prompt-input');
if (e.textContent.length < 3) {
- e.textContent += val;
- this._on_change?.();
+ let tc = e.textContent += val;
+ this._on_change?.(tc);
}
},
backspace() {
let e = document.getElementById('prompt-input');
- e.textContent = e.textContent.slice(0, -1);
- this._on_change?.();
+ let tc = e.textContent = e.textContent.slice(0, -1);
+ this._on_change?.(tc);
},
clear() {
- document.getElementById('prompt-input').textContent = '';
- this._on_change?.();
- },
-
- pre(action) {
- clearOi();
- },
-
- _get() {
- return document.getElementById('prompt-input').textContent;
- },
-
- _get_and_clear() {
- let val = this._get();
- this.clear();
- return val;
+ let tc = document.getElementById('prompt-input').textContent = '';
+ this._on_change?.(tc);
}
}
}
-prompt_handlers.visit = {
+prompt_handlers.default_with_undo = {
__proto__: prompt_handlers.default,
- submit() {
- let pts = this._get_and_clear();
- if (pts)
- Module.ccall('user_visit', 'number', ['number'], [pts]);
- },
-
- submit_rem() {
- let rem = this._get_and_clear();
- if (rem)
- Module.ccall('user_visit_to_rem', 'number', ['number'], [rem]);
+ _pre(action) {
+ super._pre(action);
+ if (action != 'undo')
+ document.getElementById('key_undo').classList.remove('active');
},
undo() {
@@ -85,22 +79,32 @@ prompt_handlers.visit = {
if (cl.contains('active'))
Module.ccall('user_undo');
cl.toggle('active');
- },
+ }
+}
- pre(action) {
- super.pre(action);
- if (action != 'undo')
- document.getElementById('key_undo').classList.remove('active');
- },
+prompt_handlers.visit = {
+ __proto__: prompt_handlers.default_with_undo,
_on_change(val) {
Module.ccall('update_user_rem_from_pts', null,
['number'], [val || this._get()]);
+ },
+
+ submit() {
+ let pts = this._get_and_clear();
+ if (pts)
+ Module.ccall('user_visit', 'number', ['number'], [pts]);
+ },
+
+ submit_rem() {
+ let rem = this._get_and_clear();
+ if (rem)
+ Module.ccall('user_visit_to_rem', 'number', ['number'], [rem]);
}
};
prompt_handlers.num_darts = {
- __proto__: prompt_handlers.default,
+ __proto__: prompt_handlers.default_with_undo,
submit() {
let n = this._get_and_clear();
@@ -110,13 +114,10 @@ prompt_handlers.num_darts = {
};
prompt_handlers.match_over = {
- __proto__: prompt_handlers.default,
+ __proto__: prompt_handlers.default_with_undo,
append() {},
- undo() { prompt_handlers.visit.undo(); },
- pre(action) { prompt_handlers.visit.pre(action); },
-
submit() {
Module.ccall('match_init');
}
@@ -124,6 +125,7 @@ prompt_handlers.match_over = {
prompt_handlers.init = {
__proto__: prompt_handlers.default,
+ _keypad: 'init',
submit() {
let v = this._get_and_clear();
@@ -133,18 +135,18 @@ prompt_handlers.init = {
};
function setPromptHandler(ptr) {
- let str = UTF8ToString(ptr);
- prompt_handler = prompt_handlers[str];
+ prompt_handler = prompt_handlers[UTF8ToString(ptr)];
document.getElementById('prompt').classList[
prompt_handler ? 'add' : 'remove']('active');
- document.querySelectorAll('.keypad').forEach(e => e.style.display = 'none');
- document.getElementById(`keypad-${str === 'init' ? 'init' : 'default'}`)
- .style.removeProperty('display');
+ let keypad_id = `keypad-${prompt_handler?._keypad || 'default'}`;
+ document.querySelectorAll('.keypad').forEach(e => {
+ e.style.display = e.id === keypad_id ? '' : 'none';
+ });
}
function promptHandle(action, ...args) {
- prompt_handler?.pre?.(action);
+ prompt_handler?._pre?.(action);
prompt_handler?.[action]?.(...args);
}