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