Files: 1fd3c2d9148ba9ea22b04eabc592afe3ff16dabe / modules / compose.js
1617 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 (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