From a6ae1e33c6c25c364fcea2e0af23578803f5941d Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Fri, 8 Sep 2023 03:05:42 +1000 Subject: Added global keyboard shortcuts --- Pages/ViewMedia.razor | 12 ++++++------ wwwroot/js/keyboard.js | 23 ++++++++++++++++++++++- wwwroot/styles/global.css | 3 ++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Pages/ViewMedia.razor b/Pages/ViewMedia.razor index e8914a0..26b7988 100644 --- a/Pages/ViewMedia.razor +++ b/Pages/ViewMedia.razor @@ -83,19 +83,19 @@
- - - + + + @if(infoEditMode) { } else { - + } @if(media.IsIngest) { - + } else { - + }
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; } } diff --git a/wwwroot/styles/global.css b/wwwroot/styles/global.css index 6c1df53..ebcda47 100644 --- a/wwwroot/styles/global.css +++ b/wwwroot/styles/global.css @@ -75,11 +75,12 @@ code { } button, input[type=submit] { - color: white; background: var(--col-button-pri); border-radius: 10px; border: none; box-sizing: border-box; + color: white; + cursor: pointer; height: 30px; margin: 10px 5px 0 5px; padding: 0 9px 0 9px; -- cgit v1.3