Commit 4441fae4d0d265267896434addfea2900d7f5154
add external link handling
mix irving committed on 3/3/2017, 2:05:15 AMParent: 3c63691a3ff381ff83e86a97ce3246807bccae1e
Files changed
main/html/app.js | changed |
main/html/external-confirm.js | added |
main/html/external-confirm.mcss | added |
message/html/meta/likes.js | changed |
main/html/app.js | ||
---|---|---|
@@ -6,8 +6,9 @@ | ||
6 | 6 | exports.gives = nest('main.html.app') |
7 | 7 | |
8 | 8 | exports.needs = nest({ |
9 | 9 | 'main.html.error': 'first', |
10 | + 'main.html.externalConfirm': 'first', | |
10 | 11 | 'router.html.page': 'first', |
11 | 12 | 'styles.css': 'reduce' |
12 | 13 | }) |
13 | 14 | |
@@ -32,15 +33,15 @@ | ||
32 | 33 | initialTabs.forEach(r => addPage(r)) |
33 | 34 | tabs.select(0) |
34 | 35 | |
35 | 36 | catchClick(App, (link, { ctrlKey: openBackground, isExternal }) => { |
37 | + if (isExternal) api.main.html.externalConfirm(link) | |
38 | + | |
36 | 39 | if (tabs.has(link)) tabs.select(link) |
37 | 40 | else { |
38 | 41 | const changeTab = !openBackground |
39 | 42 | addPage(link, changeTab) |
40 | 43 | } |
41 | - | |
42 | - // TODO add external-links module | |
43 | 44 | }) |
44 | 45 | |
45 | 46 | // Catch errors |
46 | 47 | var { container: errorPage, content: errorList } = api.router.html.page('/errors') |
main/html/external-confirm.js | ||
---|---|---|
@@ -1,0 +1,46 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const lightbox = require('hyperlightbox') | |
3 | +const { h } = require('mutant') | |
4 | +const open = require('open-external') | |
5 | + | |
6 | +exports.gives = nest('main.html.externalConfirm') | |
7 | + | |
8 | +exports.create = function (api) { | |
9 | + return nest('main.html.externalConfirm', externalConfirm) | |
10 | + | |
11 | + function externalConfirm (href) { | |
12 | + var lb = lightbox() | |
13 | + document.body.appendChild(lb) | |
14 | + | |
15 | + var okay = h('button.okay', { | |
16 | + 'ev-click': () => { | |
17 | + lb.remove() | |
18 | + open(href) | |
19 | + }}, | |
20 | + 'open' | |
21 | + ) | |
22 | + | |
23 | + var cancel = h('button.cancel', { | |
24 | + 'ev-click': () => { | |
25 | + lb.remove() | |
26 | + }}, | |
27 | + 'cancel' | |
28 | + ) | |
29 | + | |
30 | + okay.addEventListener('keydown', function (ev) { | |
31 | + if (ev.keyCode === 27) cancel.click() // escape | |
32 | + }) | |
33 | + | |
34 | + lb.show(h('ExternalConfirm', [ | |
35 | + h('header', 'External link'), | |
36 | + h('section.prompt', [ | |
37 | + h('div.question', 'Open this link in your external browser?'), | |
38 | + h('pre.link', href) | |
39 | + ]), | |
40 | + h('section.actions', [cancel, okay]) | |
41 | + ])) | |
42 | + | |
43 | + okay.focus() | |
44 | + } | |
45 | +} | |
46 | + |
main/html/external-confirm.mcss | ||
---|---|---|
@@ -1,0 +1,34 @@ | ||
1 | +ExternalConfirm { | |
2 | + header { | |
3 | + font-weight: 600 | |
4 | + margin-bottom: .5rem | |
5 | + } | |
6 | + | |
7 | + section.prompt { | |
8 | + background: #fff | |
9 | + padding: 1rem | |
10 | + margin-bottom: 1rem | |
11 | + | |
12 | + div.question{ | |
13 | + | |
14 | + } | |
15 | + | |
16 | + pre.link { | |
17 | + | |
18 | + } | |
19 | + } | |
20 | + | |
21 | + section.actions { | |
22 | + display: flex | |
23 | + justify-content: flex-end | |
24 | + | |
25 | + button.cancel { | |
26 | + | |
27 | + } | |
28 | + button.okay { | |
29 | + margin-right: 0 | |
30 | + | |
31 | + } | |
32 | + } | |
33 | +} | |
34 | + |
message/html/meta/likes.js | ||
---|---|---|
@@ -9,9 +9,9 @@ | ||
9 | 9 | }) |
10 | 10 | |
11 | 11 | exports.create = (api) => { |
12 | 12 | return nest('message.html.meta', likes) |
13 | - | |
13 | + | |
14 | 14 | function likes (msg) { |
15 | 15 | const symbol = '\u2713' // tick 🗸 |
16 | 16 | |
17 | 17 | var likes = api.message.obs.likes(msg.key) |
@@ -21,9 +21,9 @@ | ||
21 | 21 | : Array(likes.length).fill(symbol).join('') |
22 | 22 | ) |
23 | 23 | |
24 | 24 | var names = map(likes, id => api.about.obs.name(id)) |
25 | - var title = computed(names, names => names.map(n => '@'+n).join('\n')) | |
25 | + var title = computed(names, names => names.map(n => '@' + n).join('\n')) | |
26 | 26 | |
27 | 27 | return h('a.likes', { title }, body) |
28 | 28 | } |
29 | 29 | } |
Built with git-ssb-web