git ssb

16+

Dominic / patchbay



Tree: 1e24c51528660ca6d322ca62c6566f9b047c6412

Files: 1e24c51528660ca6d322ca62c6566f9b047c6412 / app / html / scroller.js

1404 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 = [], append = [] } = {}) {
10 const 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 (el.scrollIntoViewIfNeeded || el.scrollIntoView).call(el)
49 el.focus()
50 curMsgEl = el
51 }
52
53 return function scroll (d) {
54 selectChild((!curMsgEl || d === 'first') ? container.firstChild
55 : d < 0 ? curMsgEl.previousElementSibling || container.firstChild
56 : d > 0 ? curMsgEl.nextElementSibling || container.lastChild
57 : curMsgEl)
58
59 return curMsgEl
60 }
61}
62

Built with git-ssb-web