git ssb

16+

Dominic / patchbay



Tree: 0317853c50ffacda585e8b019f18d3b8ff32329a

Files: 0317853c50ffacda585e8b019f18d3b8ff32329a / modules / compose.js

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

Built with git-ssb-web