git ssb

16+

Dominic / patchbay



Tree: 15b8e0d085e01b8161f4a7c1675afdda7a02e527

Files: 15b8e0d085e01b8161f4a7c1675afdda7a02e527 / modules_basic / message / confirm.js

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

Built with git-ssb-web