mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-21 07:32:02 +00:00
KeyboardNavigation refactored to work with event.code
This commit is contained in:
parent
dd37b621c3
commit
bb4e8dfa34
1 changed files with 39 additions and 20 deletions
|
|
@ -1,32 +1,51 @@
|
||||||
const TABS = [
|
|
||||||
{ href: '#/', key: 'F1' },
|
|
||||||
{ href: '#/discover', key: 'F2' },
|
|
||||||
{ href: '#/library', key: 'F3' }
|
|
||||||
];
|
|
||||||
|
|
||||||
function KeyboardNavigation() {
|
function KeyboardNavigation() {
|
||||||
let active = false;
|
let active = false;
|
||||||
|
|
||||||
function onKeyDown(event) {
|
function onKeyDown(event) {
|
||||||
const tab = TABS.find(({ key }) => key === event.key);
|
if (event.keyboardNavigationPrevented) {
|
||||||
if (tab) {
|
|
||||||
event.preventDefault();
|
|
||||||
window.location = tab.href;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.target.tagName !== 'INPUT') {
|
switch (event.code) {
|
||||||
if (event.key === 'Backspace') {
|
case 'Digit1': {
|
||||||
window.history.back();
|
window.location = '#/';
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
case 'Digit2': {
|
||||||
|
window.location = '#/discover';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'Digit3': {
|
||||||
|
window.location = '#/library';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'Digit4': {
|
||||||
|
window.location = '#/settings';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'Digit5': {
|
||||||
|
window.location = '#/addons';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'Backspace': {
|
||||||
|
if (event.target.tagName !== 'INPUT') {
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
window.history.forward();
|
||||||
|
} else {
|
||||||
|
window.history.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (event.code === 'KeyF') {
|
break;
|
||||||
if (document.fullscreenElement === document.documentElement) {
|
}
|
||||||
document.exitFullscreen();
|
case 'KeyF': {
|
||||||
} else {
|
if (document.fullscreenElement === document.documentElement) {
|
||||||
document.documentElement.requestFullscreen();
|
document.exitFullscreen();
|
||||||
|
} else {
|
||||||
|
document.documentElement.requestFullscreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue