Replace repetitive if
blocks with switch
blocks
Committed 1775b0
--- a/canopy/static/enliven.js
+++ b/canopy/static/enliven.js
document.addEventListener('keydown', ev => {
if (mode == 'room') {
- if (ev.key == 'w') { // w TODO walk forward
- } else if (ev.key == 'a') { // a TODO strafe left
- } else if (ev.key == 's') { // s TODO walk backward
- } else if (ev.key == 'd') { // d TODO strafe right
- } else if (ev.key == 'h') { // h TODO pan left
- } else if (ev.key == 'j') { // j TODO scroll map down
- } else if (ev.key == 'k') { // k TODO scroll map up
- } else if (ev.key == 'l') { // l TODO pan right
+ switch (ev.key) {
+ case 'w': break // w TODO walk forward
+ case 'a': break // a TODO strafe left
+ case 's': break // s TODO walk backward
+ case 'd': break // d TODO strafe right
+ case 'h': break // h TODO pan left
+ case 'j': break // j TODO scroll map down
+ case 'k': break // k TODO scroll map up
+ case 'l': break // l TODO pan right
}
return
}
}
return
}
- if (ev.ctrlKey && ev.key == '.') { // C^. toggle rhythm indicator
+ if (ev.ctrlKey && ev.key == '.') { // C^. toggle rhythm indicator
if (cookies.get('rhythm') == 'on') {
document.querySelector('body').style.backgroundImage = 'none'
cookies.set('rhythm', 'off')
document.querySelector('body').style.backgroundImage = 'url(/static/measure.png)'
cookies.set('rhythm', 'on')
}
- } else if (ev.key == '?') goHelp() // ? show help
- else if (ev.key == 'f') showKeyboardFollowLinks() // f show "follow links"
- else if (ev.key == 'm') goHome() // m go home
- else if (ev.key == 'h') goBack() // h go back
- else if (ev.key == 'j') scrollDown() // j scroll down 3 EMs
- else if (ev.key == 'k') scrollUp() // k scroll up 3 EMs
- else if (ev.key == 'l') goForward() // l go forward
- else if (ev.key == 'u') goUp() // u follow rel=up
- else if (ev.key == 'p') goPrevious() // p follow rel=prev
- else if (ev.key == 'n') goNext() // n follow rel=next
- else if (ev.key == '[') pageUp() // [ scroll page up
- else if (ev.key == ']') pageDown() // ] scroll page down
- else if (ev.key == '{') scrollTop() // { scroll to top
- else if (ev.key == '}') scrollBottom() // } scroll to bottom
+ } else {
+ switch (ev.key) {
+ case '?': goHelp(); break // ? show help
+ case 'f': showKeyboardFollowLinks(); break // f show "follow links"
+ case 'm': goHome(); break // m go home
+ case 'h': goBack(); break // h go back
+ case 'j': scrollDown(); break // j scroll down 3 EMs
+ case 'k': scrollUp(); break // k scroll up 3 EMs
+ case 'l': goForward(); break // l go forward
+ case 'u': goUp(); break // u follow rel=up
+ case 'p': goPrevious(); break // p follow rel=prev
+ case 'n': goNext(); break // n follow rel=next
+ case '[': pageUp(); break // [ scroll page up
+ case ']': pageDown(); break // ] scroll page down
+ case '{': scrollTop(); break // { scroll to top
+ case '}': scrollBottom(); break // } scroll to bottom
+ }
+ }
}, false)
})
document.querySelector('input[name=q]').value = query
go(`/search?q=${query}`)
} else if (input.startsWith('go')) { // go
- const where = input.slice(3)
- if (where == 'home') goHome() // home
- else if (where == 'up') goUp() // up
- else if (where == 'prev') goPrevious() // prev
- else if (where == 'next') goNext() // next
- else if (where == 'back') goBack() // back
- else if (where == 'forward') goForward() // forward
+ switch (input.slice(3)) {
+ case 'home': goHome(); break // home
+ case 'up': goUp(); break // up
+ case 'prev': goPrevious(); break // prev
+ case 'next': goNext(); break // next
+ case 'back': goBack(); break // back
+ case 'forward': goForward(); break // forward
+ }
} else if (input.startsWith('follow')) { // follow
showVoiceFollowLinks()
} else if (input.startsWith('tell me')) { // tell me