Files: ef4158cecbf339ae1458111a2ff1218a55bef5f6 / lib / anchor-hook.js
655 bytesRaw
1 | var watch = require('mutant/watch') |
2 | |
3 | module.exports = AnchorHook |
4 | |
5 | function AnchorHook (name, current, cb) { |
6 | return function (element) { |
7 | return watch(current, (current) => { |
8 | if (current === name) { |
9 | window.requestAnimationFrame(() => { |
10 | element.scrollIntoView() |
11 | if (typeof cb === 'function') cb(element) |
12 | |
13 | // HACK: due to a browser bug, sometimes the window scrolls down below the top bar |
14 | // Why not just hack it!!! |
15 | var topBar = document.querySelector('.MainWindow > div.top') |
16 | if (topBar) { |
17 | topBar.scrollIntoViewIfNeeded() |
18 | } |
19 | }) |
20 | } |
21 | }) |
22 | } |
23 | } |
24 |
Built with git-ssb-web