mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
merge space bar pause
This commit is contained in:
parent
636ea91460
commit
f2f8786597
1 changed files with 59 additions and 0 deletions
|
@ -53,6 +53,11 @@
|
|||
var currentTargetInfo;
|
||||
var players = [];
|
||||
|
||||
var keys = new bindKeys(self);
|
||||
|
||||
$(window).on("keydown", keys.keyBinding);
|
||||
$(window).on("keypress keyup", keys.keyPrevent);
|
||||
|
||||
self.registerPlayer = function (player) {
|
||||
|
||||
players.push(player);
|
||||
|
@ -509,6 +514,60 @@
|
|||
});
|
||||
}
|
||||
|
||||
function bindKeys(controller) {
|
||||
|
||||
var self = this;
|
||||
var keyResult = {};
|
||||
|
||||
self.keyBinding = function(e) {
|
||||
|
||||
if (bypass()) return;
|
||||
|
||||
console.log("keyCode", e.keyCode);
|
||||
|
||||
if (keyResult[e.keyCode]) {
|
||||
e.preventDefault();
|
||||
keyResult[e.keyCode](e);
|
||||
}
|
||||
};
|
||||
|
||||
self.keyPrevent = function(e) {
|
||||
|
||||
if (bypass()) return;
|
||||
|
||||
var codes = [32, 38, 40, 37, 39, 81, 77, 65, 84, 83, 70];
|
||||
|
||||
if (codes.indexOf(e.keyCode) != -1) {
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
keyResult[32] = function() { // spacebar
|
||||
|
||||
var player = controller.getCurrentPlayer();
|
||||
|
||||
player.getPlayerState().done(function (result) {
|
||||
|
||||
var state = result;
|
||||
|
||||
if (state.NowPlayingItem && state.PlayState) {
|
||||
if (state.PlayState.IsPaused) {
|
||||
player.unpause();
|
||||
} else {
|
||||
player.pause();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var bypass = function() {
|
||||
// Get active elem to see what type it is
|
||||
var active = document.activeElement;
|
||||
var type = active.type || active.tagName.toLowerCase();
|
||||
return (type === "text" || type === "select" || type === "textarea");
|
||||
};
|
||||
}
|
||||
|
||||
$(document).on('headercreated', '.libraryPage', function () {
|
||||
|
||||
$('.btnCast').on('click', function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue