git ssb

16+

Dominic / patchbay



Tree: f6391d5b5450e27f0c7a8dba7d82a53c4ad2634a

Files: f6391d5b5450e27f0c7a8dba7d82a53c4ad2634a / modules_core / message-confirm.js

1408 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', {
44 'ev-click': () => {
45 lb.remove()
46 api.publish(content, cb)
47 }},
48 'okay'
49 )
50
51 var cancel = h('button', {
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', h('h1', 'Preview')),
65 h('section -message_preview', api.message_render(msg)),
66 h('section -actions', [okay, cancel])
67 ]
68 ))
69
70 okay.focus()
71 }
72}
73
74

Built with git-ssb-web