Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
1484 lines (1333 loc) · 56.8 KB
/
Copy pathapp.js
File metadata and controls
1484 lines (1333 loc) · 56.8 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
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Register PWA Service Worker
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
// Determine the root relative path for registering sw.js
const isSubdir = window.location.pathname.includes("/kb/concepts/") || window.location.pathname.includes("/kb/software/") || window.location.pathname.includes("/kb/vendors/");
const swPath = isSubdir ? "../../sw.js" : "./sw.js";
navigator.serviceWorker
.register(swPath)
.then((reg) => {
console.log("[PWA] ServiceWorker registered with scope: ", reg.scope);
// Active check for updates
reg.update().catch(() => {});
if (reg.waiting) {
reg.waiting.postMessage({ type: "SKIP_WAITING" });
}
reg.addEventListener("updatefound", () => {
const newWorker = reg.installing;
if (newWorker) {
newWorker.addEventListener("statechange", () => {
if (newWorker.state === "installed" && navigator.serviceWorker.controller) {
newWorker.postMessage({ type: "SKIP_WAITING" });
}
});
}
});
})
.catch((err) => console.error("[PWA] ServiceWorker registration failed: ", err));
});
}
const navLinks = document.querySelectorAll("[data-nav]");
const current = document.body.getAttribute("data-page");
navLinks.forEach((link) => {
if (link.getAttribute("data-nav") === current) link.classList.add("active");
});
document.getElementById("footer-year")?.append(String(new Date().getFullYear()));
// ---- Mobile hamburger menu ----
// Use event delegation on document so the handler keeps working even if
// the hamburger / nav / overlay nodes are duplicated or re-rendered, and
// even if this script runs before any of those nodes are present.
function getTopbarNav() {
// Always re-query — the first `.nav` in DOM is the primary topbar nav.
return document.querySelector(".nav");
}
function getTopbarHamburger() {
return document.querySelector(".hamburger");
}
function getNavOverlay() {
return document.querySelector(".nav-overlay");
}
function toggleMenu(forceState) {
const nav = getTopbarNav();
const hb = getTopbarHamburger();
const ov = getNavOverlay();
if (!nav) return;
const willOpen = typeof forceState === "boolean"
? forceState
: !nav.classList.contains("active");
nav.classList.toggle("active", willOpen);
if (hb) hb.classList.toggle("active", willOpen);
if (ov) ov.classList.toggle("active", willOpen);
// Prevent background scroll when the drawer is open.
document.body.style.overflow = willOpen ? "hidden" : "";
}
// Delegated tap/click handler — survives DOM swaps, late hydration, etc.
function _navDelegatedHandler(ev) {
const target = ev.target;
if (!target || !target.closest) return;
if (target.closest(".hamburger")) {
ev.preventDefault();
toggleMenu();
return;
}
if (target.closest(".nav-close")) {
ev.preventDefault();
toggleMenu(false);
return;
}
if (target.closest(".nav-overlay")) {
toggleMenu(false);
return;
}
// If a nav link is clicked AND the drawer is open, close it after.
const link = target.closest(".nav .nav-link, .nav [data-nav]");
const navEl = getTopbarNav();
if (link && navEl && navEl.classList.contains("active")) {
toggleMenu(false);
}
}
document.addEventListener("click", _navDelegatedHandler);
document.addEventListener("touchend", function (ev) {
// Only handle the hamburger via touch to keep delays low; click handles the rest.
const t = ev.target;
if (t && t.closest && t.closest(".hamburger")) {
ev.preventDefault();
toggleMenu();
}
}, { passive: false });
// Close on Escape for keyboard users.
document.addEventListener("keydown", (ev) => {
if (ev.key === "Escape") {
const nav = getTopbarNav();
if (nav && nav.classList.contains("active")) toggleMenu(false);
}
});
(function initSiteNotice() {
const notice = document.getElementById("site-notice");
if (!notice) return;
const id = notice.dataset.noticeId || "default";
const key = `learncad-site-notice-${id}`;
try {
if (localStorage.getItem(key) === "1") {
notice.classList.add("is-dismissed");
return;
}
} catch {
/* ignore */
}
const closeBtn = notice.querySelector(".site-notice-close");
closeBtn?.addEventListener("click", () => {
notice.classList.add("is-dismissed");
try {
localStorage.setItem(key, "1");
} catch {
/* ignore */
}
});
})();
(function initCookieConsent() {
const banner = document.querySelector("[data-cookie-banner]");
if (!banner) return;
const PREFS_KEY = "learncad-cookie-prefs-v2";
const GA_ID = "G-ZV3YR72933";
/* ── helpers ─────────────────────────────────────────── */
function getPrefs() {
try {
const raw = localStorage.getItem(PREFS_KEY);
return raw ? JSON.parse(raw) : null;
} catch { return null; }
}
function savePrefs(prefs) {
try { localStorage.setItem(PREFS_KEY, JSON.stringify(prefs)); } catch { /* ignore */ }
}
function applyPrefs(prefs) {
if (!prefs) return;
if (!prefs.analytics) {
window["ga-disable-" + GA_ID] = true;
}
}
function dismiss() {
banner.classList.remove("is-visible");
banner.classList.add("is-dismissed");
setTimeout(() => {
banner.style.display = "none";
}, 300);
}
/* ── check existing prefs ────────────────────────────── */
const existing = getPrefs();
if (existing) {
applyPrefs(existing);
banner.style.display = "none";
return;
}
// Show banner smoothly without triggering document layout shift
requestAnimationFrame(() => {
banner.style.display = "block";
requestAnimationFrame(() => {
banner.classList.add("is-visible");
});
});
/* ── button references ───────────────────────────────── */
const btnAccept = banner.querySelector('[data-action="accept"]') || Array.from(banner.querySelectorAll("button")).find(b => b.textContent.trim().toLowerCase() === "accept");
const btnDeny = banner.querySelector('[data-action="deny"]') || Array.from(banner.querySelectorAll("button")).find(b => b.textContent.trim().toLowerCase() === "deny");
const btnCustomize = banner.querySelector('[data-action="customize"]') || Array.from(banner.querySelectorAll("button")).find(b => b.textContent.trim().toLowerCase() === "customize");
/* ── Accept All ──────────────────────────────────────── */
btnAccept?.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
const prefs = { analytics: true, functional: true };
savePrefs(prefs);
applyPrefs(prefs);
dismiss();
});
/* ── Deny All ────────────────────────────────────────── */
btnDeny?.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
const prefs = { analytics: false, functional: false };
savePrefs(prefs);
applyPrefs(prefs);
dismiss();
});
/* ── Customize panel (dynamic) ───────────────────────── */
let panel = null;
function buildPanel() {
panel = document.createElement("div");
panel.className = "cookie-prefs-panel";
panel.innerHTML =
'<div class="cookie-pref-row">' +
'<span class="cookie-pref-label">Analytics Cookies</span>' +
'<label class="cookie-toggle">' +
'<input type="checkbox" checked data-pref="analytics">' +
'<span class="cookie-toggle-slider"></span>' +
'</label>' +
'</div>' +
'<div class="cookie-pref-row">' +
'<span class="cookie-pref-label">Functional Cookies</span>' +
'<label class="cookie-toggle">' +
'<input type="checkbox" checked data-pref="functional">' +
'<span class="cookie-toggle-slider"></span>' +
'</label>' +
'</div>' +
'<button type="button" class="btn-cookie-primary cookie-save-prefs">Save Preferences</button>';
/* insert after .cookie-consent-actions */
const inner = banner.querySelector(".cookie-consent-inner");
if (inner) inner.appendChild(panel);
/* Save button */
panel.querySelector(".cookie-save-prefs")?.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
const prefs = {
analytics: panel.querySelector('[data-pref="analytics"]').checked,
functional: panel.querySelector('[data-pref="functional"]').checked
};
savePrefs(prefs);
applyPrefs(prefs);
dismiss();
});
}
btnCustomize?.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
if (!panel) buildPanel();
const isOpen = panel.classList.toggle("is-open");
btnCustomize.classList.toggle("is-active", isOpen);
});
/* ── Close (×) = Deny ────────────────────────────────── */
banner.querySelector(".cookie-consent-close")?.addEventListener("click", (e) => {
e.preventDefault();
const prefs = { analytics: false, functional: false };
savePrefs(prefs);
applyPrefs(prefs);
dismiss();
});
})();
(function initContactForm() {
const form = document.getElementById("site-contact-form") || document.getElementById("contact-form");
const status = document.getElementById("site-contact-form-status") || document.getElementById("contact-form-status");
if (!form || !status || form.dataset.bound === "1") return;
form.dataset.bound = "1";
const submitBtn = form.querySelector('button[type="submit"]');
form.addEventListener("submit", async (e) => {
e.preventDefault();
const nameInput = document.getElementById("contact-name");
const emailInput = document.getElementById("contact-email");
const topicInput = document.getElementById("contact-topic");
const messageInput = document.getElementById("contact-message");
const name = nameInput ? nameInput.value.trim() : "";
const email = emailInput ? emailInput.value.trim() : "";
const topic = topicInput ? topicInput.value : "general";
const message = messageInput ? messageInput.value.trim() : "";
if (!name || !email || !message) {
status.hidden = false;
status.style.color = "#dc2626";
status.textContent = "Please fill in all required fields (Name, Email, and Message).";
return;
}
if (submitBtn) {
submitBtn.disabled = true;
submitBtn.textContent = "Sending...";
}
status.hidden = false;
status.style.color = "var(--ink-text-soft)";
status.textContent = "Sending your message...";
try {
const response = await fetch("https://formsubmit.co/ajax/591611431@qq.com", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify({
name: name,
email: email,
topic: topic,
message: message,
_subject: `[Gstarcademy Contact] New message from ${name} (${topic})`,
_template: "table",
_captcha: "false"
})
});
const data = await response.json();
if (response.ok && (data.success === "true" || data.success === true || data.message)) {
status.hidden = false;
status.style.color = "#16a34a";
status.textContent = "✓ Thank you! Your message has been sent successfully. We will get back to you shortly.";
form.reset();
} else {
throw new Error(data.message || "Failed to send message");
}
} catch (err) {
console.error("[Contact Form Error]", err);
status.hidden = false;
status.style.color = "#dc2626";
status.textContent = "Failed to send message online. Please email us directly at will@blog.dwgfastview.com.";
} finally {
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.textContent = "Send Message";
}
}
});
})();(function initTutorialFilters() {
if (document.body.getAttribute("data-page") !== "tutorials") return;
const chips = document.querySelectorAll(".chips .chip");
const searchInput = document.querySelector(".search-row input");
const searchBtn = document.querySelector(".search-row button");
const tutorialItems = document.querySelectorAll(".tutorial-item");
const listContainer = document.querySelector(".list");
const state = {
software: "all",
task: "all",
level: "all",
price: "all",
search: ""
};
// 创建动态空状态占位
let noResultsEl = document.getElementById("tutorials-no-results");
if (!noResultsEl && listContainer) {
noResultsEl = document.createElement("div");
noResultsEl.id = "tutorials-no-results";
noResultsEl.style.display = "none";
noResultsEl.style.flexDirection = "column";
noResultsEl.style.alignItems = "center";
noResultsEl.style.justifyContent = "center";
noResultsEl.style.padding = "60px 40px";
noResultsEl.style.textAlign = "center";
noResultsEl.style.background = "var(--surface-soft)";
noResultsEl.style.border = "1px dashed var(--line-strong)";
noResultsEl.style.borderRadius = "20px";
noResultsEl.style.margin = "20px 0";
noResultsEl.style.gap = "12px";
noResultsEl.innerHTML = `
<span style="font-size: 40px;">🔍</span>
<h3 style="font-size: 1.25rem; font-weight: 700; color: var(--text-main); margin: 0;">No Tutorials Found</h3>
<p style="font-size: 14px; color: var(--text-muted); max-width: 380px; margin: 0 auto;">We couldn't find any lessons matching your filters. Try selecting a different software, clearing your search, or resetting pricing filters.</p>
<button type="button" class="btn btn-secondary" id="btn-reset-filters" style="margin-top: 8px; font-size: 13px; font-weight: 700;">Reset Filters</button>
`;
listContainer.appendChild(noResultsEl);
noResultsEl.querySelector("#btn-reset-filters").addEventListener("click", () => {
document.querySelectorAll(".chips").forEach(group => {
group.querySelectorAll(".chip").forEach(c => c.classList.remove("active"));
const allChip = group.querySelector('.chip[data-filter-value="all"]');
if (allChip) allChip.classList.add("active");
});
if (searchInput) searchInput.value = "";
state.software = "all";
state.task = "all";
state.level = "all";
state.price = "all";
state.search = "";
applyFilters();
});
}
// 1. Function to apply the current filter state
function applyFilters() {
let visibleCount = 0;
tutorialItems.forEach((item) => {
// Software filter (handles space-separated values)
const itemSoftwareAttr = item.getAttribute("data-software") || "";
const itemSoftwares = itemSoftwareAttr.split(/\s+/).filter(Boolean);
const matchesSoftware =
state.software === "all" || itemSoftwares.includes(state.software);
// Task filter (supports space-separated aliases)
const taskList = (item.getAttribute("data-task") || "").split(/\s+/).filter(Boolean);
const matchesTask =
state.task === "all" || taskList.includes(state.task);
// Level filter
const matchesLevel =
state.level === "all" || item.getAttribute("data-level") === state.level;
// Price filter
const matchesPrice =
state.price === "all" || item.getAttribute("data-price") === state.price;
// Search text filter (title, description, tags)
let matchesSearch = true;
if (state.search.trim()) {
const query = state.search.toLowerCase();
const title = item.querySelector("h3")?.textContent.toLowerCase() || "";
const desc = item.querySelector("p")?.textContent.toLowerCase() || "";
const tags = Array.from(item.querySelectorAll(".tag"))
.map((t) => t.textContent.toLowerCase())
.join(" ");
matchesSearch =
title.includes(query) || desc.includes(query) || tags.includes(query);
}
if (matchesSoftware && matchesTask && matchesLevel && matchesPrice && matchesSearch) {
visibleCount++;
// 先设为 display 展现,重置不带转换的初始值
if (item.style.display === "none") {
item.style.display = "";
item.style.opacity = "0";
item.style.transform = "translateY(12px)";
}
// 微小延迟触发 CSS 过渡
setTimeout(() => {
item.style.opacity = "1";
item.style.transform = "translateY(0)";
}, 20);
} else {
item.style.display = "none";
item.style.opacity = "0";
}
});
// 控制空状态显隐
if (noResultsEl) {
noResultsEl.style.display = visibleCount === 0 ? "flex" : "none";
}
}
// 2. Chip click handlers
chips.forEach((chip) => {
chip.addEventListener("click", () => {
const groupEl = chip.closest(".chips");
if (!groupEl) return;
const groupName = groupEl.getAttribute("data-filter-group");
const filterValue = chip.getAttribute("data-filter-value");
if (!groupName || !filterValue) return;
// Toggle active classes in this group
groupEl.querySelectorAll(".chip").forEach((c) => c.classList.remove("active"));
chip.classList.add("active");
// Update state and apply
state[groupName] = filterValue;
applyFilters();
});
});
// 3. Search input handler
if (searchInput) {
searchInput.addEventListener("input", (e) => {
state.search = e.target.value;
applyFilters();
});
// Also handle search button click
searchBtn?.addEventListener("click", () => {
state.search = searchInput.value;
applyFilters();
});
// Support enter key on search input
searchInput.addEventListener("keypress", (e) => {
if (e.key === "Enter") {
state.search = searchInput.value;
applyFilters();
}
});
}
// 4. URL query parameter parsing
function parseUrlParams() {
const params = new URLSearchParams(window.location.search);
// Check direct filter params (e.g. ?software=autocad)
["software", "task", "level", "price"].forEach((key) => {
const val = params.get(key);
if (val) {
const chip = document.querySelector(`.chips[data-filter-group="${key}"] .chip[data-filter-value="${val}"]`);
if (chip) {
// 清空同组 active 并高亮此项
const groupEl = chip.closest(".chips");
if (groupEl) {
groupEl.querySelectorAll(".chip").forEach(c => c.classList.remove("active"));
}
chip.classList.add("active");
state[key] = val;
}
}
});
// Check generic search query parameter ?q=
const query = params.get("q");
if (query) {
const lowerQuery = query.toLowerCase();
// Check if query directly maps to one of our software values
let mappedSoftware = null;
if (lowerQuery.includes("autocad")) mappedSoftware = "autocad";
else if (lowerQuery.includes("autodesk")) mappedSoftware = "autocad"; // fallback to AutoCAD
else if (lowerQuery.includes("revit")) mappedSoftware = "revit";
else if (lowerQuery.includes("fusion")) mappedSoftware = "fusion";
else if (lowerQuery.includes("solidworks")) mappedSoftware = "solidworks";
else if (lowerQuery.includes("catia")) mappedSoftware = "catia";
else if (lowerQuery.includes("dassault")) mappedSoftware = "solidworks";
else if (lowerQuery.includes("inventor")) mappedSoftware = "inventor";
else if (lowerQuery.includes("civil")) mappedSoftware = "civil3d";
else if (lowerQuery.includes("creo")) mappedSoftware = "creo";
else if (lowerQuery.includes("ptc")) mappedSoftware = "creo";
else if (lowerQuery.includes("siemens")) mappedSoftware = "nx";
else if (lowerQuery.includes("nx")) mappedSoftware = "nx";
else if (lowerQuery.includes("gstarcad")) mappedSoftware = "gstarcad";
else if (lowerQuery.includes("gstarsoft")) mappedSoftware = "gstarcad";
else if (lowerQuery.includes("rhino")) mappedSoftware = "rhino";
else if (lowerQuery.includes("blender")) mappedSoftware = "blender";
else if (lowerQuery.includes("freecad")) mappedSoftware = "freecad";
else if (lowerQuery.includes("sketchup")) mappedSoftware = "sketchup";
else if (lowerQuery.includes("archicad")) mappedSoftware = "archicad";
else if (lowerQuery.includes("onshape")) mappedSoftware = "onshape";
else if (lowerQuery.includes("ansys") || lowerQuery.includes("abaqus")) mappedSoftware = "ansys";
if (mappedSoftware) {
const chip = document.querySelector(`.chips[data-filter-group="software"] .chip[data-filter-value="${mappedSoftware}"]`);
if (chip) {
const groupEl = chip.closest(".chips");
if (groupEl) {
groupEl.querySelectorAll(".chip").forEach(c => c.classList.remove("active"));
}
chip.classList.add("active");
state.software = mappedSoftware;
}
} else {
// Just put it in the search input and filter
if (searchInput) {
searchInput.value = query;
state.search = query;
}
}
}
// 执行初次筛选
applyFilters();
}
// 5. Sorting logic
const sortSelect = document.getElementById("tutorial-sort-select");
function sortTutorials() {
if (!sortSelect || !listContainer) return;
const sortBy = sortSelect.value;
const items = Array.from(listContainer.querySelectorAll(".tutorial-item"));
items.sort((a, b) => {
if (sortBy === "duration-asc") {
const durA = parseInt(a.getAttribute("data-duration") || "0", 10);
const durB = parseInt(b.getAttribute("data-duration") || "0", 10);
return durA - durB;
} else if (sortBy === "duration-desc") {
const durA = parseInt(a.getAttribute("data-duration") || "0", 10);
const durB = parseInt(b.getAttribute("data-duration") || "0", 10);
return durB - durA;
} else if (sortBy === "difficulty-asc") {
const levels = { "beginner": 1, "beginner–intermediate": 1.5, "intermediate": 2, "pro": 3, "—": 2 };
const lvlA = levels[a.getAttribute("data-level")] || 2;
const lvlB = levels[b.getAttribute("data-level")] || 2;
return lvlA - lvlB;
} else if (sortBy === "difficulty-desc") {
const levels = { "beginner": 1, "beginner–intermediate": 1.5, "intermediate": 2, "pro": 3, "—": 2 };
const lvlA = levels[a.getAttribute("data-level")] || 2;
const lvlB = levels[b.getAttribute("data-level")] || 2;
return lvlB - lvlA;
} else if (sortBy === "newest") {
const dateA = a.getAttribute("data-published") || "";
const dateB = b.getAttribute("data-published") || "";
return dateB.localeCompare(dateA);
} else { // featured / highest rated
const ratA = parseFloat(a.getAttribute("data-rating") || "0");
const ratB = parseFloat(b.getAttribute("data-rating") || "0");
return ratB - ratA;
}
});
items.forEach(item => {
listContainer.appendChild(item);
});
}
if (sortSelect) {
sortSelect.addEventListener("change", sortTutorials);
}
// Run initial parsing on load
parseUrlParams();
sortTutorials();
})();
// --- Phase 9: Interactive Roadmap & Career Skill Tree Logic ---
(function initRoadmapSkillTree() {
const container = document.querySelector(".roadmap-container");
if (!container) return; // Only run on knowledge-roadmap.html
// Career Tracks Data
window.ROADMAP_DATA = {
bim: {
title: "BIM Coordinator (BIM 协调员)",
salary: "Est. Salary: $65,000 - $95,000 / yr",
software: "Revit, Navisworks, Solibri, IFC",
nodes: [
{
id: "bim",
title: "BIM Coordination",
difficulty: "Beginner",
level: 1,
desc: "Building Information Modeling (BIM) operates on active, object-based relational databases coordinate design data.",
why: "Essential core concept. BIM replaces basic 2D lines with smart parametric entities representing walls, doors, and piping.",
pitfall: "Do not treat BIM as just a 3D visual model; a 3D model without metadata is not a BIM model.",
wiki: "./kb/concepts/bim",
tutorials: "./tutorials?q=bim"
},
{
id: "revit",
title: "Revit",
difficulty: "Intermediate",
level: 2,
desc: "Autodesk's flagship BIM coordinator tool organizing structural, architectural and MEP models.",
why: "Revit is the primary authoring platform used by design offices for model coordination.",
pitfall: "Avoid loading high-polygon nested families directly, which degrades pan/zoom and synchronization speed.",
wiki: "./kb/software/revit",
tutorials: "./tutorials?q=revit"
},
{
id: "shared-coords",
title: "Shared Coordinates",
difficulty: "Intermediate",
level: 2,
desc: "Multi-disciplinary coordinate system ensuring all project elements align perfectly in global coordinate space.",
why: "Prevents drawing shift errors during multi-discipline assembly merges and clash checks.",
pitfall: "Never manually drag linked models to align them. Always acquire coordinates to maintain georeferenced accuracy.",
wiki: "./kb/concepts/shared-coordinates-revit",
tutorials: "./tutorials?q=coordinates"
},
{
id: "clash",
title: "Clash Detection",
difficulty: "Pro",
level: 3,
desc: "Diagnostic clash detection verifying physical geometry intersections between MEP and structural frameworks.",
why: "Crucial project deliverable. Saves millions in site reconstruction costs by finding overlaps pre-build.",
pitfall: "Do not run clash tests on the entire model without filter rules. This creates thousands of useless duplicate clash reports.",
wiki: "./kb/concepts/navisworks-clash-detection",
tutorials: "./tutorials?q=clash"
},
{
id: "ifc",
title: "IFC Export",
difficulty: "Pro",
level: 3,
desc: "Industry Foundation Classes (IFC) data export mapping drawing entities to open-standard definitions.",
why: "Critical for openBIM coordination, letting Revit, Bentley, and ArchiCAD models federate cleanly.",
pitfall: "Always specify the required IFC Schema version in the BEP, as incorrect export settings strip custom parameters.",
wiki: "./kb/concepts/ifc-export-revit",
tutorials: "./tutorials?q=ifc"
}
],
links: [
{ from: "bim", to: "revit" },
{ from: "bim", to: "shared-coords" },
{ from: "revit", to: "clash" },
{ from: "shared-coords", to: "clash" },
{ from: "clash", to: "ifc" }
]
},
mcad: {
title: "Mechanical Design Engineer (机械设计工程师)",
salary: "Est. Salary: $70,000 - $105,000 / yr",
software: "SOLIDWORKS, Autodesk Inventor, CATIA",
nodes: [
{
id: "parametrics",
title: "Parametric Constraints",
difficulty: "Beginner",
level: 1,
desc: "Mathematical dimension and relationship rules governing sketch behavior (tangency, concentricity).",
why: "Foundation of mechanical solid modeling. Lets designers change dimensions and automatically update parts.",
pitfall: "Avoid over-constraining sketch geometries; doing so locks relations and triggers parametric solver conflicts.",
wiki: "./kb/concepts/parametric-constraints",
tutorials: "./tutorials?q=constraints"
},
{
id: "solidworks",
title: "SOLIDWORKS",
difficulty: "Intermediate",
level: 2,
desc: "Industry standard solid modeler utilizing parametric feature trees and assembly constraints.",
why: "The most widely deployed mid-range MCAD software for industrial product design.",
pitfall: "Never rename CAD part files directly in Windows Explorer; doing so breaks mates and assembly links.",
wiki: "./kb/software/solidworks",
tutorials: "./tutorials?q=solidworks"
},
{
id: "brep",
title: "B-Rep Modeling",
difficulty: "Intermediate",
level: 2,
desc: "Boundary Representation kernels maintaining model topology via mathematical faces, edges, and vertices.",
why: "Understanding B-Rep prevents solver failures and zero-thickness geometry regeneration errors.",
pitfall: "Avoid creating zero-thickness geometries or self-intersecting boundary loops, which crash feature regeneration.",
wiki: "./kb/concepts/intelligent-objects",
tutorials: "./tutorials?q=modeling"
},
{
id: "assembly",
title: "MCAD Assembly",
difficulty: "Pro",
level: 3,
desc: "Assembling discrete parts together using kinematic mate conditions (coincident, concentric, parallel).",
why: "Enables designers to verify fits, tolerances, clearances, and run mechanical animations.",
pitfall: "Never create circular mate references in assemblies. They trigger rebuild loops and slow performance.",
wiki: "./kb/concepts/skeleton-creo",
tutorials: "./tutorials?q=assembly"
},
{
id: "mbd",
title: "Model-Based Definition",
difficulty: "Pro",
level: 3,
desc: "Injecting manufacturing dimensions and product specifications (GD&T) directly into 3D solid profiles.",
why: "Eliminates the need for tedious 2D drawing sheets by using rich digital metadata.",
pitfall: "Do not skip datum references in GD&T tolerances. Coordinate tolerance ranges must be tied to physical datum frames.",
wiki: "./kb/concepts/model-based-definition-solidworks",
tutorials: "./tutorials?q=mbd"
}
],
links: [
{ from: "parametrics", to: "solidworks" },
{ from: "parametrics", to: "brep" },
{ from: "solidworks", to: "assembly" },
{ from: "brep", to: "assembly" },
{ from: "assembly", to: "mbd" }
]
},
civil: {
title: "Civil Infrastructure Engineer (市政/土木工程师)",
salary: "Est. Salary: $68,000 - $100,000 / yr",
software: "Civil 3D, Infraworks, LandXML",
nodes: [
{
id: "surfaces",
title: "Surfaces & Grading",
difficulty: "Beginner",
level: 1,
desc: "Creating digital terrain models (DTM) using triangles (TIN) representing topography.",
why: "Foundation of all civil sites. Surfaces calculate precise cut-and-fill volumes.",
pitfall: "Do not build surfaces using too many dense points without filtering. Unfiltered raw files cause massive file lag.",
wiki: "./kb/concepts/surfaces-civil-3d",
tutorials: "./tutorials?q=surfaces"
},
{
id: "civil3d",
title: "Civil 3D",
difficulty: "Intermediate",
level: 2,
desc: "Autodesk's land development platform built on top of the AutoCAD drafting engine.",
why: "The primary tool for civil drawings, grading, and road network designs.",
pitfall: "Avoid working in un-projected drawing spaces. Always establish a coordinate projection zone before drawing.",
wiki: "./kb/software/civil-3d",
tutorials: "./tutorials?q=civil"
},
{
id: "alignments",
title: "Alignments & Profiles",
difficulty: "Intermediate",
level: 2,
desc: "Horizontal road centerlines (alignments) paired with vertical elevation grids (profiles).",
why: "Defines the 3D pathway coordinates for highways, pipelines, and rail tracks.",
pitfall: "Do not edit horizontal alignments manually by moving vertex points without checking curve design speed rules.",
wiki: "./kb/concepts/profiles-civil-3d",
tutorials: "./tutorials?q=profile"
},
{
id: "corridors",
title: "Corridor Modeling",
difficulty: "Pro",
level: 3,
desc: "Sweeping road cross-sections (assemblies) along a 3D alignment and profile path.",
why: "Creates rich 3D road models with dynamic shoulders, daylight grading, and cut limits.",
pitfall: "Never build corridor surfaces without boundary settings. Unbounded surfaces will cross corridor limit lines.",
wiki: "./kb/concepts/subassembly-civil-3d",
tutorials: "./tutorials?q=corridor"
},
{
id: "landxml",
title: "LandXML Exchange",
difficulty: "Pro",
level: 3,
desc: "Open standard file format transferring surfaces, alignments, and parcels to survey equipment.",
why: "Essential for site deployment. Connects designer offices directly to GPS grading hardware.",
pitfall: "Ensure coordinate unit projection settings are correct before exporting LandXML; wrong units shift site coordinates.",
wiki: "./kb/concepts/pressure-networks-civil-3d",
tutorials: "./tutorials?q=xml"
}
],
links: [
{ from: "surfaces", to: "civil3d" },
{ from: "surfaces", to: "alignments" },
{ from: "civil3d", to: "corridors" },
{ from: "alignments", to: "corridors" },
{ from: "corridors", to: "landxml" }
]
},
draft: {
title: "2D Drafting & Standard Specialist (CAD 制图专家)",
salary: "Est. Salary: $50,000 - $75,000 / yr",
software: "AutoCAD, GstarCAD, ZWCAD",
nodes: [
{
id: "layer",
title: "Layer Strategy",
difficulty: "Beginner",
level: 1,
desc: "Organizing DWG assets by layers with strict color, linetype, and viewport visibility properties.",
why: "Basic hygiene of all drawing files. Structured layering keeps drawings readable.",
pitfall: "Avoid drawing elements directly on Layer 0. Layer 0 should only be used to create blocks.",
wiki: "./kb/concepts/layer",
tutorials: "./tutorials?q=layer"
},
{
id: "xref",
title: "Xrefs & Blocks",
difficulty: "Intermediate",
level: 2,
desc: "Linking external DWG files (Xrefs) and grouping recurring items as block references.",
why: "Crucial for team drafting. Keeps parent files lightweight by referencing background plates.",
pitfall: "Avoid using absolute paths for Xrefs. Absolute paths break reference links when files move between servers.",
wiki: "./kb/concepts/xref",
tutorials: "./tutorials?q=xref"
},
{
id: "alias",
title: "Command Aliases",
difficulty: "Intermediate",
level: 2,
desc: "Keyboard shortcuts mapping fast inputs (L for LINE, CO for COPY) into the CAD console.",
why: "Draftsman speed enhancer. Minimizes reliance on mouse clicks, boosting efficiency.",
pitfall: "Do not map too many custom command aliases. It makes collaborating on other work PCs extremely difficult.",
wiki: "./kb/concepts/command-alias",
tutorials: "./tutorials?q=alias"
},
{
id: "plot",
title: "Plot & Layout Setup",
difficulty: "Pro",
level: 3,
desc: "Configuring paperspace layouts, viewports, annotation scaling, and CTB plot styles.",
why: "Guarantees drawings print accurately to scale without overlapping lines.",
pitfall: "Never override object line thicknesses manually in layout space; always control them via CTB styles.",
wiki: "./kb/concepts/plot-style",
tutorials: "./tutorials?q=plot"
},
{
id: "merge",
title: "Drawing Merge & Compare",
difficulty: "Pro",
level: 3,
desc: "Auditing revision changes and merging changes from external coordinates cleanly.",
why: "Crucial for coordination. Ensures concurrent edits merge without database corruption.",
pitfall: "Avoid merging drawings with different base units or scale factors, which corrupts coordinate database scales.",
wiki: "./kb/concepts/drawing-merge",
tutorials: "./tutorials?q=compare"
}
],
links: [
{ from: "layer", to: "xref" },
{ from: "layer", to: "alias" },
{ from: "xref", to: "plot" },
{ from: "alias", to: "plot" },
{ from: "plot", to: "merge" }
]
}
};
const ROADMAP_DATA = window.ROADMAP_DATA;
// State Management
let activeTrack = "bim";
let masteredProgress = JSON.parse(localStorage.getItem("gstarcademy_roadmap_progress")) || {
bim: [],
mcad: [],
civil: [],
draft: []
};
// Ensure default structures are safe
["bim", "mcad", "civil", "draft"].forEach(t => {
if (!masteredProgress[t]) masteredProgress[t] = [];
});
// UI Element Selectors
const trackTabs = document.querySelectorAll(".roadmap-track-tab");
const trackTitle = document.getElementById("track-title");
const trackSalary = document.getElementById("track-salary");
const trackSoftware = document.getElementById("track-software");
const progressPercent = document.getElementById("progress-percent");
const progressFill = document.getElementById("progress-fill");
const levels = {
1: document.getElementById("level-1"),
2: document.getElementById("level-2"),
3: document.getElementById("level-3")
};
const inspectTitle = document.getElementById("inspect-title");
const inspectDifficulty = document.getElementById("inspect-difficulty");
const inspectDesc = document.getElementById("inspect-desc");
const inspectWhy = document.getElementById("inspect-why");
const btnWiki = document.getElementById("btn-inspect-wiki");
const btnTuts = document.getElementById("btn-inspect-tutorials");
const btnReset = document.getElementById("btn-reset-track");
const inspectBackdrop = document.getElementById("inspect-backdrop");
const btnInspectClose = document.getElementById("btn-inspect-close");
const inspectPitfall = document.getElementById("inspect-pitfall");
// Render nodes for active track
function renderTree() {
// Clear stages
levels[1].innerHTML = "";
levels[2].innerHTML = "";
levels[3].innerHTML = "";
const track = ROADMAP_DATA[activeTrack];
// Set Header details
trackTitle.textContent = track.title;
trackSalary.innerHTML = `💼 <strong>Est. Salary:</strong> ${track.salary}`;
trackSoftware.innerHTML = `🛠️ <strong>Stack:</strong> ${track.software}`;
// Render Nodes
track.nodes.forEach(node => {
const nodeSlug = node.wiki ? node.wiki.split("/").pop().replace("", "") : "";
let isMastered = masteredProgress[activeTrack].includes(node.id);
// Sync from quiz mastery
let masteredConcepts = [];
try {
masteredConcepts = JSON.parse(localStorage.getItem("gstarcademy_concept_mastery")) || [];
} catch (e) {}
if (nodeSlug && masteredConcepts.includes(nodeSlug)) {
isMastered = true;
if (!masteredProgress[activeTrack].includes(node.id)) {
masteredProgress[activeTrack].push(node.id);
localStorage.setItem("gstarcademy_roadmap_progress", JSON.stringify(masteredProgress));
}
}
const card = document.createElement("div");
card.className = "skill-node" + (isMastered ? " mastered" : "");
card.setAttribute("data-node-id", node.id);
card.innerHTML = `
<div class="skill-node-checkbox"></div>
<div class="skill-node-info">
<span class="skill-node-title">${node.title}</span>
<span class="skill-node-difficulty">${isMastered ? "✓ Mastered" : node.difficulty}</span>
</div>