Skip to content

Commit d69d56b

Browse files
authored
Merge pull request #1266 from eed3si9n/wip/update-theme
Update theme
2 parents 050571c + d69f540 commit d69d56b

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

theme/index.hbs

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE HTML>
2-
<html lang="{{ language }}" class="{{ default_theme }}" dir="{{ text_direction }}">
2+
<html lang="{{ language }}" class="{{ default_theme }} sidebar-visible" dir="{{ text_direction }}">
33
<head>
44
<!-- Book generated using mdBook -->
55
<meta charset="UTF-8">
@@ -52,17 +52,19 @@
5252
<!-- MathJax -->
5353
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
5454
{{/if}}
55-
</head>
56-
<body class="sidebar-visible no-js">
57-
<div id="body-container">
55+
5856
<!-- Provide site root to javascript -->
5957
<script>
6058
var path_to_root = "{{ path_to_root }}";
6159
// This forces users into dark theme
6260
// var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "{{ preferred_dark_theme }}" : "{{ default_theme }}";
6361
var default_theme = "{{ default_theme }}";
6462
</script>
65-
63+
<!-- Start loading toc.js asap -->
64+
<script src="{{ path_to_root }}toc.js"></script>
65+
</head>
66+
<body>
67+
<div id="body-container">
6668
<!-- Work around some values being stored in localStorage wrapped in quotes -->
6769
<script>
6870
try {
@@ -84,19 +86,16 @@
8486
var theme;
8587
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
8688
if (theme === null || theme === undefined) { theme = default_theme; }
87-
var html = document.querySelector('html');
89+
const html = document.documentElement;
8890
html.classList.remove('{{ default_theme }}')
8991
html.classList.add(theme);
90-
var body = document.querySelector('body');
91-
body.classList.remove('no-js')
92-
body.classList.add('js');
92+
html.classList.add("js");
9393
</script>
9494

9595
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
9696

9797
<!-- Hide / unhide sidebar before it is displayed -->
9898
<script>
99-
var body = document.querySelector('body');
10099
var sidebar = null;
101100
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
102101
if (document.body.clientWidth >= 1080) {
@@ -106,41 +105,21 @@
106105
sidebar = 'hidden';
107106
}
108107
sidebar_toggle.checked = sidebar === 'visible';
109-
body.classList.remove('sidebar-visible');
110-
body.classList.add("sidebar-" + sidebar);
108+
html.classList.remove('sidebar-visible');
109+
html.classList.add("sidebar-" + sidebar);
111110
</script>
112111

113112
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
114-
<div class="sidebar-scrollbox">
115-
{{#toc}}{{/toc}}
116-
</div>
113+
<!-- populated by js -->
114+
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
115+
<noscript>
116+
<iframe class="sidebar-iframe-outer" src="{{ path_to_root }}toc.html"></iframe>
117+
</noscript>
117118
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
118119
<div class="sidebar-resize-indicator"></div>
119120
</div>
120121
</nav>
121122

122-
<!-- Track and set sidebar scroll position -->
123-
<script>
124-
var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
125-
sidebarScrollbox.addEventListener('click', function(e) {
126-
if (e.target.tagName === 'A') {
127-
sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
128-
}
129-
}, { passive: true });
130-
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
131-
sessionStorage.removeItem('sidebar-scroll');
132-
if (sidebarScrollTop) {
133-
// preserve sidebar scroll position when navigating via links within sidebar
134-
sidebarScrollbox.scrollTop = sidebarScrollTop;
135-
} else {
136-
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
137-
var activeSection = document.querySelector('#sidebar .active');
138-
if (activeSection) {
139-
activeSection.scrollIntoView({ block: 'center' });
140-
}
141-
}
142-
</script>
143-
144123
<div id="page-wrapper" class="page-wrapper">
145124

146125
<div class="page">

0 commit comments

Comments
 (0)