git ssb

16+

Dominic / patchbay



Tree: 0812b8ec179f8389faf0bb63ce3c45242f21a07b

Files: 0812b8ec179f8389faf0bb63ce3c45242f21a07b / keyscroll.js

725 bytesRaw
1module.exports = function (container) {
2 var curMsgEl
3
4 container.addEventListener('click', onActivateChild, false)
5 container.addEventListener('focus', onActivateChild, true)
6
7 function onActivateChild(ev) {
8 for (var el = ev.target; el; el = el.parentNode) {
9 if (el.parentNode == container) {
10 curMsgEl = el
11 return
12 }
13 }
14 }
15
16 function selectChild(el) {
17 if (!el) return
18 el.scrollIntoViewIfNeeded()
19 el.focus()
20 curMsgEl = el
21 }
22
23 return function scroll(d) {
24 selectChild(!curMsgEl ? container.firstChild
25 : d > 0 ? curMsgEl.nextElementSibling || container.lastChild
26 : d < 0 ? curMsgEl.previousElementSibling || container.firstChild
27 : curMsgEl)
28 }
29}
30

Built with git-ssb-web