Files: 7c22ec2ce201b04fa7c787e4f7833eb28065327b / modules_core / external-confirm.js
1077 bytesRaw
1 | const lightbox = require('hyperlightbox') |
2 | const fs = require('fs') |
3 | const h = require('../h') |
4 | const open = require('open-external') |
5 | |
6 | exports.gives = { |
7 | external_confirm: true, |
8 | mcss:true |
9 | } |
10 | |
11 | exports.create = function (api) { |
12 | return { |
13 | external_confirm, |
14 | mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8') |
15 | } |
16 | |
17 | function external_confirm (href) { |
18 | var lb = lightbox() |
19 | document.body.appendChild(lb) |
20 | |
21 | var okay = h('button.okay', { |
22 | 'ev-click': () => { |
23 | lb.remove() |
24 | open(href) |
25 | }}, |
26 | 'open' |
27 | ) |
28 | |
29 | var cancel = h('button.cancel', { |
30 | 'ev-click': () => { |
31 | lb.remove() |
32 | }}, |
33 | 'cancel' |
34 | ) |
35 | |
36 | okay.addEventListener('keydown', function (ev) { |
37 | if (ev.keyCode === 27) cancel.click() // escape |
38 | }) |
39 | |
40 | lb.show(h('ExternalConfirm', [ |
41 | h('header', 'External link'), |
42 | h('section.prompt', [ |
43 | h('div.question', 'Open this link in your external browser?'), |
44 | h('pre.link', href) |
45 | ]), |
46 | h('section.actions', [cancel, okay]) |
47 | ])) |
48 | |
49 | okay.focus() |
50 | } |
51 | } |
52 |
Built with git-ssb-web