You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.6 KiB
74 lines
2.6 KiB
import "./common.js";
|
|
import "./pagination.js";
|
|
//#region js/search.js
|
|
function initHotTags() {
|
|
$(".sr-hot__tag").on("click", function() {
|
|
const keyword = ($(this).attr("data-keyword") || $(this).text() || "").trim();
|
|
if (!keyword) return;
|
|
const $form = $(".sr-search");
|
|
$form.find(".s-search__input").val(keyword);
|
|
const form = $form.get(0);
|
|
if (!form) return;
|
|
if (typeof form.requestSubmit === "function") form.requestSubmit();
|
|
else form.submit();
|
|
});
|
|
}
|
|
function initFaqAccordion() {
|
|
$(".sr-list .f-item__trigger").on("click", function() {
|
|
const $item = $(this).closest(".f-item");
|
|
const willOpen = !$item.hasClass("is-open");
|
|
$(".sr-list .f-item.is-open").not($item).removeClass("is-open").find(".f-item__trigger").attr("aria-expanded", "false");
|
|
$item.toggleClass("is-open", willOpen);
|
|
$(this).attr("aria-expanded", willOpen ? "true" : "false");
|
|
});
|
|
}
|
|
function initVideoModal() {
|
|
const modal = document.getElementById("v-modal");
|
|
const video = document.getElementById("v-modal-video");
|
|
const titleEl = document.getElementById("v-modal-title");
|
|
if (!modal || !video || !titleEl) return;
|
|
let lastFocus = null;
|
|
const openModal = (src, title) => {
|
|
if (!src) return;
|
|
lastFocus = document.activeElement;
|
|
titleEl.textContent = title || t("video.play");
|
|
if (video.getAttribute("src") !== src) video.src = src;
|
|
modal.hidden = false;
|
|
document.body.style.overflow = "hidden";
|
|
if (window.lenis?.stop) window.lenis.stop();
|
|
video.play().catch(() => {});
|
|
modal.querySelector(".v-modal__close")?.focus();
|
|
};
|
|
const closeModal = () => {
|
|
video.pause();
|
|
video.removeAttribute("src");
|
|
video.load();
|
|
modal.hidden = true;
|
|
document.body.style.overflow = "";
|
|
if (window.lenis?.start) window.lenis.start();
|
|
if (lastFocus && typeof lastFocus.focus === "function") lastFocus.focus();
|
|
};
|
|
document.querySelectorAll(".sr-item--video [data-video-src]").forEach((card) => {
|
|
card.addEventListener("click", () => {
|
|
const title =
|
|
card.closest(".sr-item")?.querySelector(".sr-item__title")?.textContent?.trim() ||
|
|
card.getAttribute("aria-label")?.replace(/^(播放|Play)\s*[::]\s*/i, "").trim() ||
|
|
t("video.play");
|
|
openModal(card.getAttribute("data-video-src") || "", title);
|
|
});
|
|
});
|
|
modal.querySelectorAll("[data-v-modal-close]").forEach((el) => {
|
|
el.addEventListener("click", closeModal);
|
|
});
|
|
document.addEventListener("keydown", (e) => {
|
|
if (e.key === "Escape" && !modal.hidden) closeModal();
|
|
});
|
|
}
|
|
$(function() {
|
|
const q = new URLSearchParams(window.location.search).get("q")?.trim() || "";
|
|
if (q) $(".sr-search .s-search__input").val(q);
|
|
initHotTags();
|
|
initFaqAccordion();
|
|
initVideoModal();
|
|
});
|
|
//#endregion
|