add video-player keybinds

This commit is contained in:
ed 2021-07-11 06:12:24 +02:00
parent 2b255fbbed
commit 55e0209901
3 changed files with 62 additions and 27 deletions

View file

@ -200,10 +200,16 @@ the browser has the following hotkeys
* `G` toggle list / grid view * `G` toggle list / grid view
* `T` toggle thumbnails / icons * `T` toggle thumbnails / icons
* when playing audio: * when playing audio:
* `0..9` jump to 10%..90%
* `U/O` skip 10sec back/forward
* `J/L` prev/next song * `J/L` prev/next song
* `U/O` skip 10sec back/forward
* `0..9` jump to 10%..90%
* `P` play/pause (also starts playing the folder) * `P` play/pause (also starts playing the folder)
* when viewing images / playing videos:
* `J/L, Left/Right` prev/next file
* `Home/End` first/last file
* `U/O` skip 10sec back/forward
* `P/K/Space` play/pause video
* `Esc` close viewer
* when tree-sidebar is open: * when tree-sidebar is open:
* `A/D` adjust tree width * `A/D` adjust tree width
* in the grid view: * in the grid view:

View file

@ -206,24 +206,36 @@ window.baguetteBox = (function () {
bindEvents(); bindEvents();
} }
function keyDownHandler(event) { function keyDownHandler(e) {
switch (event.keyCode) { if (e.ctrlKey || e.altKey || e.metaKey || e.isComposing)
case 37: // Left return;
showPreviousImage();
break; var k = e.code + '';
case 39: // Right
showNextImage(); if (k == "ArrowLeft" || k == "KeyJ")
break; showPreviousImage();
case 27: // Esc else if (k == "ArrowRight" || k == "KeyL")
hideOverlay(); showNextImage();
break; else if (k == "Escape")
case 36: // Home hideOverlay();
showFirstImage(event); else if (k == "Home")
break; showFirstImage(e);
case 35: // End else if (k == "End")
showLastImage(event); showLastImage(e);
break; else if (k == "Space" || k == "KeyP" || k == "KeyK")
} playpause();
else if (k == "KeyU" || k == "KeyO")
relseek(k == "KeyU" ? -10 : 10);
}
function keyUpHandler(e) {
if (e.ctrlKey || e.altKey || e.metaKey || e.isComposing)
return;
var k = e.code + '';
if (k == "Space")
ev(e);
} }
var passiveSupp = false; var passiveSupp = false;
@ -322,6 +334,7 @@ window.baguetteBox = (function () {
} }
bind(document, 'keydown', keyDownHandler); bind(document, 'keydown', keyDownHandler);
bind(document, 'keyup', keyUpHandler);
currentIndex = chosenImageIndex; currentIndex = chosenImageIndex;
touch = { touch = {
count: 0, count: 0,
@ -373,6 +386,7 @@ window.baguetteBox = (function () {
} }
unbind(document, 'keydown', keyDownHandler); unbind(document, 'keydown', keyDownHandler);
unbind(document, 'keyup', keyUpHandler);
// Fade out and hide the overlay // Fade out and hide the overlay
overlay.className = ''; overlay.className = '';
setTimeout(function () { setTimeout(function () {
@ -480,7 +494,6 @@ window.baguetteBox = (function () {
* @return {boolean} - true on success or false if the index is invalid * @return {boolean} - true on success or false if the index is invalid
*/ */
function show(index, gallery) { function show(index, gallery) {
playvid(false);
if (!isOverlayVisible && index >= 0 && index < gallery.length) { if (!isOverlayVisible && index >= 0 && index < gallery.length) {
prepareOverlay(gallery, options); prepareOverlay(gallery, options);
showOverlay(index); showOverlay(index);
@ -499,6 +512,7 @@ window.baguetteBox = (function () {
return false; return false;
} }
playvid(false);
currentIndex = index; currentIndex = index;
loadImage(currentIndex, function () { loadImage(currentIndex, function () {
preloadNext(currentIndex); preloadNext(currentIndex);
@ -513,12 +527,24 @@ window.baguetteBox = (function () {
return true; return true;
} }
function playvid(play) { function vid() {
var vid = imagesElements[currentIndex].querySelector('video'), return imagesElements[currentIndex].querySelector('video');
fun = play ? 'play' : 'pause'; }
if (vid) function playvid(play) {
vid[fun](); if (vid())
vid()[play ? 'play' : 'pause']();
}
function playpause() {
var v = vid();
if (v)
v[v.paused ? "play" : "pause"]();
}
function relseek(sec) {
if (vid())
vid().currentTime += sec;
} }
/** /**
@ -577,6 +603,7 @@ window.baguetteBox = (function () {
unbindEvents(); unbindEvents();
clearCachedData(); clearCachedData();
unbind(document, 'keydown', keyDownHandler); unbind(document, 'keydown', keyDownHandler);
unbind(document, 'keyup', keyUpHandler);
document.getElementsByTagName('body')[0].removeChild(ebi('baguetteBox-overlay')); document.getElementsByTagName('body')[0].removeChild(ebi('baguetteBox-overlay'));
data = {}; data = {};
currentGallery = []; currentGallery = [];
@ -588,6 +615,8 @@ window.baguetteBox = (function () {
show: show, show: show,
showNext: showNextImage, showNext: showNextImage,
showPrevious: showPreviousImage, showPrevious: showPreviousImage,
relseek: relseek,
playpause: playpause,
hide: hideOverlay, hide: hideOverlay,
destroy: destroyPlugin destroy: destroyPlugin
}; };

View file

@ -1756,7 +1756,7 @@ document.onkeydown = function (e) {
if (e.ctrlKey || e.altKey || e.metaKey || e.isComposing) if (e.ctrlKey || e.altKey || e.metaKey || e.isComposing)
return; return;
var k = (e.code + ''), pos = -1, n; var k = e.code + '', pos = -1, n;
if (e.shiftKey && k != 'KeyA' && k != 'KeyD') if (e.shiftKey && k != 'KeyA' && k != 'KeyD')
return; return;