git ssb

16+

Dominic / patchbay



Tree: c05e98ca66758d61b5968645419a1efaaad16bfd

Files: c05e98ca66758d61b5968645419a1efaaad16bfd / app / html / scroller.js

1431 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3
4exports.gives = nest('app.html.scroller')
5
6exports.create = function (api) {
7 return nest('app.html.scroller', Scroller)
8
9 function Scroller ({ prepend = [], content = null, append = [] } = {}) {
10 content = content || h('section.content')
11
12 const container = h('Scroller', { style: { overflow: 'auto' } }, [
13 h('div.wrapper', [
14 h('header', prepend),
15 content,
16 h('footer', append)
17 ])
18 ])
19
20 container.scroll = keyscroll(content)
21
22 return {
23 content,
24 container
25 }
26 }
27}
28
29function keyscroll (container) {
30 var curMsgEl
31
32 if (!container) return () => {}
33
34 container.addEventListener('click', onActivateChild, false)
35 container.addEventListener('focus', onActivateChild, true)
36
37 function onActivateChild (ev) {
38 for (var el = ev.target; el; el = el.parentNode) {
39 if (el.parentNode === container) {
40 curMsgEl = el
41 return
42 }
43 }
44 }
45
46 function selectChild (el) {
47 if (!el) { return }
48
49 ;(el.scrollIntoViewIfNeeded || el.scrollIntoView).call(el)
50 el.focus()
51 curMsgEl = el
52 }
53
54 return function scroll (d) {
55 selectChild((!curMsgEl || d === 'first') ? container.firstChild
56 : d < 0 ? curMsgEl.previousElementSibling || container.firstChild
57 : d > 0 ? curMsgEl.nextElementSibling || container.lastChild
58 : curMsgEl)
59
60 return curMsgEl
61 }
62}
63

Built with git-ssb-web