select first element on down arrow press, cleanup

This commit is contained in:
Laura Hausmann 2021-05-27 16:48:24 +02:00
parent 75c86b5fd8
commit e09c2545a1
Signed by: zotan
GPG key ID: D044E84C5BE01605

View file

@ -10,7 +10,7 @@ let total = 0;
let onlyDirs = true;
const handleKeyEvent = (event) => {
if (event.ctrlKey === true || event.altKey === true || event.metaKey == true) return;
if (event.ctrlKey === true || event.altKey === true || event.metaKey === true) return;
event.preventDefault();
event.stopPropagation();
@ -18,7 +18,7 @@ const handleKeyEvent = (event) => {
case ' ':
case 'p':
if (onlyDirs !== false) return;
if (playerState == 'idle' && total !== 0) {
if (playerState === 'idle' && total !== 0) {
if (document.getElementById(playingItem).classList.contains('dir')) {
return nextTrack();
}
@ -49,12 +49,12 @@ const handleKeyEvent = (event) => {
if (audioPlayer.currentTime < 10) {
audioPlayer.currentTime = 0;
} else {
audioPlayer.currentTime = audioPlayer.currentTime-10;
audioPlayer.currentTime = audioPlayer.currentTime - 10;
}
break;
case 'ArrowRight':
audioPlayer.currentTime = audioPlayer.currentTime+10;
audioPlayer.currentTime = audioPlayer.currentTime + 10;
break;
case 'Enter':
@ -213,7 +213,7 @@ const toggleContinue = () => {
const previousTrack = () => {
if (!continuous) return;
if (playingItem-- === 0) playingItem = total-1;
if (playingItem-- === 0) playingItem = total - 1;
if (document.getElementById(playingItem).classList.contains('dir')) {
return previousTrack();
@ -234,13 +234,17 @@ const nextTrack = () => {
}
const selectPreviousItem = () => {
if (selectedItem-- === 0) selectedItem = total-1;
if (selectedItem-- === 0) selectedItem = total - 1;
updateSelectedItem();
}
const selectNextItem = () => {
if (selectedItem === 0 && document.getElementsByClassName('selected').length === 0) {
document.getElementById(selectedItem).classList.add('selected');
} else {
if (++selectedItem === total) selectedItem = 0;
updateSelectedItem();
}
}
const updateSelectedItem = () => {