git ssb

16+

Dominic / patchbay



Tree: ae7c2d638a47d2b374cec6c88e45d20c4290fe33

Files: ae7c2d638a47d2b374cec6c88e45d20c4290fe33 / modules / compose.js

1458 bytesRaw
1var h = require('hyperscript')
2var suggest = require('suggest-box')
3var cont = require('cont')
4var mentions = require('ssb-mentions')
5exports.suggest = []
6
7//this decorator expects to be the first
8exports.message_compose = function (el, meta, sbot) {
9 if(el) return el
10
11 meta = meta || {}
12 var ta = h('textarea')
13 //h('pre.editable.fixed', 'HELLO')
14 //ta.setAttribute('contenteditable', '')
15
16 var blur
17 ta.addEventListener('focus', function () {
18 clearTimeout(blur)
19 ta.style.height = '200px'
20 })
21 ta.addEventListener('blur', function () {
22 //don't shrink right away, so there is time
23 //to click the publish button.
24 clearTimeout(blur)
25 blur = setTimeout(function () {
26 ta.style.height = '50px'
27 }, 200)
28 })
29
30 var composer =
31 h('div', h('div.column', ta,
32 h('button', 'publish', {onclick: function () {
33 meta.text = ta.value
34 meta.mentions = mentions(ta.value)
35 alert(JSON.stringify(meta, null, 2))
36 }})))
37
38 suggest(ta, function (word, cb) {
39 cont.para(exports.suggest.map(function (fn) {
40 return function (cb) { fn(word, sbot, cb) }
41 }))
42 (function (err, results) {
43 if(err) console.error(err)
44 results = results.reduce(function (ary, item) {
45 return ary.concat(item)
46 }, []).sort(function (a, b) {
47 return b.rank - a.rank
48 }).filter(Boolean)
49
50 console.log('RESULTS', results)
51 cb(null, results)
52 })
53 }, {})
54
55 return composer
56
57}
58
59
60

Built with git-ssb-web