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