Commit 2a990899321f909f52dce13715ee580d1e8507b6
correctly detect internal and external links
Dominic Tarr committed on 7/20/2016, 2:04:04 AMParent: eeaba82cd174ef3af7ffc6f6bc0aa88d92a5c6ec
Files changed
modules/tabs.js | changed |
modules/tabs.js | ||
---|---|---|
@@ -2,8 +2,9 @@ | ||
2 | 2 | var h = require('hyperscript') |
3 | 3 | var pull = require('pull-stream') |
4 | 4 | var u = require('../util') |
5 | 5 | var keyscroll = require('../keyscroll') |
6 | +var open = require('open-external') | |
6 | 7 | |
7 | 8 | function ancestor (el) { |
8 | 9 | if(!el) return |
9 | 10 | if(el.tagName !== 'A') return ancestor(el.parentElement) |
@@ -13,23 +14,8 @@ | ||
13 | 14 | var plugs = require('../plugs') |
14 | 15 | var screen_view = plugs.first(exports.screen_view = []) |
15 | 16 | var search_box = plugs.first(exports.search_box = []) |
16 | 17 | |
17 | -function openExternal (url) { | |
18 | - var _r = require //fool browserify | |
19 | - | |
20 | - //electron@1 | |
21 | - try {return _r('electron').shell.openExternal(url) } | |
22 | - catch (err) { } | |
23 | - | |
24 | - //electron@0 | |
25 | - try { return _r('shell').openExternal(url) } | |
26 | - catch (err) { } | |
27 | - | |
28 | - //browser | |
29 | - window.open(url, '_blank') | |
30 | -} | |
31 | - | |
32 | 18 | exports.message_render = [] |
33 | 19 | |
34 | 20 | exports.app = function () { |
35 | 21 | var search |
@@ -80,9 +66,9 @@ | ||
80 | 66 | ev.stopPropagation() |
81 | 67 | |
82 | 68 | //open external links. |
83 | 69 | //this ought to be made into something more runcible |
84 | - if(/^https?/.test(link.href)) return openExternal(link.href) | |
70 | + if(open.isExternal(link.href)) return open(link.href) | |
85 | 71 | |
86 | 72 | if(tabs.has(path)) return tabs.select(path) |
87 | 73 | |
88 | 74 | var el = screen_view(path) |
@@ -165,6 +151,4 @@ | ||
165 | 151 | |
166 | 152 | return tabs |
167 | 153 | } |
168 | 154 | |
169 | - | |
170 | - |
Built with git-ssb-web