Allow selecting elevation level with up/down buttons

This commit is contained in:
2024-07-02 13:12:21 -07:00
parent 23673cec8e
commit 624991870d
3 changed files with 20 additions and 3 deletions

View File

@@ -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;