diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-09-08 02:26:32 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2023-09-08 02:26:32 +1000 |
| commit | e14e05d13d72c44fcfb011df83f3cfefe768e1fa (patch) | |
| tree | 74fd88bca6883eb5077867e238bf1f712cec9fa8 /wwwroot | |
| parent | 241c70671e64023a0d84907a765bf8f1e2927735 (diff) | |
Added framework for routing keyboard events
Diffstat (limited to 'wwwroot')
| -rw-r--r-- | wwwroot/js/dialog.js | 10 | ||||
| -rw-r--r-- | wwwroot/js/keyboard.js | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/wwwroot/js/dialog.js b/wwwroot/js/dialog.js index 065014a..418962f 100644 --- a/wwwroot/js/dialog.js +++ b/wwwroot/js/dialog.js @@ -66,3 +66,13 @@ function bumpDialog(element) { for(var d of dialogs) d.style.zIndex = z++; } + +function dialogAddObjectReference(element, dialogObject) { + if(!window.dialogObjects) + window.dialogObjects = [] + + window.dialogObjects.push({ + element: element, + dialogObject: dialogObject + }); +} diff --git a/wwwroot/js/keyboard.js b/wwwroot/js/keyboard.js new file mode 100644 index 0000000..9d06b75 --- /dev/null +++ b/wwwroot/js/keyboard.js @@ -0,0 +1,18 @@ +async function keyDownHandler(e) { + e.preventDefault(); + + var element = Array.from(document.querySelectorAll('div.dialog')) + .filter(e => e.style.visibility == 'visible') + .map(e => ({ element: e, zIndex: parseInt(e.style.zIndex) })) + .sort((a, b) => b.zIndex - a.zIndex) + .map(e => e.element)[0]; + + if(element) { + await window.dialogObjects + .find(d => d.element == element) + .dialogObject + .invokeMethodAsync('KeyHandler', e.key); + } +} + +window.onload = () => document.onkeydown = keyDownHandler;
\ No newline at end of file |
