git ssb

2+

mixmix / ticktack



Tree: 5e079c1ed4ae498b22ca2dad8c325053457a193c

Files: 5e079c1ed4ae498b22ca2dad8c325053457a193c / app / html / scroller.js

2106 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3const pull = require('pull-stream')
4const Scroller = require('mutant-scroll')
5const next = require('pull-next-step')
6
7exports.gives = nest('app.html.scroller')
8
9exports.needs = nest({
10 'message.html.render': 'first'
11})
12
13exports.create = function (api) {
14 return nest('app.html.scroller', createScroller)
15
16 function createScroller (opts = {}) {
17 const {
18 stream,
19 filter = () => pull.filter((msg) => true),
20 indexProperty = ['value', 'timestamp']
21 } = opts
22
23 const streamToTop = pull(
24 next(stream, {old: false, limit: 100, property: indexProperty }),
25 filter() // is a pull-stream through
26 )
27
28 const streamToBottom = pull(
29 next(stream, {reverse: true, limit: 100, live: false, property: indexProperty }),
30 filter()
31 )
32
33 return Scroller(Object.assign({}, opts, { streamToTop, streamToBottom }))
34 // valid Scroller opts : see github.com/mixmix/mutant-scroll
35 // classList = [],
36 // prepend = [],
37 // append = [],
38 // streamToTop,
39 // streamToBottom,
40 // render,
41 // updateTop = updateTopDefault,
42 // updateBottom = updateBottomDefault,
43 // store = MutantArray(),
44 // cb = (err) => { if (err) throw err }
45 }
46}
47
48function keyscroll (content) {
49 var curMsgEl
50
51 if (!content) return () => {}
52
53 content.addEventListener('click', onActivateChild, false)
54 content.addEventListener('focus', onActivateChild, true)
55
56 function onActivateChild (ev) {
57 for (var el = ev.target; el; el = el.parentNode) {
58 if (el.parentNode === content) {
59 curMsgEl = el
60 return
61 }
62 }
63 }
64
65 function selectChild (el) {
66 if (!el) { return }
67
68 ;(el.scrollIntoViewIfNeeded || el.scrollIntoView).call(el)
69 el.focus()
70 curMsgEl = el
71 }
72
73 return function scroll (d) {
74 selectChild((!curMsgEl || d === 'first') ? content.firstChild
75 : d < 0 ? curMsgEl.previousElementSibling || content.firstChild
76 : d > 0 ? curMsgEl.nextElementSibling || content.lastChild
77 : curMsgEl)
78
79 return curMsgEl
80 }
81}
82

Built with git-ssb-web