git ssb

16+

Dominic / patchbay



Tree: 15c8b380dff5fefb550257e46b87876bda2db1e4

Files: 15c8b380dff5fefb550257e46b87876bda2db1e4 / modules / compose.js

1617 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 (meta, sbot) {
15 meta = meta || {}
16 if(!meta.type) throw new Error('message must have type')
17 var ta = h('textarea')
18 //h('pre.editable.fixed', 'HELLO')
19 //ta.setAttribute('contenteditable', '')
20
21 var blur
22 ta.addEventListener('focus', function () {
23 clearTimeout(blur)
24 ta.style.height = '200px'
25 })
26 ta.addEventListener('blur', function () {
27 //don't shrink right away, so there is time
28 //to click the publish button.
29 clearTimeout(blur)
30 blur = setTimeout(function () {
31 ta.style.height = '50px'
32 }, 200)
33 })
34
35 var composer =
36 h('div', h('div.column', ta,
37 h('button', 'publish', {onclick: function () {
38 meta.text = ta.value
39 meta.mentions = mentions(ta.value)
40 u.firstPlug(exports.message_confirm, meta, sbot)
41 }})))
42
43 suggest(ta, function (word, cb) {
44 cont.para(exports.suggest.map(function (fn) {
45 return function (cb) { fn(word, sbot, cb) }
46 }))
47 (function (err, results) {
48 if(err) console.error(err)
49 results = results.reduce(function (ary, item) {
50 return ary.concat(item)
51 }, []).sort(function (a, b) {
52 return b.rank - a.rank
53 }).filter(Boolean)
54
55 cb(null, results)
56 })
57 }, {})
58
59 return composer
60
61}
62
63
64
65
66
67

Built with git-ssb-web