|
|
@ -102,6 +102,63 @@ $(function() { |
|
|
$item.attr("data-expanded", String(!isExpanded)); |
|
|
$item.attr("data-expanded", String(!isExpanded)); |
|
|
$(this).attr("aria-expanded", String(!isExpanded)); |
|
|
$(this).attr("aria-expanded", String(!isExpanded)); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 语言切换:默认语言无前缀,其它语言用 /{lang}/ 前缀(与 getLang 一致)
|
|
|
|
|
|
(function initLangSwitch() { |
|
|
|
|
|
const ALLOWED = ["zh", "tc", "en", "ja", "de", "fa", "id", "th", "ru"]; |
|
|
|
|
|
const defaultLang = |
|
|
|
|
|
document.querySelector(".site-header__lang")?.getAttribute("data-lang-default") || "zh"; |
|
|
|
|
|
|
|
|
|
|
|
const getPathLang = () => { |
|
|
|
|
|
const seg = location.pathname.replace(/^\//, "").split("/")[0] || ""; |
|
|
|
|
|
return ALLOWED.includes(seg) ? seg : defaultLang; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const buildLangUrl = (targetLang) => { |
|
|
|
|
|
const parts = location.pathname.replace(/^\//, "").split("/").filter(Boolean); |
|
|
|
|
|
if (parts.length && ALLOWED.includes(parts[0])) parts.shift(); |
|
|
|
|
|
const rest = parts.join("/"); |
|
|
|
|
|
let path; |
|
|
|
|
|
if (!targetLang || targetLang === defaultLang) { |
|
|
|
|
|
path = rest ? `/${rest}` : "/"; |
|
|
|
|
|
} else { |
|
|
|
|
|
path = rest ? `/${targetLang}/${rest}` : `/${targetLang}/`; |
|
|
|
|
|
} |
|
|
|
|
|
return path + location.search + location.hash; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const goLang = (targetLang) => { |
|
|
|
|
|
if (!targetLang) return; |
|
|
|
|
|
const cur = getPathLang(); |
|
|
|
|
|
const uiCur = cur === "en" ? "en" : "zh"; |
|
|
|
|
|
if (targetLang === uiCur || targetLang === cur) return; |
|
|
|
|
|
location.href = buildLangUrl(targetLang); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const syncActive = () => { |
|
|
|
|
|
const uiLang = getPathLang() === "en" ? "en" : "zh"; |
|
|
|
|
|
$(".site-header__lang [data-lang]").removeClass("site-header__lang-active"); |
|
|
|
|
|
$(`.site-header__lang [data-lang="${uiLang}"]`).addClass("site-header__lang-active"); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
$(document).on("click", ".site-header__lang [data-lang]", function(e) { |
|
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
e.stopPropagation(); |
|
|
|
|
|
goLang(this.getAttribute("data-lang")); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$(document).on("click", ".site-header__lang", function(e) { |
|
|
|
|
|
if ($(e.target).closest("[data-lang]").length) return; |
|
|
|
|
|
goLang(getPathLang() === "en" ? "zh" : "en"); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$(document).on("click", ".site-header__extra-btn.lang, .mask-header__icon-btn.lang", function(e) { |
|
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
goLang(getPathLang() === "en" ? "zh" : "en"); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
syncActive(); |
|
|
|
|
|
})(); |
|
|
// $(".section-contact-form").on("submit", function(e) {
|
|
|
// $(".section-contact-form").on("submit", function(e) {
|
|
|
// e.preventDefault();
|
|
|
// e.preventDefault();
|
|
|
// const $form = $(this);
|
|
|
// const $form = $(this);
|
|
|
|