summaryrefslogtreecommitdiffstats
path: root/fretboard.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-03-08 12:05:53 -0500
committerBrian Cully <bjc@spork.org>2025-03-08 12:05:53 -0500
commitddc2818c6a096db5ff4db91f6538bf829043e563 (patch)
tree7db75e099280a9a86ce86337a703dcc974847e86 /fretboard.mjs
parentdaeace070ee8687fceb77ee5e9f7bce507669639 (diff)
downloadchords-ddc2818c6a096db5ff4db91f6538bf829043e563.tar.gz
chords-ddc2818c6a096db5ff4db91f6538bf829043e563.zip
js: add bare bones js stuff
Diffstat (limited to 'fretboard.mjs')
-rw-r--r--fretboard.mjs32
1 files changed, 32 insertions, 0 deletions
diff --git a/fretboard.mjs b/fretboard.mjs
new file mode 100644
index 0000000..c58543c
--- /dev/null
+++ b/fretboard.mjs
@@ -0,0 +1,32 @@
+function fretChanged(e) {
+ console.log('fret changed', e);
+}
+
+let mousedownVal = undefined;
+
+function mousedown(e) {
+ // at mousedown time, the form hasn't yet been changed. to support
+ // deselecting elements, we need to know what the previous
+ // selection was, so store it here.
+ //
+ // it'd be nice to be able to do this just in the click handler.
+ mousedownVal = e.target.checked;
+}
+
+function click(e) {
+ const elt = e.target;
+ // if this element was selected at mousedown time, deselect it
+ // now.
+ if (mousedownVal) {
+ elt.checked = false;
+ }
+}
+
+export default function Fretboard(form) {
+ console.debug('Fretboard()', form);
+ form.onchange = fretChanged;
+ form.querySelectorAll('input[type="radio"]').forEach(elt => {
+ elt.onmousedown = mousedown;
+ elt.onclick = click;
+ });
+}