Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (68 loc) · 2.85 KB
/
Copy pathscript.js
File metadata and controls
72 lines (68 loc) · 2.85 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
// Start once half the video is visible; leave native controls available.
document.querySelectorAll('video[data-scroll-play]').forEach((video) => {
if (!('IntersectionObserver' in window)) return;
let inView = false;
function updatePlayback() {
if (!inView || document.hidden) {
video.pause();
} else if (!video.ended) {
// Autoplay restrictions or a quick scroll can reject this promise.
video.play().catch(() => {});
}
}
const observer = new IntersectionObserver(([entry]) => {
inView = entry.isIntersecting && entry.intersectionRatio >= 0.5;
updatePlayback();
}, { threshold: [0, 0.5] });
observer.observe(video);
document.addEventListener('visibilitychange', updatePlayback);
});
// All content and original-resolution figures remain available without JavaScript.
document.querySelectorAll('[data-gallery]').forEach((gallery) => {
const tabList = gallery.querySelector('[role="tablist"]');
const tabs = [...gallery.querySelectorAll('[role="tab"]')];
const panels = [...gallery.querySelectorAll('[role="tabpanel"]')];
function selectTab(selected, focus = false) {
tabs.forEach((tab) => {
const active = tab === selected;
tab.setAttribute('aria-selected', String(active));
tab.tabIndex = active ? 0 : -1;
});
panels.forEach((panel) => { panel.hidden = panel.id !== selected.getAttribute('aria-controls'); });
if (focus) selected.focus();
}
tabList.hidden = false;
selectTab(tabs[0]);
tabs.forEach((tab, index) => {
tab.addEventListener('click', () => selectTab(tab));
tab.addEventListener('keydown', (event) => {
let next;
if (event.key === 'ArrowRight') next = (index + 1) % tabs.length;
if (event.key === 'ArrowLeft') next = (index - 1 + tabs.length) % tabs.length;
if (event.key === 'Home') next = 0;
if (event.key === 'End') next = tabs.length - 1;
if (next !== undefined) { event.preventDefault(); selectTab(tabs[next], true); }
});
});
});
const copyButton = document.querySelector('#copy-citation');
const copyStatus = document.querySelector('#copy-status');
copyButton.hidden = false;
copyButton.addEventListener('click', async () => {
const citation = document.querySelector('#bibtex');
try {
if (!navigator.clipboard) throw new Error('Clipboard unavailable');
await navigator.clipboard.writeText(citation.textContent);
copyStatus.textContent = 'Citation copied to clipboard.';
copyButton.textContent = 'Copied ✓';
window.setTimeout(() => { copyButton.textContent = 'Copy citation ⧉'; }, 2500);
} catch {
const range = document.createRange();
range.selectNodeContents(citation);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
copyStatus.textContent = 'Citation selected. Press Ctrl+C (Windows/Linux) or ⌘C (Mac) to copy.';
}
});