git ssb

1+

Daan Patchwork / patchwork



Tree: 612509945be4d8cb719d3b0a5a0390a0ddbcf911

Files: 612509945be4d8cb719d3b0a5a0390a0ddbcf911 / lib / expander-hook.js

741 bytesRaw
1module.exports = ExpanderHook
2
3function ExpanderHook (needsExpand) {
4 return expander.bind(null, needsExpand)
5}
6
7function expander (needsExpand, element) {
8 const handler = { handleEvent, needsExpand, element }
9 handleEvent.call(handler)
10
11 if (element.querySelector('img')) {
12 // just in case images are still loading
13 setTimeout(handleEvent.bind(handler), 200)
14 element.addEventListener('mouseover', handler)
15 return element.removeEventListener.bind(element, 'mouseover', handler)
16 }
17}
18
19function handleEvent () {
20 const { needsExpand, element } = this
21 if (!needsExpand()) {
22 if (element.firstElementChild && element.firstElementChild.clientHeight + 5 > element.clientHeight) {
23 needsExpand.set(true)
24 }
25 }
26}
27

Built with git-ssb-web