git ssb

16+

Dominic / patchbay



Tree: 5477cb7eccf839bf6a1c666a5a2808a6ead826f1

Files: 5477cb7eccf839bf6a1c666a5a2808a6ead826f1 / app / async / catch-link-click.js

1018 bytesRaw
1const nest = require('depnest')
2const Url = require('url')
3
4exports.gives = nest('app.async.catchLinkClick')
5
6exports.create = function (api) {
7 return nest('app.async.catchLinkClick', catchLinkClick)
8
9 function catchLinkClick (root, cb) {
10 root.addEventListener('click', (ev) => {
11 if (ev.target.tagName === 'INPUT' && ev.target.type === 'file') return
12 if (ev.defaultPrevented) return // TODO check this is in the right place
13 ev.preventDefault()
14 ev.stopPropagation()
15
16 var anchor = null
17 for (var n = ev.target; n.parentNode; n = n.parentNode) {
18 if (n.nodeName === 'A') {
19 anchor = n
20 break
21 }
22 }
23 if (!anchor) return true
24
25 var href = anchor.getAttribute('href')
26 if (!href) return
27
28 var url = Url.parse(href)
29 var opts = {
30 altKey: ev.altKey,
31 ctrlKey: ev.ctrlKey,
32 metaKey: ev.metaKey,
33 shiftKey: ev.shiftKey,
34 isExternal: !!url.host
35 }
36
37 cb(href, opts)
38 })
39 }
40}
41
42

Built with git-ssb-web