Use keys from 1 to 0 to navigate sidebar links
This commit is contained in:
parent
c11690763e
commit
43d4452554
@ -17,7 +17,7 @@ component Sidebar(user *arn.User)
|
|||||||
a#notification-count.badge.right-badge.badge-important.hidden(href="/notifications", title="Notifications") 0
|
a#notification-count.badge.right-badge.badge-important.hidden(href="/notifications", title="Notifications") 0
|
||||||
|
|
||||||
//- Search
|
//- Search
|
||||||
.sidebar-link(aria-label="Search")
|
div(aria-label="Search")
|
||||||
.sidebar-button
|
.sidebar-button
|
||||||
Icon("search")
|
Icon("search")
|
||||||
FuzzySearch
|
FuzzySearch
|
||||||
|
@ -976,7 +976,7 @@ export default class AnimeNotifier {
|
|||||||
// Ignore hotkeys on input elements
|
// Ignore hotkeys on input elements
|
||||||
switch(activeElement.tagName) {
|
switch(activeElement.tagName) {
|
||||||
case "INPUT":
|
case "INPUT":
|
||||||
//
|
// If the active element is the search and we press Enter, re-activate search.
|
||||||
if(activeElement.id === "search" && e.keyCode === 13) {
|
if(activeElement.id === "search" && e.keyCode === 13) {
|
||||||
actions.search(this, activeElement as HTMLInputElement, e)
|
actions.search(this, activeElement as HTMLInputElement, e)
|
||||||
}
|
}
|
||||||
@ -987,6 +987,12 @@ export default class AnimeNotifier {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When called, this will prevent the default action for that key.
|
||||||
|
let preventDefault = () => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
}
|
||||||
|
|
||||||
// Ignore hotkeys on contentEditable elements
|
// Ignore hotkeys on contentEditable elements
|
||||||
if(activeElement.getAttribute("contenteditable") === "true") {
|
if(activeElement.getAttribute("contenteditable") === "true") {
|
||||||
// Disallow Enter key in contenteditables and make it blur the element instead
|
// Disallow Enter key in contenteditables and make it blur the element instead
|
||||||
@ -995,8 +1001,7 @@ export default class AnimeNotifier {
|
|||||||
activeElement["blur"]()
|
activeElement["blur"]()
|
||||||
}
|
}
|
||||||
|
|
||||||
e.preventDefault()
|
return preventDefault()
|
||||||
e.stopPropagation()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -1005,14 +1010,11 @@ export default class AnimeNotifier {
|
|||||||
// "Ctrl" + "," = Settings
|
// "Ctrl" + "," = Settings
|
||||||
if(e.ctrlKey && e.keyCode === 188) {
|
if(e.ctrlKey && e.keyCode === 188) {
|
||||||
this.app.load("/settings")
|
this.app.load("/settings")
|
||||||
|
return preventDefault()
|
||||||
e.preventDefault()
|
|
||||||
e.stopPropagation()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following keycodes should not be activated while Ctrl is held down
|
// The following keycodes should not be activated while Ctrl or Alt is held down
|
||||||
if(e.ctrlKey) {
|
if(e.ctrlKey || e.altKey) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1022,64 +1024,58 @@ export default class AnimeNotifier {
|
|||||||
|
|
||||||
search.focus()
|
search.focus()
|
||||||
search.select()
|
search.select()
|
||||||
|
return preventDefault()
|
||||||
e.preventDefault()
|
|
||||||
e.stopPropagation()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// "S" = Toggle sidebar
|
// "S" = Toggle sidebar
|
||||||
if(e.keyCode === 83) {
|
if(e.keyCode === 83) {
|
||||||
this.sideBar.toggle()
|
this.sideBar.toggle()
|
||||||
|
return preventDefault()
|
||||||
e.preventDefault()
|
|
||||||
e.stopPropagation()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// "+" = Audio speed up
|
// "+" = Audio speed up
|
||||||
if(e.keyCode === 107 || e.keyCode === 187) {
|
if(e.keyCode === 107 || e.keyCode === 187) {
|
||||||
this.audioPlayer.addSpeed(0.05)
|
this.audioPlayer.addSpeed(0.05)
|
||||||
|
return preventDefault()
|
||||||
e.preventDefault()
|
|
||||||
e.stopPropagation()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// "-" = Audio speed down
|
// "-" = Audio speed down
|
||||||
if(e.keyCode === 109 || e.keyCode === 189) {
|
if(e.keyCode === 109 || e.keyCode === 189) {
|
||||||
this.audioPlayer.addSpeed(-0.05)
|
this.audioPlayer.addSpeed(-0.05)
|
||||||
|
return preventDefault()
|
||||||
e.preventDefault()
|
|
||||||
e.stopPropagation()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// "J" = Previous track
|
// "J" = Previous track
|
||||||
if(e.keyCode === 74) {
|
if(e.keyCode === 74) {
|
||||||
this.audioPlayer.previous()
|
this.audioPlayer.previous()
|
||||||
|
return preventDefault()
|
||||||
e.preventDefault()
|
|
||||||
e.stopPropagation()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// "K" = Play/pause
|
// "K" = Play/pause
|
||||||
if(e.keyCode === 75) {
|
if(e.keyCode === 75) {
|
||||||
this.audioPlayer.playPause()
|
this.audioPlayer.playPause()
|
||||||
|
return preventDefault()
|
||||||
e.preventDefault()
|
|
||||||
e.stopPropagation()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// "L" = Next track
|
// "L" = Next track
|
||||||
if(e.keyCode === 76) {
|
if(e.keyCode === 76) {
|
||||||
this.audioPlayer.next()
|
this.audioPlayer.next()
|
||||||
|
return preventDefault()
|
||||||
|
}
|
||||||
|
|
||||||
e.preventDefault()
|
// Number keys activate sidebar menus
|
||||||
e.stopPropagation()
|
for(let i = 48; i <= 57; i++) {
|
||||||
return
|
if(e.keyCode === i) {
|
||||||
|
let index = i === 48 ? 9 : i - 49
|
||||||
|
let links = [...findAll("sidebar-link")]
|
||||||
|
|
||||||
|
if(index < links.length) {
|
||||||
|
let element = links[index] as HTMLElement
|
||||||
|
|
||||||
|
element.click()
|
||||||
|
return preventDefault()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user