git ssb

16+

Dominic / patchbay



Commit bf289fc707717f3828ed39f6cfcfcc0c51d41947

warn the user before opening an external link

introduces external_confirm into the depject api, a simpler copy of message_confirm
Henry committed on 1/11/2017, 12:22:50 AM
Parent: 93d26ea7530a862ffda0f98070f6a1ce09d1d616

Files changed

modules_core/index.jschanged
modules_core/tabs.jschanged
modules_core/external-confirm.jsadded
modules_core/index.jsView
@@ -2,8 +2,9 @@
22 // "_screen_view.js": require('./_screen_view.js'),
33 "app.js": require('./app.js'),
44 "blob-url.js": require('./blob-url.js'),
55 "crypto.js": require('./crypto.js'),
6 + "external-confirm.js": require('./external-confirm.js'),
67 "file-input.js": require('./file-input.js'),
78 "menu.js": require('./menu.js'),
89 "message-confirm.js": require('./message-confirm.js'),
910 "tabs.js": require('./tabs.js'),
modules_core/tabs.jsView
@@ -15,9 +15,9 @@
1515 //var screen_view = plugs.first(exports._screen_view = [])
1616 //var search_box = plugs.first(exports.search_box = [])
1717 //var menu = plugs.first(exports.menu = [])
1818
19-exports.needs = {screen_view: 'first', search_box: 'first', menu: 'first'}
19 +exports.needs = {screen_view: 'first', search_box: 'first', menu: 'first', 'external_confirm':'first'}
2020
2121 exports.gives = 'screen_view'
2222
2323 exports.create = function (api) {
@@ -94,9 +94,9 @@
9494 if (link.getAttribute('href') === '#') return
9595
9696 //open external links.
9797 //this ought to be made into something more runcible
98- if(open.isExternal(link.href)) return open(link.href)
98 + if(open.isExternal(link.href)) return api.external_confirm(link.href)
9999
100100 if(tabs.has(path))
101101 return tabs.select(path, !ev.ctrlKey, !!ev.shiftKey)
102102
modules_core/external-confirm.jsView
@@ -1,0 +1,37 @@
1 +var lightbox = require('hyperlightbox')
2 +var h = require('hyperscript')
3 +var open = require('open-external')
4 +
5 +exports.gives = 'external_confirm'
6 +
7 +exports.create = function (api) {
8 + return function (href) {
9 + var lb = lightbox()
10 + document.body.appendChild(lb)
11 +
12 + var okay = h('button', 'open', {onclick: function () {
13 + lb.remove()
14 + open(href)
15 + }})
16 +
17 + var cancel = h('button', 'Cancel', {onclick: function () {
18 + lb.remove()
19 + }})
20 +
21 + okay.addEventListener('keydown', function (ev) {
22 + if (ev.keyCode === 27) cancel.click() // escape
23 + })
24 +
25 + lb.show(h('div.column.message-confirm',
26 + h('div.message',
27 + h('div.title.row',
28 + h('div.message_meta.row', h('strong', 'warning: '), 'please confirm opening the following link in your OSes browser:')
29 + ),
30 + h('div.message_content', h('pre', href))
31 + ),
32 + h('div.row.message-confirm__controls', okay, cancel)
33 + ))
34 +
35 + okay.focus()
36 + }
37 +}

Built with git-ssb-web