Files: f6b15ef0c66ef8142dc6e63a6065df61a37573a2 / lib / expander-hook.js
706 bytesRaw
1 | module.exports = ExpanderHook |
2 | |
3 | function ExpanderHook (needsExpand) { |
4 | return expander.bind(null, needsExpand) |
5 | } |
6 | |
7 | function expander (needsExpand, element) { |
8 | var 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 | |
19 | function handleEvent (ev) { |
20 | var { needsExpand, element } = this |
21 | if (!needsExpand()) { |
22 | if (element.firstElementChild.clientHeight > element.clientHeight) { |
23 | needsExpand.set(true) |
24 | } |
25 | } |
26 | } |
27 |
Built with git-ssb-web