Skip to content

Commit 8f6f7e5

Browse files
committed
Add navigation class to manage menu
1 parent a698402 commit 8f6f7e5

File tree

3 files changed

+112
-44
lines changed

3 files changed

+112
-44
lines changed

components/tenfoot_layout.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ html(lang="en")
3636
p.frit-fit #fritfit (for real)
3737

3838
+scripts
39-
script(type="module" src="/scripts/tenfoot/menu.ts")
39+
script(type="module" src="/scripts/tenfoot/tenfoot-navigation.ts")
4040
block scripts

scripts/tenfoot/menu.ts

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
// Keyboard navigation for 10-foot interface
2-
32
interface ServiceSelected {
43
service: string;
54
}
65

7-
class TenFootMenuNavigator {
6+
export interface GotoPage {
7+
navigateTo(page: string): Promise<void>;
8+
}
9+
10+
export class TenFootMenu {
811
private cards: NodeListOf<HTMLElement>;
12+
private navigator: GotoPage;
913
private currentIndex: number;
1014

11-
constructor(cardContainer: Element) {
15+
constructor(navigator: GotoPage, cardContainer: Element) {
16+
this.navigator = navigator;
1217
this.cards = cardContainer.querySelectorAll<HTMLElement>('.menu10foot-card');
1318
this.currentIndex = 0;
1419
this.init();
1520
}
1621

1722
private init(): void {
23+
console.log("Initialized Tenfoot Menu");
1824
this.setupKeyboardNavigation();
1925
this.setupClickHandlers();
20-
this.handleLoading();
2126

2227
// Focus first card on load
2328
if (this.cards.length > 0) {
@@ -69,7 +74,7 @@ class TenFootMenuNavigator {
6974
document.dispatchEvent(event);
7075

7176
// Add your navigation logic here
72-
// Example: window.location.href = `/service/${service}`;
77+
// navigator.navigateTo("links").then(r => console.log(r));
7378
});
7479

7580
card.addEventListener('focus', () => {
@@ -83,42 +88,4 @@ class TenFootMenuNavigator {
8388
});
8489
});
8590
}
86-
87-
private handleLoading(): void {
88-
const loadingIndicator = document.getElementById('loading-indicator');
89-
90-
if (loadingIndicator) {
91-
window.addEventListener('load', () => {
92-
setTimeout(() => {
93-
loadingIndicator.style.display = 'none';
94-
}, 1500);
95-
});
96-
}
97-
}
98-
99-
public async LoadPage(path: string) {
100-
const app = document.getElementsByTagName('section')[0]
101-
102-
try {
103-
const response = await fetch(`/${path}.html`);
104-
const html = await response.text();
105-
app.innerHTML = html;
106-
} catch (error) {
107-
app.innerHTML = '<p>Page not found</p>';
108-
}
109-
}
11091
}
111-
112-
const initMenu = () => {
113-
const menuContainer = document.getElementsByClassName('menu10foot')[0];
114-
let nav = new TenFootMenuNavigator(menuContainer);
115-
};
116-
117-
if (document.readyState === 'loading') {
118-
document.addEventListener('DOMContentLoaded', initMenu);
119-
} else {
120-
initMenu();
121-
}
122-
123-
// nav.LoadPage("links").then(r => console.log(r));
124-
export default TenFootMenuNavigator;
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Keyboard navigation for 10-foot interface
2+
3+
import {TenFootMenu, GotoPage} from "./menu";
4+
5+
class TenFootNavigator implements GotoPage {
6+
private currentPage: string;
7+
8+
constructor() {
9+
this.init();
10+
}
11+
12+
private init(): void {
13+
console.log("Loaded Tenfoot-navigation");
14+
15+
this.inputOverride();
16+
this.handleLoading();
17+
this.TryInstantiateMenu();
18+
}
19+
20+
private inputOverride(): void {
21+
document.addEventListener('keydown', (e: KeyboardEvent) => {
22+
switch(e.key) {
23+
case 'Enter':
24+
break;
25+
case 'Escape':
26+
case 'BrowserBack':
27+
e.preventDefault();
28+
break;
29+
case 'MediaPlayPause':
30+
break;
31+
case 'MediaPlay':
32+
break;
33+
case 'MediaPause':
34+
break;
35+
case 'MediaStop':
36+
break;
37+
case 'MediaTrackNext':
38+
break;
39+
case 'MediaTrackPrevious':
40+
break;
41+
}
42+
});
43+
}
44+
45+
private handleLoading(): void {
46+
const loadingIndicator = document.getElementById('loading-indicator');
47+
48+
if (loadingIndicator) {
49+
window.addEventListener('load', () => {
50+
setTimeout(() => {
51+
loadingIndicator.style.display = 'none';
52+
}, 1500);
53+
});
54+
}
55+
}
56+
57+
async navigateTo(page: string): Promise<void> {
58+
await this.LoadPage(page);
59+
}
60+
61+
async LoadPage(path: string) {
62+
const app = document.getElementsByTagName('section')[0]
63+
64+
try {
65+
const response = await fetch(`/${path}.html`);
66+
const html = await response.text();
67+
app.innerHTML = html;
68+
69+
this.TryInstantiateMenu();
70+
} catch (error) {
71+
app.innerHTML = '<p>Page not found</p>';
72+
}
73+
}
74+
75+
TryInstantiateMenu(){
76+
// Try load 10foot-menu handler
77+
const initMenu = () => {
78+
const menuContainer = document.getElementsByClassName('menu10foot')[0];
79+
let nav = new TenFootMenu(this, menuContainer);
80+
};
81+
82+
// TODO: mby doesn't work for loading subpages
83+
if (document.readyState === 'loading') {
84+
document.addEventListener('DOMContentLoaded', initMenu);
85+
} else {
86+
initMenu();
87+
}
88+
}
89+
}
90+
91+
const initNavigation = () => {
92+
let nav = new TenFootNavigator();
93+
};
94+
95+
if (document.readyState === 'loading') {
96+
document.addEventListener('DOMContentLoaded', initNavigation);
97+
} else {
98+
initNavigation();
99+
}
100+
101+
export default TenFootNavigator;

0 commit comments

Comments
 (0)