diff options
author | Brian Cully <bjc@kublai.com> | 2021-02-19 12:42:11 -0500 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2021-02-19 12:42:11 -0500 |
commit | 0a703e8f463dfadcf102e0b553d798b8046b03ee (patch) | |
tree | 791775233693855907d6bbc79c5c0846426c6611 /amino-acid-selector.mjs | |
parent | 555e3faea8d3cc8ae5764876fe957039cdc0d431 (diff) | |
download | molsim2-0a703e8f463dfadcf102e0b553d798b8046b03ee.tar.gz molsim2-0a703e8f463dfadcf102e0b553d798b8046b03ee.zip |
Add amino acid selection after mutation.
Diffstat (limited to 'amino-acid-selector.mjs')
-rw-r--r-- | amino-acid-selector.mjs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/amino-acid-selector.mjs b/amino-acid-selector.mjs new file mode 100644 index 0000000..fe71098 --- /dev/null +++ b/amino-acid-selector.mjs @@ -0,0 +1,33 @@ +class AminoAcidSelector { + constructor(elt) { + this.elt = elt + for (const elt of this.elt.querySelectorAll('li')) { + 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.currentTarget.innerText) + } +} + +export default AminoAcidSelector |