Implemented circular selection
When up from first item, go to last When down from last item, go to first
This commit is contained in:
parent
131768ed41
commit
e50c604a80
1 changed files with 6 additions and 13 deletions
19
items.js
19
items.js
|
@ -2,21 +2,14 @@ var currentIndex = 0
|
|||
|
||||
function nav(offset) {
|
||||
var items = document.querySelectorAll('.items:not(.disabled)')
|
||||
if (offset === -1) {
|
||||
if (currentIndex <= 0) {
|
||||
return
|
||||
}
|
||||
}
|
||||
else if (offset === 1) {
|
||||
if (currentIndex >= items.length - 1) {
|
||||
return
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.error(`nav called with unknown offset: ${offset}`)
|
||||
}
|
||||
|
||||
currentIndex += offset
|
||||
if (currentIndex < 0) {
|
||||
currentIndex += items.length
|
||||
}
|
||||
if (currentIndex >= items.length) {
|
||||
currentIndex -= items.length
|
||||
}
|
||||
items[currentIndex].focus()
|
||||
items[currentIndex].addEventListener('keydown', handleKeyDown)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue