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