const fs = require('fs') const lightbox = require('hyperlightbox') const h = require('../h') const u = require('../util') const self_id = require('../keys').id //publish or add const plugs = require('../plugs') exports.needs = { publish: 'first', message_render: 'first', avatar: 'first', message_meta: 'map' } exports.gives = { message_confirm: 'true', mcss: 'true' } exports.create = function (api) { return { message_confirm, mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8') } function message_confirm (content, cb) { cb = cb || function () {} var lb = lightbox() document.body.appendChild(lb) var msg = { key: "DRAFT", value: { author: self_id, previous: null, sequence: null, timestamp: Date.now(), content: content } } var okay = h('button', { 'ev-click': () => { lb.remove() api.publish(content, cb) }}, 'okay' ) var cancel = h('button', { 'ev-click': () => { lb.remove() cb(null) }}, 'Cancel' ) okay.addEventListener('keydown', function (ev) { if(ev.keyCode === 27) cancel.click() //escape }) lb.show(h('MessageConfirm', [ h('header -preview_description', h('h1', 'Preview')), h('section -message_preview', api.message_render(msg)), h('section -actions', [okay, cancel]) ] )) okay.focus() } }