blob: 60c45ee0231723005e62741323725073cabe5f26 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
// '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);
}
}
// Annotation support
function setupHypothes() {
const hypothesisContainer = document.querySelector('.hypothesis-container');
if (hypothesisContainer !== null) {
hypothesisContainer.addEventListener('click', (e) => {
e.preventDefault();
let script = document.createElement('script');
script.setAttribute('src', 'https://cdn.hypothes.is/hypothesis');
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
});
}
const hypothesisLink = document.querySelector('#hypothesis-link');
if (hypothesisLink !== null) {
hypothesisContainer.addEventListener('click', (e) => {
e.preventDefault();
});
}
}
document.addEventListener('DOMContentLoaded', function () {
setupBackToTop();
setupHypothes();
});
|