Files: 7b8459c024b593664fa22d32c9b9bcccfe02a2fa / modules / compose.js
1640 bytesRaw
1 | var h = require('hyperscript') |
2 | var u = require('../util') |
3 | var suggest = require('suggest-box') |
4 | var cont = require('cont') |
5 | var mentions = require('ssb-mentions') |
6 | var lightbox = require('hyperlightbox') |
7 | |
8 | exports.suggest = [] |
9 | exports.publish = [] |
10 | exports.message_content = [] |
11 | exports.message_confirm = [] |
12 | |
13 | //this decorator expects to be the first |
14 | exports.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