Skip to content

Commit fba9f76

Browse files
deploy: 8f78cbd
1 parent 20cf756 commit fba9f76

30 files changed

+868
-174
lines changed

404.html

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,23 @@
3838
const path_to_root = "";
3939
const default_light_theme = "light";
4040
const default_dark_theme = "navy";
41+
window.path_to_searchindex_js = "searchindex.js";
4142
</script>
4243
<!-- Start loading toc.js asap -->
4344
<script src="toc.js"></script>
4445
</head>
4546
<body>
47+
<div id="mdbook-help-container">
48+
<div id="mdbook-help-popup">
49+
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
50+
<div>
51+
<p>Press <kbd></kbd> or <kbd></kbd> to navigate between chapters</p>
52+
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
53+
<p>Press <kbd>?</kbd> to show this help</p>
54+
<p>Press <kbd>Esc</kbd> to hide this help</p>
55+
</div>
56+
</div>
57+
</div>
4658
<div id="body-container">
4759
<!-- Work around some values being stored in localStorage wrapped in quotes -->
4860
<script>
@@ -83,10 +95,13 @@
8395
sidebar = sidebar || 'visible';
8496
} else {
8597
sidebar = 'hidden';
98+
sidebar_toggle.checked = false;
99+
}
100+
if (sidebar === 'visible') {
101+
sidebar_toggle.checked = true;
102+
} else {
103+
html.classList.remove('sidebar-visible');
86104
}
87-
sidebar_toggle.checked = sidebar === 'visible';
88-
html.classList.remove('sidebar-visible');
89-
html.classList.add("sidebar-" + sidebar);
90105
</script>
91106

92107
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
@@ -120,7 +135,7 @@
120135
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
121136
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
122137
</ul>
123-
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
138+
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
124139
<i class="fa fa-search"></i>
125140
</button>
126141
</div>
@@ -140,7 +155,12 @@ <h1 class="menu-title">microvm.nix</h1>
140155

141156
<div id="search-wrapper" class="hidden">
142157
<form id="searchbar-outer" class="searchbar-outer">
143-
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
158+
<div class="search-wrapper">
159+
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
160+
<div class="spinner-wrapper">
161+
<i class="fa fa-spinner fa-spin"></i>
162+
</div>
163+
</div>
144164
</form>
145165
<div id="searchresults-outer" class="searchresults-outer hidden">
146166
<div id="searchresults-header" class="searchresults-header"></div>
@@ -199,6 +219,7 @@ <h1 id="document-not-found-404"><a class="header" href="#document-not-found-404"
199219
<!-- Custom JS scripts -->
200220

201221

222+
202223
</div>
203224
</body>
204225
</html>

advanced-network.html

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,23 @@
3737
const path_to_root = "";
3838
const default_light_theme = "light";
3939
const default_dark_theme = "navy";
40+
window.path_to_searchindex_js = "searchindex.js";
4041
</script>
4142
<!-- Start loading toc.js asap -->
4243
<script src="toc.js"></script>
4344
</head>
4445
<body>
46+
<div id="mdbook-help-container">
47+
<div id="mdbook-help-popup">
48+
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
49+
<div>
50+
<p>Press <kbd></kbd> or <kbd></kbd> to navigate between chapters</p>
51+
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
52+
<p>Press <kbd>?</kbd> to show this help</p>
53+
<p>Press <kbd>Esc</kbd> to hide this help</p>
54+
</div>
55+
</div>
56+
</div>
4557
<div id="body-container">
4658
<!-- Work around some values being stored in localStorage wrapped in quotes -->
4759
<script>
@@ -82,10 +94,13 @@
8294
sidebar = sidebar || 'visible';
8395
} else {
8496
sidebar = 'hidden';
97+
sidebar_toggle.checked = false;
98+
}
99+
if (sidebar === 'visible') {
100+
sidebar_toggle.checked = true;
101+
} else {
102+
html.classList.remove('sidebar-visible');
85103
}
86-
sidebar_toggle.checked = sidebar === 'visible';
87-
html.classList.remove('sidebar-visible');
88-
html.classList.add("sidebar-" + sidebar);
89104
</script>
90105

91106
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
@@ -119,7 +134,7 @@
119134
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
120135
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
121136
</ul>
122-
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
137+
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
123138
<i class="fa fa-search"></i>
124139
</button>
125140
</div>
@@ -139,7 +154,12 @@ <h1 class="menu-title">microvm.nix</h1>
139154

140155
<div id="search-wrapper" class="hidden">
141156
<form id="searchbar-outer" class="searchbar-outer">
142-
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
157+
<div class="search-wrapper">
158+
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
159+
<div class="spinner-wrapper">
160+
<i class="fa fa-spinner fa-spin"></i>
161+
</div>
162+
</div>
143163
</form>
144164
<div id="searchresults-outer" class="searchresults-outer hidden">
145165
<div id="searchresults-header" class="searchresults-header"></div>
@@ -298,6 +318,7 @@ <h2 id="port-forwarding"><a class="header" href="#port-forwarding">Port forwardi
298318
<!-- Custom JS scripts -->
299319

300320

321+
301322
</div>
302323
</body>
303324
</html>

book.js

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -515,17 +515,39 @@ aria-label="Show hidden lines"></button>';
515515
})();
516516

517517
(function sidebar() {
518-
const body = document.querySelector('body');
519518
const sidebar = document.getElementById('sidebar');
520519
const sidebarLinks = document.querySelectorAll('#sidebar a');
521520
const sidebarToggleButton = document.getElementById('sidebar-toggle');
522-
const sidebarToggleAnchor = document.getElementById('sidebar-toggle-anchor');
523521
const sidebarResizeHandle = document.getElementById('sidebar-resize-handle');
522+
const sidebarCheckbox = document.getElementById('sidebar-toggle-anchor');
524523
let firstContact = null;
525524

525+
526+
/* Because we cannot change the `display` using only CSS after/before the transition, we
527+
need JS to do it. We change the display to prevent the browsers search to find text inside
528+
the collapsed sidebar. */
529+
if (!document.documentElement.classList.contains('sidebar-visible')) {
530+
sidebar.style.display = 'none';
531+
}
532+
sidebar.addEventListener('transitionend', () => {
533+
/* We only change the display to "none" if we're collapsing the sidebar. */
534+
if (!sidebarCheckbox.checked) {
535+
sidebar.style.display = 'none';
536+
}
537+
});
538+
sidebarToggleButton.addEventListener('click', () => {
539+
/* To allow the sidebar expansion animation, we first need to put back the display. */
540+
if (!sidebarCheckbox.checked) {
541+
sidebar.style.display = '';
542+
// Workaround for Safari skipping the animation when changing
543+
// `display` and a transform in the same event loop. This forces a
544+
// reflow after updating the display.
545+
sidebar.offsetHeight;
546+
}
547+
});
548+
526549
function showSidebar() {
527-
body.classList.remove('sidebar-hidden');
528-
body.classList.add('sidebar-visible');
550+
document.documentElement.classList.add('sidebar-visible');
529551
Array.from(sidebarLinks).forEach(function(link) {
530552
link.setAttribute('tabIndex', 0);
531553
});
@@ -539,8 +561,7 @@ aria-label="Show hidden lines"></button>';
539561
}
540562

541563
function hideSidebar() {
542-
body.classList.remove('sidebar-visible');
543-
body.classList.add('sidebar-hidden');
564+
document.documentElement.classList.remove('sidebar-visible');
544565
Array.from(sidebarLinks).forEach(function(link) {
545566
link.setAttribute('tabIndex', -1);
546567
});
@@ -554,8 +575,8 @@ aria-label="Show hidden lines"></button>';
554575
}
555576

556577
// Toggle sidebar
557-
sidebarToggleAnchor.addEventListener('change', function sidebarToggle() {
558-
if (sidebarToggleAnchor.checked) {
578+
sidebarCheckbox.addEventListener('change', function sidebarToggle() {
579+
if (sidebarCheckbox.checked) {
559580
const current_width = parseInt(
560581
document.documentElement.style.getPropertyValue('--sidebar-target-width'), 10);
561582
if (current_width < 150) {
@@ -572,14 +593,14 @@ aria-label="Show hidden lines"></button>';
572593
function initResize() {
573594
window.addEventListener('mousemove', resize, false);
574595
window.addEventListener('mouseup', stopResize, false);
575-
body.classList.add('sidebar-resizing');
596+
document.documentElement.classList.add('sidebar-resizing');
576597
}
577598
function resize(e) {
578599
let pos = e.clientX - sidebar.offsetLeft;
579600
if (pos < 20) {
580601
hideSidebar();
581602
} else {
582-
if (body.classList.contains('sidebar-hidden')) {
603+
if (!document.documentElement.classList.contains('sidebar-visible')) {
583604
showSidebar();
584605
}
585606
pos = Math.min(pos, window.innerWidth - 100);
@@ -588,7 +609,7 @@ aria-label="Show hidden lines"></button>';
588609
}
589610
//on mouseup remove windows functions mousemove & mouseup
590611
function stopResize() {
591-
body.classList.remove('sidebar-resizing');
612+
document.documentElement.classList.remove('sidebar-resizing');
592613
window.removeEventListener('mousemove', resize, false);
593614
window.removeEventListener('mouseup', stopResize, false);
594615
}
@@ -623,7 +644,7 @@ aria-label="Show hidden lines"></button>';
623644

624645
(function chapterNavigation() {
625646
document.addEventListener('keydown', function(e) {
626-
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
647+
if (e.altKey || e.ctrlKey || e.metaKey) {
627648
return;
628649
}
629650
if (window.search && window.search.hasFocus()) {
@@ -643,6 +664,55 @@ aria-label="Show hidden lines"></button>';
643664
window.location.href = previousButton.href;
644665
}
645666
}
667+
function showHelp() {
668+
const container = document.getElementById('mdbook-help-container');
669+
const overlay = document.getElementById('mdbook-help-popup');
670+
container.style.display = 'flex';
671+
672+
// Clicking outside the popup will dismiss it.
673+
const mouseHandler = event => {
674+
if (overlay.contains(event.target)) {
675+
return;
676+
}
677+
if (event.button !== 0) {
678+
return;
679+
}
680+
event.preventDefault();
681+
event.stopPropagation();
682+
document.removeEventListener('mousedown', mouseHandler);
683+
hideHelp();
684+
};
685+
686+
// Pressing esc will dismiss the popup.
687+
const escapeKeyHandler = event => {
688+
if (event.key === 'Escape') {
689+
event.preventDefault();
690+
event.stopPropagation();
691+
document.removeEventListener('keydown', escapeKeyHandler, true);
692+
hideHelp();
693+
}
694+
};
695+
document.addEventListener('keydown', escapeKeyHandler, true);
696+
document.getElementById('mdbook-help-container')
697+
.addEventListener('mousedown', mouseHandler);
698+
}
699+
function hideHelp() {
700+
document.getElementById('mdbook-help-container').style.display = 'none';
701+
}
702+
703+
// Usually needs the Shift key to be pressed
704+
switch (e.key) {
705+
case '?':
706+
e.preventDefault();
707+
showHelp();
708+
break;
709+
}
710+
711+
// Rest of the keys are only active when the Shift key is not pressed
712+
if (e.shiftKey) {
713+
return;
714+
}
715+
646716
switch (e.key) {
647717
case 'ArrowRight':
648718
e.preventDefault();
@@ -716,7 +786,7 @@ aria-label="Show hidden lines"></button>';
716786
let scrollTop = document.scrollingElement.scrollTop;
717787
let prevScrollTop = scrollTop;
718788
const minMenuY = -menu.clientHeight - 50;
719-
// When the script loads, the page can be at any scroll (e.g. if you reforesh it).
789+
// When the script loads, the page can be at any scroll (e.g. if you refresh it).
720790
menu.style.top = scrollTop + 'px';
721791
// Same as parseInt(menu.style.top.slice(0, -2), but faster
722792
let topCache = menu.style.top.slice(0, -2);

conventions.html

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,23 @@
3737
const path_to_root = "";
3838
const default_light_theme = "light";
3939
const default_dark_theme = "navy";
40+
window.path_to_searchindex_js = "searchindex.js";
4041
</script>
4142
<!-- Start loading toc.js asap -->
4243
<script src="toc.js"></script>
4344
</head>
4445
<body>
46+
<div id="mdbook-help-container">
47+
<div id="mdbook-help-popup">
48+
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
49+
<div>
50+
<p>Press <kbd></kbd> or <kbd></kbd> to navigate between chapters</p>
51+
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
52+
<p>Press <kbd>?</kbd> to show this help</p>
53+
<p>Press <kbd>Esc</kbd> to hide this help</p>
54+
</div>
55+
</div>
56+
</div>
4557
<div id="body-container">
4658
<!-- Work around some values being stored in localStorage wrapped in quotes -->
4759
<script>
@@ -82,10 +94,13 @@
8294
sidebar = sidebar || 'visible';
8395
} else {
8496
sidebar = 'hidden';
97+
sidebar_toggle.checked = false;
98+
}
99+
if (sidebar === 'visible') {
100+
sidebar_toggle.checked = true;
101+
} else {
102+
html.classList.remove('sidebar-visible');
85103
}
86-
sidebar_toggle.checked = sidebar === 'visible';
87-
html.classList.remove('sidebar-visible');
88-
html.classList.add("sidebar-" + sidebar);
89104
</script>
90105

91106
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
@@ -119,7 +134,7 @@
119134
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
120135
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
121136
</ul>
122-
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
137+
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
123138
<i class="fa fa-search"></i>
124139
</button>
125140
</div>
@@ -139,7 +154,12 @@ <h1 class="menu-title">microvm.nix</h1>
139154

140155
<div id="search-wrapper" class="hidden">
141156
<form id="searchbar-outer" class="searchbar-outer">
142-
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
157+
<div class="search-wrapper">
158+
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
159+
<div class="spinner-wrapper">
160+
<i class="fa fa-spinner fa-spin"></i>
161+
</div>
162+
</div>
143163
</form>
144164
<div id="searchresults-outer" class="searchresults-outer hidden">
145165
<div id="searchresults-header" class="searchresults-header"></div>
@@ -241,6 +261,7 @@ <h2 id="generating-custom-operating-system-hypervisor-packages"><a class="header
241261
<!-- Custom JS scripts -->
242262

243263

264+
244265
</div>
245266
</body>
246267
</html>

0 commit comments

Comments
 (0)