freddie 0.0.82 → 0.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/web/app.js +17 -3
package/package.json
CHANGED
package/src/web/app.js
CHANGED
|
@@ -11,7 +11,12 @@ root.textContent = 'loading…';
|
|
|
11
11
|
const host0 = await fetchHost();
|
|
12
12
|
root.innerHTML = '';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
function routeFromHash() {
|
|
15
|
+
const m = String(location.hash || '').match(/^#(?:fd-)?([a-z]+)/i);
|
|
16
|
+
const p = m && m[1];
|
|
17
|
+
return ROUTES.find(r => r.path === p) ? p : 'home';
|
|
18
|
+
}
|
|
19
|
+
const state = { active: routeFromHash(), ts: new Date().toLocaleTimeString(), body: null, error: null };
|
|
15
20
|
|
|
16
21
|
function buildSide() {
|
|
17
22
|
return Side({ sections: [{ group: 'freddie', items: ROUTES.map(r => ({
|
|
@@ -36,8 +41,17 @@ function view() {
|
|
|
36
41
|
|
|
37
42
|
function rerender() { applyDiff(root, view()); }
|
|
38
43
|
|
|
39
|
-
function setActive(p) {
|
|
40
|
-
if (
|
|
44
|
+
function setActive(p) {
|
|
45
|
+
if (state.active === p) return;
|
|
46
|
+
state.active = p; state.body = null;
|
|
47
|
+
const want = '#fd-' + p;
|
|
48
|
+
if (location.hash !== want) { try { history.replaceState(null, '', want); } catch { location.hash = want; } }
|
|
49
|
+
rerender(); loadActive();
|
|
50
|
+
}
|
|
51
|
+
if (typeof window !== 'undefined') {
|
|
52
|
+
window.__fd_nav = setActive;
|
|
53
|
+
window.addEventListener('hashchange', () => setActive(routeFromHash()));
|
|
54
|
+
}
|
|
41
55
|
|
|
42
56
|
async function loadActive() {
|
|
43
57
|
const active = state.active;
|