From e297ac65f8f0cde103880c73d0c92ad3cb50f161 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 3 May 2022 13:21:24 -0700 Subject: web: more use of generic JS functions --- web/static/dartboat.js | 26 +++++++------------------- web/static/index.html | 4 ++-- web/static/style.css | 10 +++++++++- web/web_control.c | 8 ++++---- web/web_prompt.c | 16 +++++++++------- web/web_scoreboard.c | 19 +++++++++++++++++++ web/web_scoreboard.h | 4 ++++ 7 files changed, 54 insertions(+), 33 deletions(-) diff --git a/web/static/dartboat.js b/web/static/dartboat.js index b420543..99513e2 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -53,6 +53,13 @@ function elemToggleClass(sel, c) { $(UTF8ToString(sel)).classList.toggle(UTF8ToString(c)); } +function elemSetUniqClass(sel, c, sel_set) { + selstr = sel && UTF8ToString(sel); + cstr = UTF8ToString(c); + $$(UTF8ToString(sel_set)).forEach(e => + e.classList[sel && e.matches(selstr) ? 'add' : 'remove'](cstr)); +} + function promptHandle(command, data) { const str_c = toCString(command); const str_d = data && toCString(data); @@ -62,25 +69,6 @@ function promptHandle(command, data) { if (str_d) _free(str_d); } -function setKeypad(keypad) { - const keypad_id = `keypad-${UTF8ToString(keypad)}`; - $$('.keypad').forEach(e => - e.style.display = e.id === keypad_id ? '' : 'none'); -} - -function setPlayerActive(n) { - $$('[id$=-info]').forEach(e => - e.classList[n && e.id == `p${n}-info` ? 'add' : 'remove']('active')); -} - -function showPlayerInfo(n) { - $(`#p${n}-info-inner`).style.visibility = 'visible'; -} - -function hidePlayerInfo(n) { - $(`#p${n}-info-inner`).style.visibility = 'hidden'; -} - const POINT_CLASSES = [180, 140, 100, 60, 40, 20, 0]; function drawVisit(visit_no, p1_pts, p1_rem, p2_pts, p2_rem, p2_darts) { const e = $('#visits'); diff --git a/web/static/index.html b/web/static/index.html index 1a8d1b5..53796d8 100644 --- a/web/static/index.html +++ b/web/static/index.html @@ -35,7 +35,7 @@
-