Skip to content

Commit 621ed1c

Browse files
committed
attempt add keybinds
1 parent a869e99 commit 621ed1c

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

js/comics.js

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ function buttonPlus() {
113113
setZoom(1 / ((1 / zoom) - 1))
114114
}
115115
$(".comicButtonPlus").on("click", buttonPlus)
116-
$(document).on("keydown", function(e) {
117-
if (e.key === "+" || e.key === "=") {
118-
buttonPlus();
119-
}
120-
});
121116

122117
function buttonMinus() {
123118
// Opposite of the .comicButtonPlus (swaps [+] and [-])
@@ -181,6 +176,44 @@ async function buttonRandom() {
181176
}
182177
$(".comicButtonRandom").on("click", buttonRandom)
183178

179+
$(document).on("keydown", (e) => {
180+
if (!e.key) {
181+
return
182+
}
183+
// cspell: ignore keybinds
184+
/** Keybinds
185+
* plus = enlarge
186+
* minus = shrink
187+
* left = previous
188+
* right = next
189+
* shift + left = first
190+
* shift + right = last
191+
* r = random
192+
*/
193+
let shift = e.shiftKey
194+
switch (e.key) {
195+
case "ArrowLeft":
196+
if (shift) buttonFirst()
197+
else buttonPrevious()
198+
break
199+
case "ArrowRight":
200+
if (shift) buttonLast()
201+
else buttonNext()
202+
break
203+
case "r":
204+
buttonRandom()
205+
break
206+
case "plus":
207+
buttonPlus()
208+
break
209+
case "minus":
210+
buttonMinus()
211+
break
212+
default:
213+
console.log(`Unhandled key: ${e.key}`);
214+
break;
215+
}
216+
})
184217

185218
// ================================ ON LOAD ================================ //
186219

0 commit comments

Comments
 (0)