Files: abd49a5d6c84f499180e6bdbb52e5188d42df75e / modules_core / message-confirm.js
1472 bytesRaw
1 | var fs = require('fs') |
2 | var lightbox = require('hyperlightbox') |
3 | var h = require('../h') |
4 | var u = require('../util') |
5 | var self_id = require('../keys').id |
6 | //publish or add |
7 | |
8 | var plugs = require('../plugs') |
9 | |
10 | exports.needs = { |
11 | publish: 'first', |
12 | message_render: 'first', |
13 | avatar: 'first', |
14 | message_meta: 'map' |
15 | } |
16 | |
17 | exports.gives = { |
18 | message_confirm: 'true', |
19 | mcss: 'true' |
20 | } |
21 | |
22 | exports.create = function (api) { |
23 | return { |
24 | message_confirm, |
25 | mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8') |
26 | } |
27 | |
28 | function message_confirm (content, cb) { |
29 | |
30 | cb = cb || function () {} |
31 | |
32 | var lb = lightbox() |
33 | document.body.appendChild(lb) |
34 | |
35 | var msg = { |
36 | key: "DRAFT", |
37 | value: { |
38 | author: self_id, |
39 | previous: null, |
40 | sequence: null, |
41 | timestamp: Date.now(), |
42 | content: content |
43 | } |
44 | } |
45 | |
46 | var okay = h('button', { |
47 | 'ev-click': () => { |
48 | lb.remove() |
49 | api.publish(content, cb) |
50 | }}, |
51 | 'okay' |
52 | ) |
53 | |
54 | var cancel = h('button', { |
55 | 'ev-click': () => { |
56 | lb.remove() |
57 | cb(null) |
58 | }}, |
59 | 'Cancel' |
60 | ) |
61 | |
62 | okay.addEventListener('keydown', function (ev) { |
63 | if(ev.keyCode === 27) cancel.click() //escape |
64 | }) |
65 | |
66 | lb.show(h('MessageConfirm', [ |
67 | h('header -preview_description', h('h1', 'Preview')), |
68 | h('section -message_preview', api.message_render(msg)), |
69 | h('section -actions', [okay, cancel]) |
70 | ] |
71 | )) |
72 | |
73 | okay.focus() |
74 | } |
75 | } |
76 | |
77 |
Built with git-ssb-web