diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-09-08 03:05:42 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2023-09-08 03:05:42 +1000 |
| commit | a6ae1e33c6c25c364fcea2e0af23578803f5941d (patch) | |
| tree | 89e6d22ef6e57ab319a2b9074844cf8390c212c0 /wwwroot/js/keyboard.js | |
| parent | e14e05d13d72c44fcfb011df83f3cfefe768e1fa (diff) | |
Added global keyboard shortcuts
Diffstat (limited to 'wwwroot/js/keyboard.js')
| -rw-r--r-- | wwwroot/js/keyboard.js | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/wwwroot/js/keyboard.js b/wwwroot/js/keyboard.js index 9d06b75..5669637 100644 --- a/wwwroot/js/keyboard.js +++ b/wwwroot/js/keyboard.js @@ -1,5 +1,13 @@ async function keyDownHandler(e) { - e.preventDefault(); + function isDialogChild(e) { + while (e = e.parentElement) + if (e.tagName == 'DIV' && e.classList.contains('dialog')) + return true; + return false; + } + + if(document.activeElement.tagName == 'INPUT') + return; var element = Array.from(document.querySelectorAll('div.dialog')) .filter(e => e.style.visibility == 'visible') @@ -12,6 +20,19 @@ async function keyDownHandler(e) { .find(d => d.element == element) .dialogObject .invokeMethodAsync('KeyHandler', e.key); + e.preventDefault(); + return; + } + + var button = Array.from(document.getElementsByTagName('button')) + .filter(b => typeof(b.dataset.keyboardShortcut) == 'string') + .filter(b => !isDialogChild(b)) + .find(b => b.dataset.keyboardShortcut == e.key); + + if(button) { + button.click(); + e.preventDefault(); + return; } } |
