git ssb

10+

Matt McKegg / patchwork



Tree: efead363d153b58ea67532a7044afee4c76bb99a

Files: efead363d153b58ea67532a7044afee4c76bb99a / lib / anchor-hook.js

795 bytesRaw
1var watch = require('mutant/watch')
2
3module.exports = AnchorHook
4
5function AnchorHook (name, current, cb) {
6 return function (element) {
7 return watch(current, (current) => {
8 if (current === name) {
9 window.requestAnimationFrame(() => {
10 element.scrollIntoView()
11
12 // just make sure we still have the scroll position
13 setTimeout(() => element.scrollIntoViewIfNeeded(), 400)
14
15 if (typeof cb === 'function') cb(element)
16
17 // HACK: due to a browser bug, sometimes the window scrolls down below the top bar
18 // Why not just hack it!!!
19 var topBar = document.querySelector('.MainWindow > div.top')
20 if (topBar) {
21 topBar.scrollIntoViewIfNeeded()
22 }
23 })
24 }
25 })
26 }
27}
28

Built with git-ssb-web