mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-01 03:46:44 +01:00
feat: use keyCode instead of key
This commit is contained in:
parent
99958ee941
commit
9ca1a50a0a
1 changed files with 13 additions and 13 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
import { $ } from './utils/dom';
|
import { $ } from './utils/dom';
|
||||||
|
|
||||||
type ShortcutKeyMap = Record<string, () => void>;
|
type ShortcutKeyMap = Record<number, () => void>;
|
||||||
|
|
||||||
function getHover(): string | null {
|
function getHover(): string | null {
|
||||||
const thumbBoxHover = $<HTMLDivElement>('.media-box:hover');
|
const thumbBoxHover = $<HTMLDivElement>('.media-box:hover');
|
||||||
|
@ -50,19 +50,19 @@ function isOK(event: KeyboardEvent): boolean {
|
||||||
/* eslint-disable prettier/prettier */
|
/* eslint-disable prettier/prettier */
|
||||||
|
|
||||||
const keyCodes: ShortcutKeyMap = {
|
const keyCodes: ShortcutKeyMap = {
|
||||||
j() { click('.js-prev'); }, // J - go to previous image
|
74() { click('.js-prev'); }, // J - go to previous image
|
||||||
i() { click('.js-up'); }, // I - go to index page
|
73() { click('.js-up'); }, // I - go to index page
|
||||||
k() { click('.js-next'); }, // K - go to next image
|
75() { click('.js-next'); }, // K - go to next image
|
||||||
r() { click('.js-rand'); }, // R - go to random image
|
82() { click('.js-rand'); }, // R - go to random image
|
||||||
s() { click('.js-source-link'); }, // S - go to image source
|
83() { click('.js-source-link'); }, // S - go to image source
|
||||||
l() { click('.js-tag-sauce-toggle'); }, // L - edit tags
|
76() { click('.js-tag-sauce-toggle'); }, // L - edit tags
|
||||||
o() { openFullView(); }, // O - open original
|
79() { openFullView(); }, // O - open original
|
||||||
v() { openFullViewNewTab(); }, // V - open original in a new tab
|
86() { openFullViewNewTab(); }, // V - open original in a new tab
|
||||||
f() {
|
70() {
|
||||||
// F - favourite image
|
// F - favourite image
|
||||||
click(getHover() ? `a.interaction--fave[data-image-id="${getHover()}"]` : '.block__header a.interaction--fave');
|
click(getHover() ? `a.interaction--fave[data-image-id="${getHover()}"]` : '.block__header a.interaction--fave');
|
||||||
},
|
},
|
||||||
u() {
|
85() {
|
||||||
// U - upvote image
|
// U - upvote image
|
||||||
click(getHover() ? `a.interaction--upvote[data-image-id="${getHover()}"]` : '.block__header a.interaction--upvote');
|
click(getHover() ? `a.interaction--upvote[data-image-id="${getHover()}"]` : '.block__header a.interaction--upvote');
|
||||||
},
|
},
|
||||||
|
@ -72,8 +72,8 @@ const keyCodes: ShortcutKeyMap = {
|
||||||
|
|
||||||
export function listenForKeys() {
|
export function listenForKeys() {
|
||||||
document.addEventListener('keydown', (event: KeyboardEvent) => {
|
document.addEventListener('keydown', (event: KeyboardEvent) => {
|
||||||
if (isOK(event) && keyCodes[event.key]) {
|
if (isOK(event) && keyCodes[event.keyCode]) {
|
||||||
keyCodes[event.key]();
|
keyCodes[event.keyCode]();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue