git ssb

16+

Dominic / patchbay



Commit 4441fae4d0d265267896434addfea2900d7f5154

add external link handling

mix irving committed on 3/3/2017, 2:05:15 AM
Parent: 3c63691a3ff381ff83e86a97ce3246807bccae1e

Files changed

main/html/app.jschanged
main/html/external-confirm.jsadded
main/html/external-confirm.mcssadded
message/html/meta/likes.jschanged
main/html/app.jsView
@@ -6,8 +6,9 @@
66 exports.gives = nest('main.html.app')
77
88 exports.needs = nest({
99 'main.html.error': 'first',
10+ 'main.html.externalConfirm': 'first',
1011 'router.html.page': 'first',
1112 'styles.css': 'reduce'
1213 })
1314
@@ -32,15 +33,15 @@
3233 initialTabs.forEach(r => addPage(r))
3334 tabs.select(0)
3435
3536 catchClick(App, (link, { ctrlKey: openBackground, isExternal }) => {
37+ if (isExternal) api.main.html.externalConfirm(link)
38+
3639 if (tabs.has(link)) tabs.select(link)
3740 else {
3841 const changeTab = !openBackground
3942 addPage(link, changeTab)
4043 }
41-
42- // TODO add external-links module
4344 })
4445
4546 // Catch errors
4647 var { container: errorPage, content: errorList } = api.router.html.page('/errors')
main/html/external-confirm.jsView
@@ -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.mcssView
@@ -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.jsView
@@ -9,9 +9,9 @@
99 })
1010
1111 exports.create = (api) => {
1212 return nest('message.html.meta', likes)
13-
13+
1414 function likes (msg) {
1515 const symbol = '\u2713' // tick 🗸
1616
1717 var likes = api.message.obs.likes(msg.key)
@@ -21,9 +21,9 @@
2121 : Array(likes.length).fill(symbol).join('')
2222 )
2323
2424 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'))
2626
2727 return h('a.likes', { title }, body)
2828 }
2929 }

Built with git-ssb-web