Skip to content

Commit e8352bb

Browse files
committed
allow backwards navigation too
1 parent ab71cda commit e8352bb

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

templates/base.html

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<body id="root" class="safe-h-screen">
5353
{% include "theme-switch.html" %}
5454

55-
<div class="flex h-[100%]" id="portal">
55+
<div class="flex h-[100%]">
5656
<div class="left-bar pl-3 hidden md:block h-[100%] shadow-md dark:shadow-xl" id="left-bar">
5757
<div class="flex flex-row">
5858
<div class="flex flex-col justify-center">
@@ -63,7 +63,7 @@
6363
<input data-stork="ref-search" class="text-input flex-grow m-2 pr-2" type="text" placeholder="Search" />
6464
</div>
6565
<div data-stork="ref-search-output" class="results"></div>
66-
<nav role="navigation" class="pr-2">
66+
<nav role="navigation" id="navbar" class="pr-2">
6767
<ul>
6868
{%- block menu -%}
6969
{%- set index = get_section(path="_index.md", metadata_only=true) -%}
@@ -76,7 +76,7 @@
7676
</nav>
7777
</div>
7878

79-
<section class="section">
79+
<section class="section" id="portal">
8080
<div class="mt-5 mx-5">
8181
<div class="flex flex-col gap-5 border-b-2 border-lightborder dark:border-darkborder pb-2 mb-3">
8282
<div class="flex flex-col-reverse gap-5 md:flex-row justify-between">
@@ -137,38 +137,47 @@
137137
const doc = parser.parseFromString(await fetched.text(), "text/html");
138138

139139
const content = doc.getElementById("portal");
140+
const navbar = doc.getElementById("navbar");
140141

141-
if(pre) preFetched[link] = content;
142-
return content;
142+
if(pre) preFetched[link] = {content: content, navbar: navbar};
143+
return {content: content, navbar: navbar};
143144
}
144145

145-
const buttonInterceptor = async (ev) => {
146-
if(!ev.target.href) return;
147-
148-
ev.preventDefault();
149-
146+
const navTo = async(link) => {
150147
const portal = document.getElementById("portal");
151-
const potentialFetch = preFetched[ev.target.href];
148+
const navbar = document.getElementById("navbar");
149+
150+
const potentialFetch = preFetched[link];
152151

153152
if(potentialFetch) {
154-
portal.replaceChildren(...potentialFetch.children);
153+
portal.replaceChildren(...potentialFetch.content.children);
154+
navbar.replaceChildren(...potentialFetch.navbar.children)
155155
} else {
156-
const newContents = await fetchLink(ev.target.href);
156+
const newContents = await fetchLink(link);
157157

158158
if(!newContents) {
159159
return;
160160
}
161161

162-
portal.replaceChildren(...newContents.children);
162+
portal.replaceChildren(...newContents.content.children);
163+
navbar.replaceChildren(...newContents.navbar.children)
163164
}
164165

165-
delete preFetched[ev.target.href];
166+
delete preFetched[link];
166167

167-
history.pushState(null, "", ev.target.href);
168+
history.pushState(true, "", link);
168169

169170
prefetchLinks();
170171
}
171172

173+
const buttonInterceptor = async (ev) => {
174+
if(!ev.target.href) return;
175+
176+
ev.preventDefault();
177+
178+
navTo(ev.target.href);
179+
}
180+
172181
const hoverInterceptor = (ev) => {
173182
if(!ev.target.href) return;
174183

@@ -186,6 +195,10 @@
186195
}
187196
}
188197

198+
window.addEventListener("popstate", (pop) => {
199+
navTo(location.href);
200+
})
201+
189202
prefetchLinks();
190203
</script>
191204
</body>

0 commit comments

Comments
 (0)