summaryrefslogtreecommitdiffstats
path: root/key-picker.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-03-10 12:48:14 -0400
committerBrian Cully <bjc@spork.org>2025-03-10 12:48:14 -0400
commit20fc6265238a787c73b805faeb2fb97b23cb5701 (patch)
tree79c92c245ead6a3bcdf40dd0be2bec433b6c40e2 /key-picker.mjs
parent56adfaa1d105780c7b45df683c3ad81efde8fc35 (diff)
downloadchords-20fc6265238a787c73b805faeb2fb97b23cb5701.tar.gz
chords-20fc6265238a787c73b805faeb2fb97b23cb5701.zip
add click handler for notes in key selector
Diffstat (limited to 'key-picker.mjs')
-rw-r--r--key-picker.mjs19
1 files changed, 17 insertions, 2 deletions
diff --git a/key-picker.mjs b/key-picker.mjs
index a1739fa..0d3b421 100644
--- a/key-picker.mjs
+++ b/key-picker.mjs
@@ -16,19 +16,33 @@ function handleNoteEnter(e) {
// todo: this should be delegated. the key selector shouldn't know
// about the fretboard at all.
document.querySelectorAll(`#fretboard [x-data-note="${n}"]`).forEach(elt => {
- console.debug('wow! found elt', elt);
elt.classList.add('hover');
})
}
+
function handleNoteLeave(e) {
const n = Note.fromString(e.target.innerText).toString();
// ibid.
document.querySelectorAll(`#fretboard [x-data-note="${n}"]`).forEach(elt => {
- console.debug('wow! found elt', elt);
elt.classList.remove('hover');
})
}
+function handleNoteClick(e) {
+ const elt = e.target;
+ const n = Note.fromString(elt.innerText).toString();
+ const count = Number(elt.getAttribute('x-data-clicked')) || 0;
+ const next = (count + 1) % 4;
+ elt.classList.remove(`click${count}`);
+ elt.classList.add(`click${next}`);
+ // ibid.
+ document.querySelectorAll(`#fretboard [x-data-note="${n}"]`).forEach(elt => {
+ elt.classList.remove(`click${count}`);
+ elt.classList.add(`click${next}`);
+ })
+ elt.setAttribute('x-data-clicked', next.toString());
+}
+
function formChanged(form) {
const formData = new FormData(form);
const scale = scaleFrom(formData.get('tonic'), formData.get('scale'));
@@ -70,6 +84,7 @@ export default function KeyPicker(form) {
form.querySelectorAll('.notes li').forEach(elt => {
elt.onmouseenter = handleNoteEnter;
elt.onmouseleave = handleNoteLeave;
+ elt.onclick = handleNoteClick;
})
formChanged(form);
}