git ssb

2+

mixmix / ticktack



Tree: f2c1e3d81bf5bba14c878872f1c99529d7eb2be5

Files: f2c1e3d81bf5bba14c878872f1c99529d7eb2be5 / app / async / catch-link-click.js

910 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 const href = anchor.getAttribute('href')
26 if (!href) return
27
28 const url = Url.parse(href)
29 const opts = {
30 isExternal: !!url.host
31 }
32
33 cb(href, opts)
34 })
35 }
36}
37
38
39

Built with git-ssb-web