Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-07-02 13:12:21 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-07-02 14:04:27 -0700
commit624991870df0e804d64cf4d9359c63435513d61b (patch)
tree5aeddf42b9c058127ec38bfd33d6c04dc3d2d0e0 /src
parent23673cec8e05970f96681eac733285732cf09e1c (diff)
Allow selecting elevation level with up/down buttons
Diffstat (limited to 'src')
-rw-r--r--src/index.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/index.js b/src/index.js
index efc6784..f1bc918 100644
--- a/src/index.js
+++ b/src/index.js
@@ -208,6 +208,22 @@ document.querySelector('#roll-dice').addEventListener('click', () => {
});
});
+document.querySelectorAll('.select-elevation button').forEach(el => el.addEventListener('click', () => {
+ const current = document.querySelector('.select-elevation input:checked');
+ const siblingMethod = `${el.classList.contains('up') ? 'previous' : 'next'}ElementSibling`;
+ let next = current;
+
+ do {
+ next = next[siblingMethod];
+ } while (next !== null && !next.matches('input'));
+
+ if (next) {
+ next.checked = true;
+ const event = new Event('change', { value: next.value });
+ next.dispatchEvent(event);
+ }
+}));
+
document.querySelectorAll('[name="select-elevation"]').forEach(el => {
el.addEventListener('change', function (e) {
document.querySelector('object').contentDocument.querySelector('.gameboard').dataset.viewElevation = this.value;