-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
885 lines (775 loc) · 31.6 KB
/
index.html
File metadata and controls
885 lines (775 loc) · 31.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="StratoLab - Educational STEM project for launching high-altitude balloons to the stratosphere">
<title>StratoLab - High Altitude Balloon STEM Project</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.min.js"></script>
</head>
<body>
<!-- Header -->
<header id="header">
<button id="hamburger" aria-label="Toggle navigation">☰</button>
<a href="#" id="logo-link" aria-label="Return to home">
<img src="assets/images/stratolab.svg" alt="StratoLab logo" id="logo">
<span id="logo-text">StratoLab</span>
</a>
<div id="search-container">
<input
id="search-input"
type="search"
placeholder="Search…"
autocomplete="off"
aria-label="Search documentation"
aria-haspopup="listbox"
aria-expanded="false"
aria-controls="search-results"
role="combobox"
>
<div id="search-results" role="listbox" aria-label="Search results" class="hidden"></div>
</div>
<a id="github-link"
href="https://github.com/StratoLab"
target="_blank"
rel="noopener noreferrer"
aria-label="StratoLab on GitHub"
title="StratoLab on GitHub">
<!-- Inline GitHub SVG mark, 20×20 -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="20" height="20" aria-hidden="true">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38
0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13
-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66
.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15
-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0
1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82
1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01
1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/>
</svg>
</a>
</header>
<!-- Sidebar -->
<aside id="sidebar">
<nav id="track-picker" aria-label="Track selection">
<button data-track="all" class="active">All</button>
<button data-track="pico">Pico</button>
<button data-track="arduino">Arduino</button>
<button data-track="esp32">ESP32</button>
</nav>
<nav id="nav-tree" aria-label="Site navigation">
<!-- Populated by JavaScript -->
</nav>
</aside>
<!-- Main Content -->
<main id="content">
<!-- Landing state or rendered lesson -->
</main>
<!-- Toast for "continue where you left off" -->
<div id="toast" class="hidden" role="alert">
<span id="toast-message"></span>
<button id="toast-continue">Continue</button>
<button id="toast-dismiss" aria-label="Dismiss">×</button>
</div>
<!-- Pinout FAB (Floating Action Button) -->
<button id="pinout-fab" class="hidden" aria-label="Show pinout diagram">
<img id="pinout-fab-image" src="" alt="Pinout" class="fab-image">
<span class="fab-label">Pinout</span>
</button>
<!-- Pinout Modal -->
<div id="pinout-modal" class="hidden" role="dialog" aria-modal="true" aria-labelledby="pinout-modal-title">
<div id="pinout-modal-backdrop"></div>
<div id="pinout-modal-content">
<div id="pinout-modal-header">
<h2 id="pinout-modal-title"></h2>
<button id="pinout-modal-close" aria-label="Close">×</button>
</div>
<div id="pinout-modal-body">
<img id="pinout-modal-image" src="" alt="">
</div>
</div>
</div>
<script>
// ===== State =====
let config = null;
let activeTrack = 'all';
let activeId = null;
let allItems = []; // Flat list of all navigable items for lookup
let searchIndex = [];
let activeSearchIndex = -1;
const contentStore = new Map(); // id → stripped plain text
// ===== Pinout Configuration =====
const pinoutConfig = {
pico: {
title: 'Raspberry Pi Pico Pinout',
thumbSrc: 'assets/images/pinouts/raspberry-pi-pico-pinout-thumb.png',
fullSrc: 'assets/images/pinouts/raspberry-pi-pico-pinout.png',
altText: 'Raspberry Pi Pico pinout diagram showing all GPIO pins, power pins, and their functions'
},
arduino: {
title: 'Arduino Uno Rev3 Pinout',
thumbSrc: 'assets/images/pinouts/arduino-uno-rev3-pinout-thumb.png',
fullSrc: 'assets/images/pinouts/arduino-uno-rev3-pinout.png',
altText: 'Arduino Uno Rev3 pinout diagram showing digital pins, analog pins, power pins, and their functions'
},
esp32: {
title: 'Heltec ESP32-S3 Tracker Pinout',
thumbSrc: 'assets/images/pinouts/esp32s3-pinout-thumb.png',
fullSrc: 'assets/images/pinouts/esp32s3-pinout.png',
altText: 'Heltec ESP32-S3 Tracker V1 pinout diagram showing GPIO pins, power pins, ADC/DAC, SPI, I2C, and LoRa connections'
}
};
// ===== Initialization =====
document.addEventListener('DOMContentLoaded', init);
async function init() {
try {
// 1. Fetch config
const response = await fetch('site-config.json');
if (!response.ok) {
throw new Error('Failed to load site configuration');
}
config = await response.json();
// 2. Build flat item lookup and search index
buildItemLookup();
buildSearchIndex();
// 3. Render sidebar
renderSidebar();
// 4. Setup event listeners
setupEventListeners();
initSearch();
// 5. Prefetch content for full-text search during idle time
scheduleContentPrefetch();
// 6. Handle initial state
if (window.location.hash) {
const id = window.location.hash.slice(1);
const item = findItemById(id);
if (item) {
loadContent(item.path, item.id, item.stub);
} else {
console.warn(`No item found for hash: ${id}`);
showLanding();
}
} else {
showLanding();
checkLastVisited(); // Show toast if applicable
}
} catch (error) {
console.error('Initialization error:', error);
showError('Failed to load site. Please refresh the page.');
}
}
// ===== Build flat lookup of all items =====
function buildItemLookup() {
allItems = [];
// Add shared items
config.shared.forEach(item => {
if (item.children) {
item.children.forEach(child => {
allItems.push(child);
});
} else {
allItems.push(item);
}
});
// Add track items
config.tracks.forEach(track => {
track.sections.forEach(section => {
allItems.push(section);
});
});
}
// ===== Build search index =====
function buildSearchIndex() {
searchIndex = [];
// Shared items
for (const item of config.shared || []) {
if (item.children) {
for (const child of item.children) {
if (child.path && !child.stub) {
searchIndex.push({ id: child.id, title: child.title, path: child.path, trackLabel: 'General' });
}
}
} else if (item.path && !item.stub) {
searchIndex.push({ id: item.id, title: item.title, path: item.path, trackLabel: 'General' });
}
}
// Track items
for (const track of config.tracks || []) {
for (const section of track.sections || []) {
if (section.path && !section.stub) {
searchIndex.push({ id: section.id, title: section.title, path: section.path, trackLabel: track.title });
}
}
}
}
// ===== Full-Text Content Prefetch =====
function scheduleContentPrefetch() {
if ('requestIdleCallback' in window) {
requestIdleCallback(() => prefetchContent(), { timeout: 5000 });
} else {
setTimeout(() => prefetchContent(), 2000);
}
}
async function prefetchContent() {
await Promise.all(searchIndex.map(async (item) => {
if (contentStore.has(item.id)) return;
try {
const res = await fetch(item.path);
if (!res.ok) return;
contentStore.set(item.id, stripMarkdown(await res.text()));
} catch (e) { /* silent */ }
}));
}
function stripMarkdown(md) {
return md
// Remove code fences (keep inner text for keyword matching)
.replace(/^```[^\n]*\n([\s\S]*?)^```/gm, '$1')
// Remove inline code backticks
.replace(/`([^`]+)`/g, '$1')
// Remove images
.replace(/!\[[^\]]*\]\([^)]*\)/g, '')
// Replace links with their label text
.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
// Remove heading markers
.replace(/^#{1,6}\s+/gm, '')
// Remove bold/italic markers
.replace(/\*{1,3}([^*\n]+)\*{1,3}/g, '$1')
.replace(/_{1,3}([^_\n]+)_{1,3}/g, '$1')
// Remove HTML tags
.replace(/<[^>]+>/g, ' ')
// Remove horizontal rules
.replace(/^[-*_]{3,}\s*$/gm, '')
// Collapse whitespace
.replace(/\n{3,}/g, '\n\n')
.trim();
}
function escapeHtml(str) {
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
}
function extractExcerpt(text, query) {
const lowerText = text.toLowerCase();
const q = query.trim().toLowerCase();
const matchIdx = lowerText.indexOf(q);
if (matchIdx === -1) return '';
const ctxStart = Math.max(0, matchIdx - 60);
const ctxEnd = Math.min(text.length, matchIdx + q.length + 60);
const pre = escapeHtml(text.slice(ctxStart, matchIdx));
const match = escapeHtml(text.slice(matchIdx, matchIdx + q.length));
const post = escapeHtml(text.slice(matchIdx + q.length, ctxEnd));
return (ctxStart > 0 ? '…' : '') + pre + '<mark>' + match + '</mark>' + post + (ctxEnd < text.length ? '…' : '');
}
// ===== Search =====
function searchItems(query) {
const q = query.trim().toLowerCase();
if (!q) return [];
// Title search
const titleResults = searchIndex
.map(item => {
const t = item.title.toLowerCase();
let score = 0;
if (t === q) score = 3;
else if (t.startsWith(q)) score = 2;
else if (t.includes(q)) score = 1;
return { ...item, score, excerpt: '' };
})
.filter(item => item.score > 0)
.sort((a, b) => b.score - a.score);
// Enrich title results with excerpts if content is available
titleResults.forEach(r => {
const text = contentStore.get(r.id);
if (text) r.excerpt = extractExcerpt(text, q);
});
// Content-only search for pages not already in title results
const titleIds = new Set(titleResults.map(r => r.id));
const contentResults = [];
if (contentStore.size > 0) {
for (const item of searchIndex) {
if (titleIds.has(item.id)) continue;
const text = contentStore.get(item.id);
if (text && text.toLowerCase().includes(q)) {
contentResults.push({ ...item, score: 0.5, excerpt: extractExcerpt(text, q) });
}
}
}
return [...titleResults, ...contentResults].slice(0, 8);
}
function renderSearchResults(results) {
const container = document.getElementById('search-results');
const input = document.getElementById('search-input');
if (!results.length) {
container.classList.add('hidden');
input.setAttribute('aria-expanded', 'false');
return;
}
container.innerHTML = results.map((item, i) =>
`<div class="search-result" role="option" data-id="${item.id}" data-index="${i}" tabindex="-1">
<div class="search-result-top">
<span class="search-result-title">${item.title}</span>
<span class="search-result-track">${item.trackLabel}</span>
</div>
${item.excerpt ? `<div class="search-result-excerpt">${item.excerpt}</div>` : ''}
</div>`
).join('');
container.classList.remove('hidden');
input.setAttribute('aria-expanded', 'true');
}
function selectSearchResult(id) {
closeSearch();
const item = findItemById(id);
if (item && item.path) {
loadContent(item.path, item.id, false);
}
}
function closeSearch() {
const container = document.getElementById('search-results');
const input = document.getElementById('search-input');
container.classList.add('hidden');
input.setAttribute('aria-expanded', 'false');
input.value = '';
activeSearchIndex = -1;
}
function initSearch() {
const input = document.getElementById('search-input');
const results = document.getElementById('search-results');
input.addEventListener('input', () => {
activeSearchIndex = -1;
renderSearchResults(searchItems(input.value));
});
input.addEventListener('keydown', (e) => {
const items = results.querySelectorAll('.search-result');
if (e.key === 'ArrowDown') {
e.preventDefault();
activeSearchIndex = Math.min(activeSearchIndex + 1, items.length - 1);
updateSearchHighlight(items);
} else if (e.key === 'ArrowUp') {
e.preventDefault();
activeSearchIndex = Math.max(activeSearchIndex - 1, -1);
updateSearchHighlight(items);
} else if (e.key === 'Enter') {
if (activeSearchIndex >= 0 && items[activeSearchIndex]) {
selectSearchResult(items[activeSearchIndex].dataset.id);
}
} else if (e.key === 'Escape') {
closeSearch();
}
});
results.addEventListener('mousedown', (e) => {
// Prevent input blur before click fires
e.preventDefault();
});
results.addEventListener('click', (e) => {
const result = e.target.closest('.search-result');
if (result) selectSearchResult(result.dataset.id);
});
input.addEventListener('blur', () => {
setTimeout(() => closeSearch(), 150);
});
}
function updateSearchHighlight(items) {
items.forEach((el, i) => {
el.classList.toggle('search-result-active', i === activeSearchIndex);
});
}
// ===== Find item by ID =====
function findItemById(id) {
return allItems.find(item => item.id === id);
}
// ===== Render Sidebar =====
function renderSidebar() {
const navTree = document.getElementById('nav-tree');
navTree.innerHTML = '';
// Render shared sections
const sharedSection = document.createElement('div');
sharedSection.className = 'nav-section';
const sharedHeader = document.createElement('div');
sharedHeader.className = 'nav-section-header';
sharedHeader.textContent = 'General';
sharedSection.appendChild(sharedHeader);
config.shared.forEach(item => {
if (item.children) {
// Render as collapsible group (Balloon)
const group = document.createElement('div');
group.className = item.collapsed ? 'nav-group collapsed' : 'nav-group expanded';
const toggle = document.createElement('button');
toggle.className = 'nav-group-toggle';
toggle.textContent = item.title;
toggle.addEventListener('click', () => {
group.classList.toggle('collapsed');
group.classList.toggle('expanded');
});
const children = document.createElement('div');
children.className = 'nav-children';
item.children.forEach(child => {
const childBtn = createNavButton(child);
children.appendChild(childBtn);
});
group.appendChild(toggle);
group.appendChild(children);
sharedSection.appendChild(group);
} else {
const btn = createNavButton(item);
sharedSection.appendChild(btn);
}
});
navTree.appendChild(sharedSection);
// Render track sections
// Add "Tracks" header
const tracksHeader = document.createElement('div');
tracksHeader.className = 'nav-section-header';
tracksHeader.textContent = 'Tracks';
navTree.appendChild(tracksHeader);
if (activeTrack === 'all') {
// Show all tracks as collapsible groups (collapsed by default)
config.tracks.forEach(track => {
const group = document.createElement('div');
group.className = track.collapsed ? 'nav-group collapsed' : 'nav-group expanded';
const toggle = document.createElement('button');
toggle.className = 'nav-group-toggle';
toggle.textContent = track.title;
toggle.addEventListener('click', () => {
group.classList.toggle('collapsed');
group.classList.toggle('expanded');
});
const children = document.createElement('div');
children.className = 'nav-children';
track.sections.forEach(section => {
const btn = createNavButton(section);
children.appendChild(btn);
});
group.appendChild(toggle);
group.appendChild(children);
navTree.appendChild(group);
});
} else {
// Show only selected track as auto-expanded collapsible group
const track = config.tracks.find(t => t.id === activeTrack);
if (track) {
const group = document.createElement('div');
group.className = 'nav-group expanded'; // Auto-expand when filtered
const toggle = document.createElement('button');
toggle.className = 'nav-group-toggle';
toggle.textContent = track.title;
toggle.addEventListener('click', () => {
group.classList.toggle('collapsed');
group.classList.toggle('expanded');
});
const children = document.createElement('div');
children.className = 'nav-children';
track.sections.forEach(section => {
const btn = createNavButton(section);
children.appendChild(btn);
});
group.appendChild(toggle);
group.appendChild(children);
navTree.appendChild(group);
}
}
updateSidebarActiveState();
}
// ===== Create nav button =====
function createNavButton(item) {
const btn = document.createElement('button');
btn.className = 'nav-item';
btn.textContent = item.title;
btn.dataset.id = item.id;
if (item.stub) {
btn.classList.add('stub');
}
if (item.id === activeId) {
btn.classList.add('active');
}
btn.addEventListener('click', () => {
if (!item.stub) {
loadContent(item.path, item.id, false);
// Close sidebar on mobile
if (window.innerWidth < 768) {
document.body.classList.remove('sidebar-open');
}
} else {
showStubMessage(item.title);
}
});
return btn;
}
// ===== Load Content =====
async function loadContent(path, id, isStub = false) {
if (isStub) {
showStubMessage(id);
return;
}
try {
const response = await fetch(path);
if (!response.ok) {
throw new Error(`Failed to load: ${path}`);
}
const markdown = await response.text();
let html = marked.parse(markdown);
html = rewritePaths(html, path);
document.getElementById('content').innerHTML = html;
// Update state
activeId = id;
window.location.hash = id;
updateSidebarActiveState();
updatePinoutFabVisibility();
saveLastVisited(id);
// Scroll to top
window.scrollTo(0, 0);
} catch (error) {
console.error('Content load error:', error);
showError(`Failed to load content: ${error.message}`);
}
}
// ===== Rewrite relative paths =====
function rewritePaths(html, mdFilePath) {
const baseDir = mdFilePath.substring(0, mdFilePath.lastIndexOf('/') + 1);
const container = document.createElement('div');
container.innerHTML = html;
// Rewrite img src
container.querySelectorAll('img[src]').forEach(img => {
const src = img.getAttribute('src');
if (src && !src.startsWith('http') && !src.startsWith('#') && !src.startsWith('/') && !src.startsWith(baseDir)) {
img.setAttribute('src', baseDir + src);
}
});
// Rewrite video/source src
container.querySelectorAll('video[src], source[src]').forEach(el => {
const src = el.getAttribute('src');
if (src && !src.startsWith('http') && !src.startsWith('#') && !src.startsWith('/') && !src.startsWith(baseDir)) {
el.setAttribute('src', baseDir + src);
}
});
// Rewrite a href (for relative links)
container.querySelectorAll('a[href]').forEach(link => {
const href = link.getAttribute('href');
if (href && !href.startsWith('http') && !href.startsWith('#') && !href.startsWith('/') && !href.startsWith(baseDir)) {
link.setAttribute('href', baseDir + href);
}
});
return container.innerHTML;
}
// ===== Show Landing =====
function showLanding() {
activeId = null;
window.location.hash = '';
updateSidebarActiveState();
updatePinoutFabVisibility();
document.getElementById('content').innerHTML = `
<div class="landing">
<img src="assets/images/stratolab.svg" alt="StratoLab logo" class="landing-logo">
<h1>Welcome to StratoLab!</h1>
<p>StratoLab is a project built to be usable by schools, community groups, youth organizations, and more as an introduction to programming, electronics and team building.</p>
<p>The <a href="https://www.weather.gov/chs/upperair" target="_blank" rel="noopener noreferrer">National Weather Service</a> launches a minimum of two high altitude balloons a day from <a href="https://www.weather.gov/upperair/nws_upper" target="_blank" rel="noopener noreferrer">91 locations</a> at 1100 and 2300 UTC to observe weather conditions used to model weather forecasts. When flying high altitude balloons, data is usually collected throughout the flight and later retrieved for analysis.</p>
<p>This project contains lessons wherein learners will launch their own weather balloon to the stratosphere, or approximately 90,000+ feet. Throughout the balloon flight, the components within the payload will collect temperature, barometric pressure, latitude, longitude, elevation, and other telemetry data. This information is collected via the peripheral modules attached to the microcontrollers within the payload and stored in an SD card for analysis after recovery.</p>
<h2>Hands-on Experiences</h2>
<p>The project contains basic hands-on experiences with the following:</p>
<ul>
<li>Microcontrollers & electronics, including wiring peripheral modules between a microcontroller and breadboard</li>
<li>Programming microcontrollers to interact with peripheral modules using C programming language (Arduino microcontroller) or Python (Raspberry Pi Pico microcontroller)</li>
<li>Launching a finished product in a high-altitude balloon flight to the stratosphere (90,000+ feet)</li>
<li>Analyzing collected data after recovering the balloon payload</li>
</ul>
<p>Each lesson is constructed to be completed within the timeframe of a typical classroom experience (approximately 45 minutes to 1 hour), and are designed to be completed by small groups (between 2 and 5 learners is recommended).</p>
<p class="cta">Select a track from the sidebar to get started!</p>
</div>
`;
}
// ===== Show Stub Message =====
function showStubMessage(title) {
document.getElementById('content').innerHTML = `
<div class="landing">
<h1>${title}</h1>
<p style="font-size: 18px; color: var(--color-text-muted);">This lesson is coming soon. Check back later!</p>
<p><a href="#" onclick="showLanding(); return false;">Return to home</a></p>
</div>
`;
window.scrollTo(0, 0);
}
// ===== Show Error =====
function showError(message) {
document.getElementById('content').innerHTML = `
<div class="landing">
<h1>Error</h1>
<p style="color: var(--color-warning-border);">${message}</p>
<p><a href="#" onclick="showLanding(); return false;">Return to home</a></p>
</div>
`;
}
// ===== Update Sidebar Active State =====
function updateSidebarActiveState() {
document.querySelectorAll('.nav-item').forEach(btn => {
if (btn.dataset.id === activeId) {
btn.classList.add('active');
} else {
btn.classList.remove('active');
}
});
}
// ===== Event Listeners =====
function setupEventListeners() {
// Track picker buttons
document.querySelectorAll('#track-picker button').forEach(btn => {
btn.addEventListener('click', () => {
const track = btn.dataset.track;
setActiveTrack(track);
// Update active state
document.querySelectorAll('#track-picker button').forEach(b => {
b.classList.remove('active');
});
btn.classList.add('active');
});
});
// Hamburger toggle (mobile)
document.getElementById('hamburger').addEventListener('click', () => {
document.body.classList.toggle('sidebar-open');
});
// Close sidebar when clicking outside on mobile
document.body.addEventListener('click', (e) => {
if (window.innerWidth < 768 && document.body.classList.contains('sidebar-open')) {
if (!e.target.closest('#sidebar') && !e.target.closest('#hamburger')) {
document.body.classList.remove('sidebar-open');
}
}
});
// Hash change
window.addEventListener('hashchange', () => {
if (!window.location.hash) {
showLanding();
} else {
const id = window.location.hash.slice(1);
const item = findItemById(id);
if (item && item.id !== activeId) {
loadContent(item.path, item.id, item.stub);
}
}
});
// Logo click → showLanding
document.getElementById('logo-link').addEventListener('click', (e) => {
e.preventDefault();
showLanding();
});
// Toast buttons
document.getElementById('toast-continue').addEventListener('click', () => {
const data = localStorage.getItem('stratolab-last-visited');
if (data) {
try {
const { id } = JSON.parse(data);
const item = findItemById(id);
if (item) {
loadContent(item.path, item.id, item.stub);
dismissToast();
}
} catch (e) {
console.error('Error parsing last visited:', e);
}
}
});
document.getElementById('toast-dismiss').addEventListener('click', () => {
dismissToast();
localStorage.removeItem('stratolab-last-visited');
});
// Pinout FAB and Modal
document.getElementById('pinout-fab').addEventListener('click', openPinoutModal);
document.getElementById('pinout-modal-close').addEventListener('click', closePinoutModal);
document.getElementById('pinout-modal-backdrop').addEventListener('click', closePinoutModal);
// Escape key to close modal
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && !document.getElementById('pinout-modal').classList.contains('hidden')) {
closePinoutModal();
}
});
}
// ===== Track Picker =====
function setActiveTrack(track) {
activeTrack = track;
renderSidebar();
updatePinoutFabVisibility();
}
// ===== localStorage: Last Visited =====
function saveLastVisited(id) {
const item = findItemById(id);
if (item && !item.stub) {
localStorage.setItem('stratolab-last-visited', JSON.stringify({
id: id,
title: item.title,
timestamp: Date.now()
}));
}
}
function checkLastVisited() {
const data = localStorage.getItem('stratolab-last-visited');
if (!data) return;
try {
const { id, title, timestamp } = JSON.parse(data);
const thirtyDays = 30 * 24 * 60 * 60 * 1000;
if (Date.now() - timestamp > thirtyDays) {
localStorage.removeItem('stratolab-last-visited');
return;
}
// Verify the item still exists
const item = findItemById(id);
if (item && !item.stub) {
showToast(id, title);
} else {
localStorage.removeItem('stratolab-last-visited');
}
} catch (e) {
console.error('Error checking last visited:', e);
localStorage.removeItem('stratolab-last-visited');
}
}
function showToast(id, title) {
const toast = document.getElementById('toast');
document.getElementById('toast-message').textContent =
`Continue where you left off? ${title}`;
toast.classList.remove('hidden');
// Auto-dismiss after 10 seconds
setTimeout(() => {
if (!toast.classList.contains('hidden')) {
dismissToast();
}
}, 10000);
}
function dismissToast() {
document.getElementById('toast').classList.add('hidden');
}
// ===== Pinout Modal =====
function updatePinoutFabVisibility() {
const fab = document.getElementById('pinout-fab');
// Determine which platform to show pinout for
let platform = null;
if (activeTrack === 'pico' || (activeId && activeId.startsWith('pico-'))) {
platform = 'pico';
} else if (activeTrack === 'arduino' || (activeId && activeId.startsWith('arduino-'))) {
platform = 'arduino';
} else if (activeTrack === 'esp32' || (activeId && activeId.startsWith('esp32-'))) {
platform = 'esp32';
}
if (platform && pinoutConfig[platform]) {
const cfg = pinoutConfig[platform];
// Update FAB thumbnail
document.getElementById('pinout-fab-image').src = cfg.thumbSrc;
// Update modal content
document.getElementById('pinout-modal-title').textContent = cfg.title;
const modalImg = document.getElementById('pinout-modal-image');
modalImg.src = cfg.fullSrc;
modalImg.alt = cfg.altText;
fab.classList.remove('hidden');
} else {
fab.classList.add('hidden');
}
}
function openPinoutModal() {
document.getElementById('pinout-modal').classList.remove('hidden');
document.body.classList.add('modal-open');
document.getElementById('pinout-modal-close').focus();
}
function closePinoutModal() {
document.getElementById('pinout-modal').classList.add('hidden');
document.body.classList.remove('modal-open');
document.getElementById('pinout-fab').focus();
}
// Make showLanding available globally for inline onclick handlers
window.showLanding = showLanding;
</script>
</body>
</html>