git ssb

1+

Daan Patchwork / patchwork



Tree: 58ab0241031aa549a35cce1e678c27065ae66221

Files: 58ab0241031aa549a35cce1e678c27065ae66221 / lib / observe-link-hover.js

615 bytesRaw
1const Sustained = require('./sustained')
2const Value = require('mutant/value')
3
4module.exports = function (root, delay) {
5 const target = Value()
6 root.addEventListener('mouseover', (ev) => {
7 let anchor = null
8 for (let n = ev.target; n.parentNode; n = n.parentNode) {
9 if (n.nodeName === 'A') {
10 anchor = n
11 break
12 }
13 }
14 target.set(anchor)
15 })
16
17 root.addEventListener('mouseleave', () => {
18 target.set(false)
19 })
20
21 const result = Sustained(target, delay || 500, (v) => {
22 return v === undefined
23 })
24
25 result.cancel = () => target.set(undefined)
26 return result
27}
28

Built with git-ssb-web