summaryrefslogtreecommitdiffstats
path: root/assets/js/ed.js
blob: fb75c943e47fcaec3adfa9ed2e3cbffe2424b3af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 'Back to top' logic
function setupBackToTop() {
  const intersectionObserver = new IntersectionObserver(function(entries) {
    const topBtn = document.querySelector('.top-of-site-link');
    if (topBtn === null) return;

    topBtn.dataset.visible = entries[0].boundingClientRect.y < 0;
  });

  const topAnchor = document.querySelector('#top-of-site-anchor');
  if (topAnchor !== null) {
    intersectionObserver.observe(topAnchor);
  }
}

document.addEventListener('DOMContentLoaded', () => {
  setupBackToTop();
  setupHypothes();
});