-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsidebars-toggle.html
41 lines (35 loc) · 1.3 KB
/
sidebars-toggle.html
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
<script type="module">
// When keyboard's 's' key is pressed,
// hide both sidebars (tables of contents)
document.addEventListener(
"keydown",
function (evt) {
// Avoid keydown event repetition due to holding key
if (evt.repeat) return;
if ('s' === event.key.toLowerCase()) {
const quartoContent = document.querySelector("#quarto-content");
if (window.getComputedStyle(quartoContent).display === 'grid') {
// Remove grid display
quartoContent.style.display = "block";
// Hide every HTML element, except for main content
quartoContent
.querySelectorAll(":scope > :not(.content, script)")
.forEach(e => e.style.display = "none");
// Change content margin for desktop view
quartoContent
.querySelector("main.content")
.style.margin = "20px 100px";
} else {
// Try to restore Quarto's initial style
quartoContent.style.display = "grid";
quartoContent
.querySelectorAll(":scope > :not(.content, script)")
.forEach(e => e.style.display = "flex");
quartoContent
.querySelector("main.content")
.style.margin = "21px 0";
}
}
}
);
</script>