git ssb

2+

mixmix / ticktack



Tree: 1b9e4fefcc2bb238e43c37df39cb776444d8978e

Files: 1b9e4fefcc2bb238e43c37df39cb776444d8978e / 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