modules/compose.jsView |
---|
8 | 8 | exports.suggest = [] |
9 | 9 | exports.publish = [] |
10 | 10 | exports.message_content = [] |
11 | 11 | exports.message_confirm = [] |
| 12 | +exports.file_input = [] |
12 | 13 | |
13 | 14 | |
14 | 15 | |
15 | 16 | function id (e) { return e } |
16 | 17 | |
17 | 18 | exports.message_compose = function (meta, prepublish, sbot) { |
18 | 19 | if('function' !== typeof prepublish) |
19 | | - sbot = prepublish, prepublish = id |
| 20 | + sbot = prepublish, prepublish = id |
20 | 21 | meta = meta || {} |
21 | 22 | if(!meta.type) throw new Error('message must have type') |
22 | 23 | var ta = h('textarea') |
23 | | - |
24 | | - |
25 | 24 | |
26 | 25 | var blur |
27 | 26 | ta.addEventListener('focus', function () { |
28 | 27 | clearTimeout(blur) |
36 | 35 | ta.style.height = '50px' |
37 | 36 | }, 200) |
38 | 37 | }) |
39 | 38 | |
| 39 | + ta.addEventListener('keydown', function (ev) { |
| 40 | + if(ev.keyCode === 13 && ev.ctrlKey) publish() |
| 41 | + }) |
| 42 | + |
| 43 | + var files = [] |
| 44 | + |
| 45 | + function publish() { |
| 46 | + meta.text = ta.value |
| 47 | + meta.mentions = mentions(ta.value).concat(files) |
| 48 | + try { |
| 49 | + meta = prepublish(meta) |
| 50 | + } catch (err) { |
| 51 | + return alert(err.message) |
| 52 | + } |
| 53 | + u.firstPlug(exports.message_confirm, meta, sbot) |
| 54 | + } |
| 55 | + |
| 56 | + |
40 | 57 | var composer = |
41 | 58 | h('div', h('div.column', ta, |
42 | | - h('button', 'publish', {onclick: function () { |
43 | | - meta.text = ta.value |
44 | | - meta.mentions = mentions(ta.value) |
45 | | - try { |
46 | | - meta = prepublish(meta) |
47 | | - } catch (err) { |
48 | | - return alert(err.message) |
49 | | - } |
50 | | - u.firstPlug(exports.message_confirm, meta, sbot) |
51 | | - }}))) |
| 59 | + h('div.row', |
| 60 | + u.firstPlug(exports.file_input, function (file) { |
| 61 | + files.push(file) |
52 | 62 | |
| 63 | + var embed = file.type.indexOf('image/') === 0 ? '!' : '' |
| 64 | + ta.value += embed + '['+file.name+']('+file.link+')' |
| 65 | + console.log('added:', file) |
| 66 | + }), |
| 67 | + h('button', 'publish', {onclick: publish})) |
| 68 | + ) |
| 69 | + ) |
| 70 | + |
53 | 71 | suggest(ta, function (word, cb) { |
54 | 72 | cont.para(exports.suggest.map(function (fn) { |
55 | 73 | return function (cb) { fn(word, sbot, cb) } |
56 | 74 | })) |
69 | 87 | return composer |
70 | 88 | |
71 | 89 | } |
72 | 90 | |
73 | | - |
74 | | - |
75 | | - |
76 | | - |