Files: b62ecd6f843b26f37e70c7b6d65c71db35bbf922 / modules / message-confirm.js
1451 bytesRaw
1 | var lightbox = require('hyperlightbox') |
2 | var h = require('hyperscript') |
3 | var u = require('../util') |
4 | var self_id = require('../keys').id |
5 | |
6 | var plugs = require('../plugs') |
7 | |
8 | exports.needs = { |
9 | publish: 'first', message_content: 'first', avatar: 'first', |
10 | message_meta: 'map' |
11 | } |
12 | |
13 | exports.gives = 'message_confirm' |
14 | |
15 | exports.create = function (api) { |
16 | return function (content, cb) { |
17 | |
18 | cb = cb || function () {} |
19 | |
20 | var lb = lightbox() |
21 | document.body.appendChild(lb) |
22 | |
23 | var msg = { |
24 | key: "DRAFT", |
25 | value: { |
26 | author: self_id, |
27 | previous: null, |
28 | sequence: null, |
29 | timestamp: Date.now(), |
30 | content: content |
31 | } |
32 | } |
33 | |
34 | var okay = h('button', 'Publish', {onclick: function () { |
35 | lb.remove() |
36 | api.publish(content, cb) |
37 | }}) |
38 | |
39 | var cancel = h('button', 'Cancel', {onclick: function () { |
40 | lb.remove() |
41 | cb(null) |
42 | }}) |
43 | |
44 | okay.addEventListener('keydown', function (ev) { |
45 | if(ev.keyCode === 27) cancel.click() //escape |
46 | }) |
47 | |
48 | lb.show(h('div.column.message-confirm', |
49 | h('div.message', |
50 | h('div.title.row', |
51 | h('div.avatar', api.avatar(msg.value.author, 'thumbnail')), |
52 | h('div.message_meta.row', api.message_meta(msg)) |
53 | ), |
54 | h('div.message_content', |
55 | api.message_content(msg) || h('pre', JSON.stringify(msg, null, 2))), |
56 | h('div.row.message-confirm__controls', okay, cancel) |
57 | ) |
58 | )) |
59 | |
60 | okay.focus() |
61 | } |
62 | } |
63 | |
64 |
Built with git-ssb-web