git ssb

1+

Daan Patchwork / patchwork



Tree: aabb27408791b10bbb6e9ba87c00240141ddec4a

Files: aabb27408791b10bbb6e9ba87c00240141ddec4a / lib / anchor-hook.js

799 bytesRaw
1const 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 || (current && current.anchor === name)) {
9 element.classList.add('-anchor')
10 window.requestAnimationFrame(() => {
11 element.scrollIntoView()
12 if (typeof cb === 'function') cb(element)
13
14 // HACK: due to a browser bug, sometimes the window scrolls down below the top bar
15 // Why not just hack it!!!
16 const topBar = document.querySelector('.MainWindow > div.top')
17 if (topBar) {
18 topBar.scrollIntoViewIfNeeded()
19 }
20 })
21 } else {
22 element.classList.remove('-anchor')
23 }
24 })
25 }
26}
27

Built with git-ssb-web