forked from bliu95/WV-App-Worksheet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
592 lines (522 loc) · 20 KB
/
index.html
File metadata and controls
592 lines (522 loc) · 20 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>App Worksheet</title>
<style>
body {
font-family: "Segoe UI", system-ui, sans-serif;
background-color: #f0f2f5;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
padding: 20px;
}
.card {
background: white;
width: 100%;
max-width: 800px;
border-radius: 12px;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
overflow: hidden;
display: flex;
flex-direction: column;
border: 1px solid #e1e4e8;
}
/* Loading Screen */
.loading-state {
padding: 40px;
text-align: center;
color: #666;
font-size: 1.2rem;
display: none; /* Hidden by default */
}
/* 1. Header (Title) */
.header-section {
padding: 1rem 1.5rem;
border-bottom: 1px solid #eee;
background: #fff;
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}
.header-left {
display: flex;
flex-direction: column;
}
.header-right {
display: flex;
gap: 10px;
align-items: center;
}
.step-badge {
background-color: #e3f2fd;
color: #0d47a1;
font-size: 0.75rem;
font-weight: 700;
padding: 4px 10px;
border-radius: 4px;
text-transform: uppercase;
letter-spacing: 1px;
display: inline-block;
margin-bottom: 0.25rem;
}
h2 {
margin: 0;
color: #202124;
font-size: 1.4rem;
}
#week-select {
width: 90px;
}
#section-select {
width: 325px;
}
/* 2. Image Component */
.image-section {
background-color: #f8f9fa;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
padding: 1rem 0;
border-bottom: 1px solid #eee;
min-height: 300px;
}
.image-section img {
max-width: 95%;
max-height: 400px;
border-radius: 6px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
object-fit: contain;
display: none;
}
/* 3. Text Component */
.text-section {
padding: 2rem;
color: #3c4043;
line-height: 1.6;
font-size: 1.05rem;
flex-grow: 1;
min-height: 100px;
}
/* Block Introduction Section */
.block-intro {
margin-top: 1.5rem;
padding: 1rem;
background-color: #f8f9fa;
border-radius: 8px;
border-left: 4px solid #1a73e8;
}
.block-intro-header {
font-weight: bold;
margin-bottom: 0.5rem;
color: #202124;
}
.block-intro img {
max-width: 100%;
max-height: 300px;
margin: 0.5rem 0;
border-radius: 4px;
}
.block-intro-description {
color: #5f6368;
font-size: 0.95rem;
}
/* 4. Controls (Next/Back) */
.controls {
display: flex;
justify-content: space-between;
padding: 1.25rem 2rem;
background-color: #fff;
border-top: 1px solid #eee;
}
button {
background-color: #1a73e8;
color: white;
border: none;
padding: 10px 24px;
border-radius: 6px;
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
}
button:hover { background-color: #1557b0; }
button:disabled { background-color: #dadce0; color: #80868b; cursor: not-allowed; }
select {
padding: 6px 10px;
border-radius: 4px;
border: 1px solid #ccc;
font-size: 0.9rem;
}
</style>
</head>
<body>
<div class="card">
<div id="loading-msg" class="loading-state">
Loading...
</div>
<div id="main-content">
<div class="header-section">
<div class="header-left">
<div id="step-badge" class="step-badge">Step 1</div>
<h2 id="step-title">Welcome</h2>
</div>
<div class="header-right">
<select id="week-select" onchange="handleWeekChange()"></select>
<select id="section-select" onchange="handleSectionChange()"></select>
</div>
</div>
<div class="image-section" id="image-block">
<img id="step-image" src="" alt="Step visualization" />
</div>
<div id="step-text" class="text-section">
Select a lesson below to begin.
</div>
<div class="controls">
<button id="btn-back" onclick="changeStep(-1)">Back</button>
<button id="btn-next" onclick="changeStep(1)">Next</button>
</div>
</div>
</div>
<script>
let allSteps = []; // All steps from the markdown file
let sections = []; // Array of sections, each with start/end indices
let currentSection = 0; // Currently selected section index
let currentStepInSection = 0; // Current step within the section
const lessonData = {
"Week 2": "./Weeks/Week 2/w2_guide.md",
"Week 4": "./Weeks/Week 4/w4_guide.md",
"Week 5": "./Weeks/Week 5/w5_guide.md",
"Week 6": "./Weeks/Week 6/w6_guide.md",
"Week 7": "./Weeks/Week 7/w7_guide.md",
"Week 8": "./Weeks/Week 8/w8_guide.md",
};
// Initialize
function init() {
const weekSelect = document.getElementById('week-select');
// Populate the Week Dropdown
Object.keys(lessonData).forEach(week => {
const option = document.createElement('option');
option.value = week;
option.textContent = week;
weekSelect.appendChild(option);
});
// Load the first week
handleWeekChange();
}
function handleWeekChange() {
const weekSelect = document.getElementById('week-select');
const selectedWeek = weekSelect.value;
const filename = lessonData[selectedWeek];
loadMarkdownFile(filename);
}
function handleSectionChange() {
const sectionSelect = document.getElementById('section-select');
currentSection = parseInt(sectionSelect.value, 10);
currentStepInSection = 0;
renderStep();
}
// Fetch Logic
function loadMarkdownFile(filename) {
currentSection = 0;
currentStepInSection = 0;
document.getElementById("main-content").style.opacity = "0.5";
document.getElementById("loading-msg").style.display = "block";
fetch(filename)
.then((response) => {
if (!response.ok) throw new Error("Could not find " + filename);
return response.text();
})
.then((text) => {
allSteps = parseMarkdown(text);
sections = splitIntoSections(allSteps);
document.getElementById("loading-msg").style.display = "none";
document.getElementById("main-content").style.opacity = "1";
populateSectionDropdown();
renderStep();
})
.catch((error) => {
document.getElementById("loading-msg").innerHTML = `Error: ${error.message}`;
document.getElementById("loading-msg").style.display = "block";
console.error(error);
});
}
// Parse Markdown
function parseMarkdown(md) {
const rawSteps = md.split(/^---$/m);
// First pass: parse all steps
const parsedSteps = rawSteps
.map((stepContent) => {
const lines = stepContent.trim().split("\n");
let title = "Step";
let image = "";
let textLines = [];
let isCheckpoint = false;
let checkpointName = null;
let isBlockIntro = false;
let blockName = "";
let blockNameStyled = "";
let blockImage = "";
let blockDescription = "";
lines.forEach((line) => {
const trimmed = line.trim();
if (trimmed.startsWith("# ")) {
title = trimmed.replace("# ", "");
} else if (trimmed.match(/!\[.*?\]\(.*?\)/)) {
const match = trimmed.match(/\((.*?)\)/);
if (match) image = match[1];
} else if (trimmed.length > 0) {
// Check for checkpoint or extension marker
const checkpointMatch = trimmed.match(/\[([^\]]*(Checkpoint|Extension)[^\]]*)\]/i);
if (checkpointMatch) {
isCheckpoint = true;
checkpointName = checkpointMatch[1].replace(/<[^>]*>/g, '').trim();
}
// Check for block introduction marker
const blockMatch = trimmed.match(/font-weight:bold[^>]*>Block:<\/span>\s*(<span[^>]*>([^<]*)<\/span>[^<]*)/i);
if (blockMatch) {
isBlockIntro = true;
blockNameStyled = blockMatch[1].trim(); // Preserve styled HTML span
blockName = blockMatch[2].trim(); // Plain text name for alt attribute
}
let parsed = trimmed
.replace(/\*\*(.*?)\*\*/g, "<b>$1</b>")
.replace(/`(.*?)`/g, '<code style="background:#eee;padding:2px 5px;border-radius:4px">$1</code>')
.replace(/\[([^\]]+)\]\((https?:\/\/[^)]+)\)/g, '<a href="$2" target="_blank">$1</a>');
// Check if this is a list item (ordered or unordered, with optional indent for sublists)
const indent = line.length - line.trimStart().length;
const listMatch = parsed.match(/^(\d+)\.\s+(.*)$/);
const letterMatch = parsed.match(/^([a-z])[.)]\s+(.*)$/);
const unorderedMatch = parsed.match(/^[-*]\s+(.*)$/);
if (listMatch) {
parsed = `<li data-indent="${indent}" value="${listMatch[1]}">${listMatch[2]}</li>`;
} else if (letterMatch) {
parsed = `<li data-indent="${indent}" data-letter="true">${letterMatch[2]}</li>`;
} else if (unorderedMatch) {
parsed = `<li data-indent="${indent}" data-ul="true">${unorderedMatch[1]}</li>`;
}
textLines.push(parsed);
}
});
// For block intros, extract the block image and description
if (isBlockIntro) {
blockImage = image;
// The description is all text after the block name line
const textContent = textLines.join("<br>");
const descMatch = textContent.split("<br>").slice(1).join("<br>").trim();
blockDescription = descMatch;
}
// Wrap consecutive <li> elements in nested <ol>/<ul> tags
let textContent = textLines.join("<br>");
textContent = textContent.replace(/(<li[^>]*>.*?<\/li>)(<br><li[^>]*>.*?<\/li>)*/g, function(match) {
const items = match.split('<br>').filter(s => s.trim());
let result = '';
let stack = []; // track open list tags and their indent levels
items.forEach(item => {
const indentMatch = item.match(/data-indent="(\d+)"/);
const isUl = item.includes('data-ul="true"');
const isLetter = item.includes('data-letter="true"');
const indent = indentMatch ? parseInt(indentMatch[1]) : 0;
const tag = isUl ? 'ul' : (isLetter ? 'ol type="a"' : 'ol');
const closeTag = isUl ? 'ul' : 'ol';
// Clean data attributes from the li
const cleanItem = item.replace(/\s*data-indent="\d+"/, '').replace(/\s*data-ul="true"/, '').replace(/\s*data-letter="true"/, '');
if (stack.length === 0) {
result += `<${tag}>`;
stack.push({ indent, closeTag });
} else {
const top = stack[stack.length - 1];
if (indent > top.indent) {
// Open a nested list
result += `<${tag}>`;
stack.push({ indent, closeTag });
} else {
// Close lists until we reach the right level
while (stack.length > 1 && stack[stack.length - 1].indent > indent) {
const closed = stack.pop();
result += `</${closed.closeTag}>`;
}
// If tag type changed at same level, close and reopen
if (stack.length > 0 && stack[stack.length - 1].indent === indent && stack[stack.length - 1].closeTag !== closeTag) {
const closed = stack.pop();
result += `</${closed.closeTag}><${tag}>`;
stack.push({ indent, closeTag });
}
}
}
result += cleanItem;
});
// Close all remaining open tags
while (stack.length > 0) {
const closed = stack.pop();
result += `</${closed.closeTag}>`;
}
return result;
});
return {
title,
image,
text: textContent,
isCheckpoint,
checkpointName,
isBlockIntro,
blockName,
blockNameStyled,
blockImage,
blockDescription
};
})
.filter((s) => s.text || s.image);
// Second pass: merge block intros with the following step
const mergedSteps = [];
let pendingBlockIntro = null;
for (let i = 0; i < parsedSteps.length; i++) {
const step = parsedSteps[i];
if (step.isBlockIntro && !step.isCheckpoint) {
// Store this block intro to merge with the next step
// (but not if it's also a checkpoint/extension - those should stand alone)
pendingBlockIntro = step;
} else {
// This is a regular step or a checkpoint/extension
if (pendingBlockIntro) {
// Merge the pending block intro into this step
step.blockIntro = {
name: pendingBlockIntro.blockName,
nameStyled: pendingBlockIntro.blockNameStyled,
image: pendingBlockIntro.blockImage,
description: pendingBlockIntro.blockDescription
};
pendingBlockIntro = null;
}
// For checkpoint/extension steps that have their own block intro content,
// set blockIntro from their own data
if (step.isCheckpoint && step.isBlockIntro && step.blockNameStyled) {
step.blockIntro = {
name: step.blockName,
nameStyled: step.blockNameStyled,
image: step.blockImage,
description: step.blockDescription
};
}
mergedSteps.push(step);
}
}
return mergedSteps;
}
// Split steps into sections based on checkpoints
function splitIntoSections(steps) {
const result = [];
let sectionStart = 0;
steps.forEach((step, index) => {
if (step.isCheckpoint) {
result.push({
name: step.checkpointName || `Checkpoint ${result.length + 1}`,
startIndex: sectionStart,
endIndex: index
});
sectionStart = index + 1;
}
});
// If there are remaining steps after the last checkpoint, create a final section
if (sectionStart < steps.length) {
result.push({
name: `Section ${result.length + 1} (Final)`,
startIndex: sectionStart,
endIndex: steps.length - 1
});
}
return result;
}
function populateSectionDropdown() {
const sectionSelect = document.getElementById('section-select');
sectionSelect.innerHTML = "";
sections.forEach((section, index) => {
const option = document.createElement('option');
option.value = index;
option.textContent = section.name;
sectionSelect.appendChild(option);
});
}
// Get steps for current section
function getCurrentSectionSteps() {
if (sections.length === 0) return [];
const section = sections[currentSection];
return allSteps.slice(section.startIndex, section.endIndex + 1);
}
// Render View
function renderStep() {
const sectionSteps = getCurrentSectionSteps();
if (sectionSteps.length === 0) return;
const current = sectionSteps[currentStepInSection];
// Show "Overview" only for the first step of a section if it has no image
if (currentStepInSection === 0 && !current.image) {
document.getElementById("step-badge").innerText = "Overview";
} else {
// Count steps for numbering (excluding overview if present)
const hasOverview = sectionSteps.length > 0 && !sectionSteps[0].image;
const stepsToCount = hasOverview ? sectionSteps.slice(1) : sectionSteps;
const adjustedIndex = hasOverview ? currentStepInSection - 1 : currentStepInSection;
document.getElementById("step-badge").innerText = `Step ${adjustedIndex + 1} of ${stepsToCount.length}`;
}
document.getElementById("step-title").innerText = current.title;
// Build the text content, including block intro if present
let textContent = current.text;
if (current.blockIntro) {
textContent += `
<div class="block-intro">
<div class="block-intro-header">Block: ${current.blockIntro.nameStyled}</div>
${current.blockIntro.image ? `<img src="${current.blockIntro.image}" alt="Block: ${current.blockIntro.name}">` : ''}
<div class="block-intro-description">${current.blockIntro.description}</div>
</div>
`;
}
document.getElementById("step-text").innerHTML = textContent;
const imgEl = document.getElementById("step-image");
if (current.image) {
imgEl.src = current.image;
imgEl.style.display = "block";
document.getElementById("image-block").style.display = "flex";
} else {
imgEl.style.display = "none";
document.getElementById("image-block").style.display = "none";
}
document.getElementById("btn-back").disabled = currentStepInSection === 0;
const nextBtn = document.getElementById("btn-next");
const isLastStepInSection = currentStepInSection === sectionSteps.length - 1;
const isLastSection = currentSection === sections.length - 1;
if (isLastStepInSection && isLastSection) {
nextBtn.innerText = "Finish";
nextBtn.disabled = true;
} else if (isLastStepInSection) {
nextBtn.innerText = "Next Section";
nextBtn.disabled = false;
} else {
nextBtn.innerText = "Next";
nextBtn.disabled = false;
}
}
function changeStep(direction) {
const sectionSteps = getCurrentSectionSteps();
const nextIndex = currentStepInSection + direction;
if (nextIndex >= 0 && nextIndex < sectionSteps.length) {
currentStepInSection = nextIndex;
renderStep();
} else if (direction === 1 && nextIndex >= sectionSteps.length && currentSection < sections.length - 1) {
// Move to next section
currentSection++;
currentStepInSection = 0;
document.getElementById('section-select').value = currentSection;
renderStep();
}
}
// Start the app
init();
</script>
</body>
</html>