summaryrefslogtreecommitdiffstats
path: root/lethality-selector.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2021-02-19 14:13:25 -0500
committerBrian Cully <bjc@kublai.com>2021-02-19 14:13:25 -0500
commite998052cb2d8aea08b5af77c4611d08d9623c169 (patch)
tree98746b69e779e3af6132e581f1e3afa2cd2e7d2f /lethality-selector.mjs
parenta5629c55b5575a590f9e8c7884c3bd532c3ed063 (diff)
downloadmolsim2-e998052cb2d8aea08b5af77c4611d08d9623c169.tar.gz
molsim2-e998052cb2d8aea08b5af77c4611d08d9623c169.zip
First pass at lethal/non-lethal marking.
Diffstat (limited to 'lethality-selector.mjs')
-rw-r--r--lethality-selector.mjs34
1 files changed, 34 insertions, 0 deletions
diff --git a/lethality-selector.mjs b/lethality-selector.mjs
new file mode 100644
index 0000000..9f5813d
--- /dev/null
+++ b/lethality-selector.mjs
@@ -0,0 +1,34 @@
+class LethalitySelector {
+ constructor(elt) {
+ this.elt = elt
+
+ for (const elt of this.elt.querySelectorAll('button')) {
+ elt.addEventListener('click', this.select.bind(this))
+ }
+ }
+
+ attach() {
+ this.elt.classList.remove('hidden')
+ }
+
+ detach() {
+ this.elt.classList.add('hidden')
+ }
+
+ get onItemSelected() {
+ if (this._onItemSelected !== undefined) {
+ return this._onItemSelected
+ }
+ return () => {}
+ }
+
+ set onItemSelected(fn) {
+ this._onItemSelected = fn
+ }
+
+ select(evt) {
+ this.onItemSelected(evt.originalTarget.id == 'lethal')
+ }
+}
+
+export default LethalitySelector