git ssb

16+

Dominic / patchbay



Tree: ceab09c9e34bbabf034b57309315733a28ec5e7a

Files: ceab09c9e34bbabf034b57309315733a28ec5e7a / modules / compose.js

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

Built with git-ssb-web