Skip to content

Commit 64ce81b

Browse files
committed
update mdbook
1 parent 4b7edf8 commit 64ce81b

26 files changed

+582
-109
lines changed

1hlp22/c/404.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,22 @@ <h1 id="document-not-found-404"><a class="header" href="#document-not-found-404"
210210

211211
</div>
212212

213+
<!-- Livereload script (if served using the cli tool) -->
214+
<script>
215+
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
216+
const wsAddress = wsProtocol + "//" + location.host + "/" + "__livereload";
217+
const socket = new WebSocket(wsAddress);
218+
socket.onmessage = function (event) {
219+
if (event.data === "reload") {
220+
socket.close();
221+
location.reload();
222+
}
223+
};
224+
225+
window.onbeforeunload = function() {
226+
socket.close();
227+
}
228+
</script>
213229

214230

215231

1hlp22/c/book.js

Lines changed: 86 additions & 16 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,12 +575,12 @@ 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(
560-
document.documentElement.style.getPropertyValue('--sidebar-width'), 10);
581+
document.documentElement.style.getPropertyValue('--sidebar-target-width'), 10);
561582
if (current_width < 150) {
562-
document.documentElement.style.setProperty('--sidebar-width', '150px');
583+
document.documentElement.style.setProperty('--sidebar-target-width', '150px');
563584
}
564585
showSidebar();
565586
} else {
@@ -572,23 +593,23 @@ 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);
586-
document.documentElement.style.setProperty('--sidebar-width', pos + 'px');
607+
document.documentElement.style.setProperty('--sidebar-target-width', pos + 'px');
587608
}
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);

1hlp22/c/css/chrome.css

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,34 @@ mark.fade-out {
344344
max-width: var(--content-max-width);
345345
}
346346

347+
#searchbar-outer.searching #searchbar {
348+
padding-right: 30px;
349+
}
350+
#searchbar-outer .spinner-wrapper {
351+
display: none;
352+
}
353+
#searchbar-outer.searching .spinner-wrapper {
354+
display: block;
355+
}
356+
357+
.search-wrapper {
358+
position: relative;
359+
}
360+
361+
.spinner-wrapper {
362+
--spinner-margin: 2px;
363+
position: absolute;
364+
margin-block-start: calc(var(--searchbar-margin-block-start) + var(--spinner-margin));
365+
right: var(--spinner-margin);
366+
top: 0;
367+
bottom: var(--spinner-margin);
368+
padding: 6px;
369+
background-color: var(--bg);
370+
}
371+
347372
#searchbar {
348373
width: 100%;
349-
margin-block-start: 5px;
374+
margin-block-start: var(--searchbar-margin-block-start);
350375
margin-block-end: 0;
351376
margin-inline-start: auto;
352377
margin-inline-end: auto;
@@ -474,9 +499,24 @@ html:not(.sidebar-resizing) .sidebar {
474499

475500
.sidebar-resize-handle .sidebar-resize-indicator {
476501
width: 100%;
477-
height: 12px;
478-
background-color: var(--icons);
502+
height: 16px;
503+
color: var(--icons);
479504
margin-inline-start: var(--sidebar-resize-indicator-space);
505+
display: flex;
506+
align-items: center;
507+
justify-content: flex-start;
508+
}
509+
.sidebar-resize-handle .sidebar-resize-indicator::before {
510+
content: "";
511+
width: 2px;
512+
height: 12px;
513+
border-left: dotted 2px currentColor;
514+
}
515+
.sidebar-resize-handle .sidebar-resize-indicator::after {
516+
content: "";
517+
width: 2px;
518+
height: 16px;
519+
border-left: dotted 2px currentColor;
480520
}
481521

482522
[dir=rtl] .sidebar .sidebar-resize-handle {
@@ -490,7 +530,6 @@ html:not(.sidebar-resizing) .sidebar {
490530
/* sidebar-hidden */
491531
#sidebar-toggle-anchor:not(:checked) ~ .sidebar {
492532
transform: translateX(calc(0px - var(--sidebar-width) - var(--sidebar-resize-indicator-width)));
493-
z-index: -1;
494533
}
495534
[dir=rtl] #sidebar-toggle-anchor:not(:checked) ~ .sidebar {
496535
transform: translateX(calc(var(--sidebar-width) + var(--sidebar-resize-indicator-width)));
@@ -641,3 +680,46 @@ html:not(.sidebar-resizing) .sidebar {
641680
margin-inline-start: -14px;
642681
width: 14px;
643682
}
683+
684+
/* The container for the help popup that covers the whole window. */
685+
#mdbook-help-container {
686+
/* Position and size for the whole window. */
687+
position: fixed;
688+
top: 0;
689+
left: 0;
690+
right: 0;
691+
bottom: 0;
692+
/* This uses flex layout (which is set in book.js), and centers the popup
693+
in the window.*/
694+
display: none;
695+
align-items: center;
696+
justify-content: center;
697+
z-index: 1000;
698+
/* Dim out the book while the popup is visible. */
699+
background: var(--overlay-bg);
700+
}
701+
702+
/* The popup help box. */
703+
#mdbook-help-popup {
704+
box-shadow: 0 4px 24px rgba(0,0,0,0.15);
705+
min-width: 300px;
706+
max-width: 500px;
707+
width: 100%;
708+
box-sizing: border-box;
709+
display: flex;
710+
flex-direction: column;
711+
align-items: center;
712+
background-color: var(--bg);
713+
color: var(--fg);
714+
border-width: 1px;
715+
border-color: var(--theme-popup-border);
716+
border-style: solid;
717+
border-radius: 8px;
718+
padding: 10px;
719+
}
720+
721+
.mdbook-help-title {
722+
text-align: center;
723+
/* mdbook's margin for h2 is way too large. */
724+
margin: 10px;
725+
}

1hlp22/c/css/general.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ h6:target::before {
8686
box-sizing: border-box;
8787
background-color: var(--bg);
8888
}
89-
.no-js .page-wrapper,
89+
html:not(.js) .page-wrapper,
9090
.js:not(.sidebar-resizing) .page-wrapper {
9191
transition: margin-left 0.3s ease, transform 0.3s ease; /* Animation: slide away */
9292
}
93-
[dir=rtl] .js:not(.sidebar-resizing) .page-wrapper {
93+
[dir=rtl]:not(.js) .page-wrapper,
94+
[dir=rtl].js:not(.sidebar-resizing) .page-wrapper {
9495
transition: margin-right 0.3s ease, transform 0.3s ease; /* Animation: slide away */
9596
}
9697

1hlp22/c/css/variables.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
/* Globals */
33

44
:root {
5-
--sidebar-width: 300px;
5+
--sidebar-target-width: 300px;
6+
--sidebar-width: min(var(--sidebar-target-width), 80vw);
67
--sidebar-resize-indicator-width: 8px;
78
--sidebar-resize-indicator-space: 2px;
89
--page-padding: 15px;
910
--content-max-width: 750px;
1011
--menu-bar-height: 50px;
1112
--mono-font: "Source Code Pro", Consolas, "Ubuntu Mono", Menlo, "DejaVu Sans Mono", monospace, monospace;
1213
--code-font-size: 0.875em; /* please adjust the ace font size accordingly in editor.js */
14+
--searchbar-margin-block-start: 5px;
1315
}
1416

1517
/* Themes */
@@ -63,6 +65,8 @@
6365
--copy-button-filter-hover: invert(68%) sepia(55%) saturate(531%) hue-rotate(341deg) brightness(104%) contrast(101%);
6466

6567
--footnote-highlight: #2668a6;
68+
69+
--overlay-bg: rgba(33, 40, 48, 0.4);
6670
}
6771

6872
.coal {
@@ -114,6 +118,8 @@
114118
--copy-button-filter-hover: invert(36%) sepia(70%) saturate(503%) hue-rotate(167deg) brightness(98%) contrast(89%);
115119

116120
--footnote-highlight: #4079ae;
121+
122+
--overlay-bg: rgba(33, 40, 48, 0.4);
117123
}
118124

119125
.light, html:not(.js) {
@@ -165,6 +171,8 @@
165171
--copy-button-filter-hover: invert(14%) sepia(93%) saturate(4250%) hue-rotate(243deg) brightness(99%) contrast(130%);
166172

167173
--footnote-highlight: #7e7eff;
174+
175+
--overlay-bg: rgba(200, 200, 205, 0.4);
168176
}
169177

170178
.navy {
@@ -216,6 +224,8 @@
216224
--copy-button-filter-hover: invert(46%) sepia(20%) saturate(1537%) hue-rotate(156deg) brightness(85%) contrast(90%);
217225

218226
--footnote-highlight: #4079ae;
227+
228+
--overlay-bg: rgba(33, 40, 48, 0.4);
219229
}
220230

221231
.rust {
@@ -265,6 +275,8 @@
265275
--copy-button-filter-hover: invert(77%) sepia(16%) saturate(1798%) hue-rotate(328deg) brightness(98%) contrast(83%);
266276

267277
--footnote-highlight: #d3a17a;
278+
279+
--overlay-bg: rgba(150, 150, 150, 0.25);
268280
}
269281

270282
@media (prefers-color-scheme: dark) {

0 commit comments

Comments
 (0)