Skip to content

Commit 9334380

Browse files
committed
deploy: 5869cae
1 parent 5b3751e commit 9334380

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

_sidebar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ const FoldableItem = ({ config, outputPath, sidebarItem: { text, link, children
3838
setFold(!fold);
3939
}
4040
else {
41-
setFold(false);
4241
// @ts-ignore
4342
document.documentElement.classList.remove('show_sidebar');
43+
setFold(false);
4444
}
4545
}
4646
else {

assets/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ table th {
443443
header > h1 {
444444
display: none;
445445
}
446+
.show_sidebar body {
447+
overflow-y: hidden;
448+
}
446449
.sidebar {
447450
transform: translateX(-100%);
448451
transition: transform var(--transition-duration);

index.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@ let lastPathname = null;
33
let lastLayout = null;
44
let lastProps = null;
55

6+
async function clickHandler(e) {
7+
const { origin, pathname } = e.target;
8+
if (typeof pathname !== 'string') return;
9+
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
10+
if (origin !== location.origin) return;
11+
await rerender(e.target, {
12+
preventDefault: () => e.preventDefault(),
13+
pushState: () => window.history.pushState({}, '', e.target.href)
14+
});
15+
}
16+
17+
function popstateHandler() {
18+
rerender(location);
19+
}
20+
621
async function main() {
722
rerender(location, { isHydrate: true });
823

9-
document.addEventListener('click', async (e) => {
10-
const { origin, pathname } = e.target;
11-
if (typeof pathname !== 'string') return;
12-
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
13-
if (origin !== location.origin) return;
14-
await rerender(e.target, {
15-
preventDefault: () => e.preventDefault(),
16-
pushState: () => window.history.pushState({}, '', e.target.href)
17-
});
18-
});
19-
20-
window.addEventListener('popstate', () => rerender(location));
24+
document.addEventListener('click', clickHandler);
25+
window.addEventListener('popstate', popstateHandler);
2126
}
2227

2328
async function rerender(
@@ -71,4 +76,12 @@ async function rerender(
7176
loading = false;
7277
}
7378

74-
main();
79+
try {
80+
main();
81+
} catch (e) {
82+
console.error(e);
83+
console.log('Error occured, disable spa');
84+
85+
document.removeEventListener('click', clickHandler);
86+
window.removeEventListener('popstate', popstateHandler);
87+
}

0 commit comments

Comments
 (0)