-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmodule.html
More file actions
596 lines (548 loc) · 24.6 KB
/
Copy pathmodule.html
File metadata and controls
596 lines (548 loc) · 24.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Module · The AI Learning Map</title>
<link href="https://fonts.googleapis.com/css?family=Raleway:400,300,600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
<style>
.module-hero { padding: 46px 0 8px; max-width: 700px; }
.crumb { font-size: 12.5px; color: var(--muted); letter-spacing: 0.5px; }
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--accent-dark); }
h1 { font-size: clamp(26px, 4vw, 38px); font-weight: 600; letter-spacing: -0.8px; margin-top: 6px; }
.module-hero .blurb { color: var(--text); font-size: 15.5px; margin-top: 12px; font-weight: 300; }
.module-hero .meta { font-size: 13px; color: var(--muted); margin-top: 10px; }
.module-hero .meta b { color: var(--text); font-weight: 600; }
.prereq-chips a.chip { cursor: pointer; }
/* ---------- mini skill tree (top right, low opacity) ---------- */
#minimap {
position: fixed; top: 64px; right: 18px; width: 200px; z-index: 80;
opacity: 0.28; transition: opacity .25s ease, transform .5s ease;
transform-origin: top right;
}
#minimap:hover { opacity: 1; }
#minimap.traveling { opacity: 1; transform: scale(1.6); }
#minimap rect { cursor: pointer; transition: fill .15s ease, stroke .15s ease; }
#minimap rect.hop { fill: var(--accent-primary); stroke: var(--accent-dark); }
#minimap rect.hovered { fill: #e6f7fe !important; stroke: var(--accent-primary) !important; }
#minimap text.node-abbr { pointer-events: none; user-select: none; }
#minimap .label {
font-size: 9.5px; letter-spacing: 1.5px; text-transform: uppercase;
color: var(--muted); text-align: center; margin-top: 2px;
}
#minimap-tip {
position: fixed; z-index: 200; background: rgba(30,36,48,0.88);
color: #fff; font-size: 11px; padding: 4px 9px; border-radius: 5px;
pointer-events: none; white-space: nowrap; display: none;
box-shadow: 0 3px 10px rgba(0,0,0,0.25); letter-spacing: 0.2px;
}
@media (max-width: 900px) { #minimap { display: none; } }
/* ---------- step nav ---------- */
.step-nav {
display: flex; gap: 8px; margin: 26px 0 8px; position: sticky; top: 53px;
background: rgba(255,255,255,0.95); backdrop-filter: blur(6px);
padding: 10px 0; z-index: 70; border-bottom: 1px solid var(--line);
}
.step-nav a {
display: flex; align-items: center; gap: 8px;
border: 1px solid var(--line); border-radius: var(--radius-pill);
padding: 6px 14px; font-size: 13px; color: var(--text); font-weight: 600;
transition: all .15s;
}
.step-nav a:hover, .step-nav a.current { border-color: var(--accent-primary); color: var(--accent-dark); }
.step-nav .n {
width: 20px; height: 20px; border-radius: 50%; background: var(--accent-primary);
color: #fff; font-size: 11.5px; display: flex; align-items: center; justify-content: center;
}
/* ---------- flow sections ---------- */
section.flow { padding: 36px 0 8px; max-width: 760px; scroll-margin-top: 110px; }
section.flow .eyebrow {
font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--accent-dark); font-weight: 600;
}
section.flow h2 { font-size: 23px; font-weight: 600; margin-top: 2px; }
section.flow .desc { color: var(--muted); font-size: 14px; margin-top: 6px; font-weight: 300; }
.placeholder {
margin-top: 16px; border: 1.5px dashed #d5d5d5; border-radius: var(--radius-card);
padding: 34px 26px; text-align: center; color: var(--muted); background: #fcfcfc;
}
.placeholder .big { font-size: 30px; }
.placeholder p { font-size: 13.5px; max-width: 460px; margin: 8px auto 0; }
.placeholder .actions { margin-top: 14px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.next-prev { display: flex; justify-content: space-between; margin: 44px 0 10px; max-width: 760px; gap: 10px; }
/* ---------- resources ---------- */
.resource {
display: flex; align-items: center; gap: 12px;
border: 1px solid var(--line); border-radius: var(--radius-card);
padding: 11px 16px; margin-top: 10px; color: var(--text); transition: all .15s;
}
.resource:hover { border-color: var(--accent-primary); box-shadow: var(--shadow-card); color: var(--text); }
.resource .icon { font-size: 18px; }
.resource .h { font-weight: 600; font-size: 13.5px; }
.resource .u { font-size: 11.5px; color: var(--muted); }
.resources-empty {
margin-top: 12px; border: 1.5px dashed #d5d5d5; border-radius: var(--radius-card);
padding: 18px; text-align: center; color: var(--muted); font-size: 13px; background: #fcfcfc;
}
</style>
</head>
<body>
<nav class="site-nav">
<div class="wrap inner">
<span class="brand"><a href="index.html" style="color:var(--text)">Amir-Hossein Karimi · <span class="teaching">Teaching</span></a></span>
<span class="links">
<a href="index.html" id="back-link">← back to the map</a>
<button class="lang-btn" id="lang-btn" title="Switch language / تغییر زبان">فا</button>
<a href="https://amirhkarimi.com" target="_blank">amirhkarimi.com</a>
</span>
</div>
</nav>
<div id="minimap-tip"></div>
<div id="minimap" title="Click a node to travel there">
<svg id="minimap-svg"></svg>
<div class="label" id="minimap-label">you are here — click a node to travel</div>
</div>
<main class="wrap">
<header class="module-hero" id="hero"></header>
<div class="step-nav" id="step-nav"></div>
<div id="sections"></div>
<div class="next-prev" id="next-prev"></div>
</main>
<footer class="site-footer">
<div class="wrap" id="footer-text">Sequence may evolve based on feedback and emerging technology. · © 2026 Amir-Hossein Karimi</div>
</footer>
<script src="data.js"></script>
<script>
const params = new URLSearchParams(location.search);
const mod = byId[params.get("id")] || byId["c-ml"];
const mode = params.get("mode");
document.title = `${mod.title} · The AI Learning Map`;
track("module_view", { module_id: mod.id, mode: mode || "(none)", reference: !!mod.ref });
const RES_ICON = { video: "\u{1F3A5}", website: "\u{1F310}", pdf: "\u{1F4C4}", book: "\u{1F4D8}" };
/* ---------- hero ---------- */
function renderHero() {
const lang = getLang();
const title = (lang === "fa" && mod.title_fa) ? mod.title_fa : mod.title;
const prereqChips = mod.prereqs.length
? mod.prereqs.map(p => {
const pt = (lang === "fa" && byId[p].title_fa) ? byId[p].title_fa : byId[p].title;
return `<a class="chip aud" href="module.html?id=${p}">${pt}</a>`;
}).join("")
: `<span class="chip planned">None — start here</span>`;
const S = STRINGS[lang];
const TL = lang === "fa" ? TIER_LABEL_FA : TIER_LABEL;
const tierDisplay = TL[mod.tier] || mod.tier;
document.getElementById("hero").innerHTML = `
<div class="crumb"><a href="index.html">The AI Learning Map</a> / ${tierDisplay}</div>
<h1>${title}</h1>
<div>${mod.aud.map(a => `<span class="chip aud">${S.audience[a] || AUD_LABEL[a]}</span>`).join("")}</div>
<p class="blurb">${mod.blurb}</p>
<p class="meta prereq-chips"><b>Builds on:</b> ${prereqChips}</p>`;
}
/* ---------- step nav + sections ---------- */
const STEPS_EN = ["listen","play","build","quiz"];
const STEP_ICONS = { listen:"\u{1F3A7}", play:"\u{1F3AE}", build:"\u{1F528}", quiz:"\u{2705}" };
function renderSections() {
const lang = getLang();
const S = STRINGS[lang];
// Step nav
if (!mod.ref) {
document.getElementById("step-nav").innerHTML = STEPS_EN.map((k, i) => {
const ingData = S.ing[k];
const name = ingData ? ingData.name : (k === "quiz" ? (lang === "fa" ? "آزمون" : "Quiz") : k);
const tag = ingData ? ingData.tag : (k === "quiz" ? (lang === "fa" ? "خودآزمایی" : "self-check") : "");
return `<a href="#${k}" data-k="${k}">
<span class="n">${i + 1}</span>${name}
<span class="muted-tag" style="font-weight:400;color:var(--muted)">· ${tag}</span>
</a>`;
}).join("");
}
// Resources HTML
const resourcesHtml = mod.resources && mod.resources.length
? mod.resources.map(r => `
<a class="resource" href="${r.url}" target="_blank" rel="noopener"
onclick="track('resource_click',{module_id:'${mod.id}',resource:'${r.url}'})">
<span class="icon">${RES_ICON[r.type] || RES_ICON.website}</span>
<span><div class="h">${r.title}</div><div class="u">${r.url.replace(/^https?:\/\//, "")}</div></span>
</a>`).join("")
: `<div class="resources-empty">${S.resources_empty}</div>`;
if (mod.ref) {
document.getElementById("step-nav").style.display = "none";
document.getElementById("sections").innerHTML = `
<section class="flow" id="resources">
<div class="eyebrow">Reference module</div>
<h2>${S.ref_resources_title}</h2>
<p class="desc">${S.ref_resources_sub} ${mod.title}.</p>
${resourcesHtml}
</section>`;
return;
}
// --- Listen section — auto-detect PDF from assets/ ---
const listenHtml = `
<section class="flow" id="listen">
<div class="eyebrow">Step 1 · ${S.ing.listen.tag}</div>
<h2>${STEP_ICONS.listen} ${S.ing.listen.name}</h2>
<p class="desc">${S.ing.listen.desc}</p>
<div id="pdf-area" style="margin-top:16px">
<div class="placeholder" id="pdf-loading">
<div class="big">⏳</div>
<p style="color:var(--muted);font-size:13px">Checking for lecture notes…</p>
</div>
</div>
<div class="placeholder" style="margin-top:16px">
<div class="big">${STEP_ICONS.listen}</div>
<p>Lecture recording and podcast version coming soon.</p>
<div class="actions">
<button class="btn" disabled>Watch lecture</button>
<button class="btn" disabled>Listen as podcast</button>
</div>
</div>
</section>`;
// --- Play section ---
const playHtml = `
<section class="flow" id="play">
<div class="eyebrow">Step 2 · ${S.ing.play.tag}</div>
<h2>${STEP_ICONS.play} ${S.ing.play.name}</h2>
<p class="desc">${S.ing.play.desc}</p>
<div id="play-content">
<div class="placeholder">
<div class="big">${STEP_ICONS.play}</div>
<p>Interactive course notes under construction — readable theory with live, manipulable visualizations of the algorithms (KaTeX + animations).</p>
<div class="actions"><button class="btn" disabled>Open interactive notes</button></div>
</div>
</div>
</section>`;
// --- Build section ---
const buildHtml = `
<section class="flow" id="build">
<div class="eyebrow">Step 3 · ${S.ing.build.tag}</div>
<h2>${STEP_ICONS.build} ${S.ing.build.name}</h2>
<p class="desc">${S.ing.build.desc}</p>
<div class="placeholder">
<div class="big">${STEP_ICONS.build}</div>
<p>A guided Python notebook where you implement the ideas yourself and get feedback on your work.</p>
<div class="actions">
<button class="btn" disabled>Open notebook</button>
<button class="btn" disabled>Open in Colab</button>
</div>
</div>
</section>`;
// --- Quiz section ---
const quizLabel = lang === "fa" ? "آزمون" : "Quiz";
const quizTag = lang === "fa" ? "خودآزمایی" : "self-check";
const quizHtml = buildQuizSection(lang);
// --- Resources section ---
const resourcesSection = `
<section class="flow" id="resources">
<div class="eyebrow">Optional · go deeper</div>
<h2>${S.resources_title}</h2>
<p class="desc">${S.resources_sub}</p>
${resourcesHtml}
</section>`;
document.getElementById("sections").innerHTML =
listenHtml + playHtml + buildHtml + quizHtml + resourcesSection;
// Auto-detect lecture PDF from assets/
autoDetectPDF();
// Auto-inject module-specific play content
autoDetectPlay();
}
/* ---------- PDF auto-detect (checks assets/manual.pdf then assets/generated.pdf) ---------- */
async function autoDetectPDF() {
const base = `modules/${mod.id}/assets`;
const candidates = [
{ path: `${base}/manual.pdf`, label: mod.title },
{ path: `${base}/generated.pdf`, label: mod.title },
];
const area = document.getElementById("pdf-area");
if (!area) return;
for (const { path, label } of candidates) {
try {
const r = await fetch(path, { method: "HEAD" });
if (r.ok) {
area.innerHTML = `
<div style="border:1px solid var(--line);border-radius:var(--radius-card);overflow:hidden;margin-top:4px">
<div style="padding:7px 12px;font-size:12px;color:var(--muted);background:#f8f8f8;border-bottom:1px solid var(--line);display:flex;justify-content:space-between;align-items:center">
<span>📄 ${label}</span>
<a href="${path}" target="_blank" style="font-size:12px;font-weight:600">Open in new tab ↗</a>
</div>
<iframe src="${path}" title="Lecture notes" style="width:100%;height:540px;border:none;display:block"></iframe>
</div>`;
track("pdf_auto_load", { module_id: mod.id, pdf_path: path });
return;
}
} catch {}
}
// No PDF found — show a quiet placeholder
area.innerHTML = `
<div style="border:1.5px dashed #d5d5d5;border-radius:var(--radius-card);padding:22px;text-align:center;color:var(--muted);background:#fcfcfc;font-size:13px">
Lecture notes not yet published — run <code style="background:#f0f0f0;padding:2px 6px;border-radius:4px">make listen MODULE=${mod.id}</code> to generate them.
</div>`;
}
/* ---------- Play content auto-detect ---------- */
async function autoDetectPlay() {
const area = document.getElementById("play-content");
if (!area) return;
try {
const r = await fetch(`modules/${mod.id}/play.html`, { method: "HEAD" });
if (!r.ok) return;
const html = await fetch(`modules/${mod.id}/play.html`).then(r => r.text());
area.innerHTML = html;
// Execute any <script> tags in the injected HTML
area.querySelectorAll("script").forEach(old => {
const s = document.createElement("script");
s.textContent = old.textContent;
old.replaceWith(s);
});
} catch {}
}
/* ---------- Quiz section builder ---------- */
function buildQuizSection(lang) {
const quizLabel = lang === "fa" ? "آزمون" : "Quiz";
const quizTag = lang === "fa" ? "خودآزمایی" : "self-check";
const quiz = mod.quiz || [];
let innerHtml;
if (quiz.length === 0) {
innerHtml = `
<div class="placeholder" style="margin-top:16px">
<div class="big">✅</div>
<p>${lang === "fa"
? "سوالات آزمون برای این ماژول به زودی اضافه میشود."
: "Quiz questions for this module are on their way. Check back after the lecture."}</p>
</div>`;
} else {
const mcqs = quiz.filter(q => q.opts);
const open = quiz.filter(q => !q.opts);
innerHtml = mcqs.map((q, qi) => `
<div class="quiz-q" id="qq-${qi}">${q.q}${q.marks ? `<span class="marks">[${q.marks} mark${q.marks>1?"s":""}]</span>` : ""}
</div>
<div class="quiz-opts">${q.opts.map((opt, oi) =>
`<button onclick="pickOpt(${qi},${oi},${q.ans})">${opt}</button>`
).join("")}</div>
`).join("") + open.map((q, qi) => `
<div class="quiz-open">
<div class="open-q">${q.q}${q.marks ? `<span class="marks">[${q.marks} mark${q.marks>1?"s":""}]</span>` : ""}</div>
<div class="open-hint">${lang === "fa" ? "پاسخ خود را اینجا بنویسید..." : "Work it out on paper, then check your notes."}</div>
</div>
`).join("");
if (mcqs.length) {
innerHtml += `<div style="margin-top:14px">
<button class="btn primary" onclick="checkQuiz(${mcqs.length})">
${lang === "fa" ? "بررسی پاسخها" : "Check answers"}
</button>
<span class="quiz-score" id="quiz-score"></span>
</div>`;
}
}
return `
<section class="flow" id="quiz">
<div class="eyebrow">Step 4 · ${quizTag}</div>
<h2>✅ ${quizLabel}</h2>
<p class="desc">${lang === "fa"
? "چند سوال کوتاه برای بررسی درک شما از این ماژول."
: "A few short questions to test your understanding of this module."}</p>
${innerHtml}
</section>`;
}
/* Quiz MCQ interactions */
const quizSelections = {};
function pickOpt(qi, oi, correct) {
quizSelections[qi] = oi;
const container = document.querySelectorAll(".quiz-opts")[qi];
container.querySelectorAll("button").forEach((btn, i) => {
btn.classList.toggle("selected", i === oi);
});
}
function checkQuiz(total) {
let score = 0;
for (let qi = 0; qi < total; qi++) {
const quiz = mod.quiz.filter(q => q.opts);
const correct = quiz[qi].ans;
const chosen = quizSelections[qi];
const container = document.querySelectorAll(".quiz-opts")[qi];
if (!container) continue;
container.querySelectorAll("button").forEach((btn, oi) => {
btn.classList.remove("correct","wrong");
if (oi === correct) btn.classList.add("correct");
else if (oi === chosen && oi !== correct) btn.classList.add("wrong");
});
if (chosen === correct) score++;
}
const lang = getLang();
document.getElementById("quiz-score").textContent = lang === "fa"
? `${score} از ${total} درست`
: `${score} / ${total} correct`;
}
/* ---------- next / prev within the audience path ---------- */
function renderNextPrev() {
const lang = getLang();
const aud = mod.aud.includes(getAudience()) ? getAudience() : mod.aud[0];
const steps = (PATHS[aud] || PATHS.student).steps.map(s => s.id);
const idx = steps.indexOf(mod.id);
const np = [];
if (idx > 0) {
const prev = byId[steps[idx-1]];
const prevTitle = (lang === "fa" && prev.title_fa) ? prev.title_fa : prev.title;
np.push(`<a class="btn" href="module.html?id=${prev.id}">← ${prevTitle}</a>`);
} else np.push("<span></span>");
if (idx >= 0 && idx < steps.length - 1) {
const next = byId[steps[idx+1]];
const nextTitle = (lang === "fa" && next.title_fa) ? next.title_fa : next.title;
np.push(`<a class="btn primary" href="module.html?id=${next.id}">${nextTitle} →</a>`);
}
document.getElementById("next-prev").innerHTML = np.join("");
}
/* ---------- mini skill tree ---------- */
(function renderMinimap() {
const W = 200, NW = 30, NH = 11, UY = 22, PADM = 8;
const maxY = Math.max(...Object.values(LAYOUT).map(p => p.y));
const H = maxY * UY + NH + 2 * PADM;
const svg = document.getElementById("minimap-svg");
svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
svg.setAttribute("width", W); svg.setAttribute("height", H);
const tip = document.getElementById("minimap-tip");
const pos = id => ({
x: Math.max(NW/2 + 2, Math.min((LAYOUT[id].x / 100) * W, W - NW/2 - 2)),
y: H - PADM - NH / 2 - LAYOUT[id].y * UY,
});
// Edge lines (skip junction nodes — draw direct line from math to junction to concepts)
let lines = "";
for (const [from, to] of EDGES) {
const mfrom = byId[from], mto = byId[to];
if (mfrom.junction || mto.junction) continue; // junctions handled separately
const a = pos(from), b = pos(to);
lines += `<line x1="${a.x}" y1="${a.y - NH/2}" x2="${b.x}" y2="${b.y + NH/2}" stroke="#c9ced2" stroke-width="1"/>`;
}
// Draw junction edges as direct lines (fan-in from 5 maths, fan-out to 3 concepts)
for (const [from, to] of EDGES) {
const mfrom = byId[from], mto = byId[to];
if (!mfrom.junction && !mto.junction) continue;
if (!(from in LAYOUT) || !(to in LAYOUT)) continue;
const a = pos(from), b = pos(to);
const ay = mfrom.junction ? a.y : a.y - NH/2;
const by2 = mto.junction ? b.y : b.y + NH/2;
lines += `<line x1="${a.x}" y1="${ay}" x2="${b.x}" y2="${by2}" stroke="#c9ced2" stroke-width="1"/>`;
}
svg.innerHTML = lines;
// Draw junction dots in minimap
for (const m of MODULES) {
if (!m.junction || !(m.id in LAYOUT)) continue;
const p = pos(m.id);
const c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
c.setAttribute("cx", p.x); c.setAttribute("cy", p.y);
c.setAttribute("r", "3"); c.setAttribute("fill", "#a8b8c0");
svg.appendChild(c);
}
// Rects + short labels
const rects = [];
for (const id of Object.keys(LAYOUT)) {
if (byId[id] && byId[id].junction) continue; // skip junction nodes
const p = pos(id);
const cur = id === mod.id;
const isMini = byId[id].mini;
const nw = isMini ? 22 : NW;
const r = document.createElementNS("http://www.w3.org/2000/svg", "rect");
r.setAttribute("x", p.x - nw/2); r.setAttribute("y", p.y - NH/2);
r.setAttribute("width", nw); r.setAttribute("height", NH); r.setAttribute("rx", 3);
r.setAttribute("fill", cur ? "var(--accent-primary)" : "#fff");
r.setAttribute("stroke", cur ? "var(--accent-dark)" : (isMini ? "#bbd" : "#bbb"));
r.setAttribute("stroke-width", cur ? 1.5 : 1);
r.setAttribute("stroke-dasharray", isMini && !cur ? "2,2" : "none");
r.dataset.id = id;
if (!cur) {
r.addEventListener("click", () => travelTo(id));
r.addEventListener("mouseenter", (evt) => {
r.setAttribute("fill", "#daf0fb");
r.setAttribute("stroke", "var(--accent-primary)");
tip.textContent = byId[id].title;
tip.style.display = "block";
const minimap = document.getElementById("minimap");
const rect = minimap.getBoundingClientRect();
tip.style.top = (rect.top + p.y * (minimap.offsetHeight / H) - 14) + "px";
tip.style.left = (rect.left - tip.offsetWidth - 8) + "px";
});
r.addEventListener("mouseleave", () => {
r.setAttribute("fill", "#fff");
r.setAttribute("stroke", isMini ? "#bbd" : "#bbb");
tip.style.display = "none";
});
}
svg.appendChild(r);
rects.push({ id, p, nw, cur });
}
// Short-form labels (drawn on top of rects, pointer-events:none)
for (const { id, p, nw, cur } of rects) {
const abbr = byId[id].short || "";
if (!abbr) continue;
const t = document.createElementNS("http://www.w3.org/2000/svg", "text");
t.setAttribute("x", p.x);
t.setAttribute("y", p.y + 0.5);
t.setAttribute("text-anchor", "middle");
t.setAttribute("dominant-baseline", "middle");
t.setAttribute("font-size", "5");
t.setAttribute("fill", cur ? "#fff" : "#999");
t.setAttribute("pointer-events", "none");
t.setAttribute("font-family", "Raleway, sans-serif");
t.classList.add("node-abbr");
t.textContent = abbr;
svg.appendChild(t);
}
})();
/* travel animation */
let traveling = false;
function travelTo(target) {
if (traveling) return;
traveling = true;
track("minimap_travel", { from_module: mod.id, to_module: target });
const mini = document.getElementById("minimap");
mini.classList.add("traveling");
const hops = shortestPath(mod.id, target);
hops.forEach((id, i) => {
setTimeout(() => {
const r = document.querySelector(`#minimap-svg rect[data-id="${id}"]`);
if (r) r.classList.add("hop");
if (i === hops.length - 1)
setTimeout(() => { location.href = `module.html?id=${target}`; }, 280);
}, 140 * (i + 1));
});
}
/* ---------- language toggle ---------- */
function applyLang() {
const lang = getLang();
const S = STRINGS[lang];
document.documentElement.lang = lang;
document.getElementById("lang-btn").textContent = S.lang_btn;
document.getElementById("back-link").textContent = (lang === "fa" ? "→ بازگشت به نقشه" : "← back to the map");
document.getElementById("minimap-label").textContent = S.minimap_label;
renderHero();
renderSections();
renderNextPrev();
// Scroll to mode section
const modeEl = mode && STEPS_EN.includes(mode) ? document.getElementById(mode) : null;
if (modeEl && modeEl.scrollIntoView) {
setTimeout(() => modeEl.scrollIntoView({ behavior: "smooth" }), 80);
}
}
document.getElementById("lang-btn").addEventListener("click", () => {
const next = getLang() === "en" ? "fa" : "en";
setLang(next);
track("lang_toggle", { lang: next, module_id: mod.id });
applyLang();
});
/* ---------- scroll-highlight step nav ---------- */
function initObserver() {
if (mod.ref || typeof IntersectionObserver === "undefined") return;
const navLinks = document.querySelectorAll(".step-nav a");
const sections = [...STEPS_EN, "resources"];
const obs = new IntersectionObserver(entries => {
for (const e of entries) if (e.isIntersecting)
navLinks.forEach(l => l.classList.toggle("current", l.dataset.k === e.target.id));
}, { rootMargin: "-30% 0px -60% 0px" });
sections.forEach(k => { const el = document.getElementById(k); if (el) obs.observe(el); });
}
/* ---------- init ---------- */
applyLang();
initObserver();
</script>
</body>
</html>