Disable keyboard navigation for non-TV

This commit is contained in:
Dmitry Lyzo 2020-02-05 15:20:48 +03:00
parent 8d02d05441
commit 17f9480188
2 changed files with 26 additions and 8 deletions

View File

@ -36,6 +36,11 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager)
10252: "MediaPlayPause"
};
/**
* Keys used for keyboard navigation.
*/
var NavigationKeys = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"];
var hasFieldKey = false;
try {
hasFieldKey = "key" in new KeyboardEvent("keydown");
@ -60,11 +65,28 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager)
return KeyNames[event.keyCode] || event.key;
}
/**
* Returns _true_ if key is used for navigation.
*
* @param {string} key name
* @return {boolean} _true_ if key is used for navigation
*/
function isNavigationKey(key) {
return NavigationKeys.indexOf(key) != -1;
}
function enable() {
document.addEventListener("keydown", function (e) {
var key = getKeyName(e);
// Ignore navigation keys for non-TV
if (!layoutManager.tv && isNavigationKey(key)) {
return;
}
var capture = true;
switch (getKeyName(e)) {
switch (key) {
case "ArrowLeft":
inputManager.handle("left");
break;
@ -128,6 +150,7 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager)
return {
enable: enable,
getKeyName: getKeyName
getKeyName: getKeyName,
isNavigationKey: isNavigationKey
};
});

View File

@ -1087,11 +1087,6 @@ define(["playbackManager", "dom", "inputManager", "datetime", "itemHelper", "med
}
}
/**
* Keys used for keyboard navigation.
*/
var NavigationKeys = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"];
/**
* Clicked element.
* To skip 'click' handling on Firefox/Edge.
@ -1109,7 +1104,7 @@ define(["playbackManager", "dom", "inputManager", "datetime", "itemHelper", "med
return;
}
if (layoutManager.tv && NavigationKeys.indexOf(key) != -1) {
if (layoutManager.tv && keyboardnavigation.isNavigationKey(key)) {
showOsd();
return;
}