Files: 0c056b3b97a2efd2fceb281c3d99ac1fe864be47 / keyscroll.js
817 bytesRaw
1 | module.exports = function (container) { |
2 | var curMsgEl |
3 | |
4 | if (!container) |
5 | return function() {} |
6 | |
7 | container.addEventListener('click', onActivateChild, false) |
8 | container.addEventListener('focus', onActivateChild, true) |
9 | |
10 | function onActivateChild(ev) { |
11 | for (var el = ev.target; el; el = el.parentNode) { |
12 | if (el.parentNode == container) { |
13 | curMsgEl = el |
14 | return |
15 | } |
16 | } |
17 | } |
18 | |
19 | function selectChild(el) { |
20 | if (!el) return |
21 | (el.scrollIntoViewIfNeeded || el.scrollIntoView).call(el) |
22 | el.focus() |
23 | curMsgEl = el |
24 | } |
25 | |
26 | return function scroll(d) { |
27 | selectChild((!curMsgEl || d == 'first') ? container.firstChild |
28 | : d < 0 ? curMsgEl.previousElementSibling || container.firstChild |
29 | : d > 0 ? curMsgEl.nextElementSibling || container.lastChild |
30 | : curMsgEl) |
31 | } |
32 | } |
33 |
Built with git-ssb-web