-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
96 lines (89 loc) · 3.03 KB
/
script.js
File metadata and controls
96 lines (89 loc) · 3.03 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
// Copy button
const copyBtn = document.getElementById("copyBtn");
const codeBlock = document.getElementById("codeBlock");
const year = document.getElementById("year");
if (year) year.textContent = String(new Date().getFullYear());
// Mobile nav: hamburger toggle
const navToggle = document.getElementById("navToggle");
const navInner = document.querySelector(".nav__inner");
if (navToggle && navInner) {
navToggle.addEventListener("click", function () {
var open = navInner.classList.toggle("nav--open");
navToggle.setAttribute("aria-expanded", open);
});
// Close menu when clicking a link (for SPA-like close after navigate)
var menuWrap = navInner.querySelector(".nav__menu-wrap");
if (menuWrap) {
menuWrap.addEventListener("click", function (e) {
if (e.target.closest("a")) {
navInner.classList.remove("nav--open");
navToggle.setAttribute("aria-expanded", "false");
}
});
}
}
// Mobile: "项目" dropdown click-to-toggle (instead of hover)
function initNavDropdownMobile() {
var dropbtn = document.querySelector(".nav__dropdown .nav__dropbtn");
var dropdown = document.querySelector(".nav__dropdown");
if (!dropbtn || !dropdown) return;
dropbtn.addEventListener("click", function (e) {
if (window.innerWidth > 768) return;
e.preventDefault();
dropdown.classList.toggle("is-open");
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initNavDropdownMobile);
} else {
initNavDropdownMobile();
}
// Community members: duplicate items for seamless auto-scroll
const communityTrack = document.getElementById("communityTrack");
if (communityTrack) {
const items = communityTrack.innerHTML;
communityTrack.insertAdjacentHTML("beforeend", items);
}
// Overview diagram: language-specific asset (index.html)
function updateOverviewImage() {
var img = document.getElementById("overviewImg");
if (!img) return;
var lang =
typeof window.ruyiaiLang !== "undefined" && window.ruyiaiLang === "en"
? "en"
: "zh";
img.src =
lang === "en"
? "./assets/ruyiai-overview_en.png"
: "./assets/ruyiai-overview.png";
if (typeof window.ruyiaiGetText === "function") {
img.alt = window.ruyiaiGetText("hero.overviewImgAlt");
}
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", updateOverviewImage);
} else {
updateOverviewImage();
}
window.addEventListener("languagechange", updateOverviewImage);
copyBtn?.addEventListener("click", async () => {
const text = codeBlock?.innerText || "";
try {
await navigator.clipboard.writeText(text);
const t = copyBtn.querySelector(".copy__text");
if (t) t.textContent = "Copied!";
copyBtn.disabled = true;
setTimeout(() => {
if (t) t.textContent = "Copy";
copyBtn.disabled = false;
}, 1200);
} catch {
// fallback
const ta = document.createElement("textarea");
ta.value = text;
document.body.appendChild(ta);
ta.select();
document.execCommand("copy");
document.body.removeChild(ta);
}
});