forked from ssbc/patchbay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyscroll.js
More file actions
32 lines (27 loc) · 799 Bytes
/
keyscroll.js
File metadata and controls
32 lines (27 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module.exports = function (container) {
var curMsgEl
if (!container)
return function() {}
container.addEventListener('click', onActivateChild, false)
container.addEventListener('focus', onActivateChild, true)
function onActivateChild(ev) {
for (var el = ev.target; el; el = el.parentNode) {
if (el.parentNode == container) {
curMsgEl = el
return
}
}
}
function selectChild(el) {
if (!el) return
(el.scrollIntoViewIfNeeded || el.scrollIntoView).call(el)
el.focus()
curMsgEl = el
}
return function scroll(d) {
selectChild(!curMsgEl ? container.firstChild
: d > 0 ? curMsgEl.nextElementSibling || container.lastChild
: d < 0 ? curMsgEl.previousElementSibling || container.firstChild
: curMsgEl)
}
}