-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrise_output_fix.js
More file actions
54 lines (48 loc) · 2.16 KB
/
rise_output_fix.js
File metadata and controls
54 lines (48 loc) · 2.16 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
// Small script to keep RISE slides from being pushed off-screen by large outputs.
// It watches for added output areas inside the current slide and if the
// slide's content overflows the viewport it will scroll the slide container
// up by the overflow amount, keeping the earlier content visible.
(function() {
function onOutputAdded(node) {
// find the closest section (slide)
var section = node.closest('section') || node.closest('.reveal') || document.querySelector('.reveal .slides section.present');
if (!section) return;
// give the browser a moment to layout
requestAnimationFrame(function() {
var rect = section.getBoundingClientRect();
var overflow = rect.bottom - window.innerHeight;
if (overflow > 0) {
// scroll the section up inside the slide container
// prefer smooth behavior if available
var parent = document.scrollingElement || document.documentElement;
parent.scrollBy({ top: overflow + 8, left: 0, behavior: 'smooth' });
}
});
}
function observeOutputs() {
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(m) {
m.addedNodes.forEach(function(n) {
if (!n) return;
// detect Jupyter output wrappers
if (n.classList && (n.classList.contains('output') || n.classList.contains('output_area') || n.classList.contains('jp-OutputArea') || n.classList.contains('output_wrapper'))) {
onOutputAdded(n);
} else if (n.querySelectorAll) {
var found = n.querySelectorAll('.output, .output_area, .jp-OutputArea, .output_wrapper');
if (found.length) onOutputAdded(n);
}
});
});
});
observer.observe(document.body, { childList: true, subtree: true });
// also handle immediate existing outputs when script loads
document.querySelectorAll('.output, .output_area, .jp-OutputArea, .output_wrapper').forEach(function(n) {
onOutputAdded(n);
});
}
if (document.readyState === 'complete' || document.readyState === 'interactive') {
observeOutputs();
} else {
document.addEventListener('DOMContentLoaded', observeOutputs);
}
})();