diff --git a/public/themes/dist_static/static/js/search.js b/public/themes/dist_static/static/js/search.js index 674b72f..1ceb3ca 100644 --- a/public/themes/dist_static/static/js/search.js +++ b/public/themes/dist_static/static/js/search.js @@ -1,13 +1,43 @@ import "./common.js"; import "./pagination.js"; //#region js/search.js +function matchItem($item, type) { + const itemType = $item.attr("data-type") || ""; + return type === "all" || itemType === type; +} +function updateCounts($items) { + ["all", "product", "solution", "news", "faq"].forEach((type) => { + const count = $items.filter((_, el) => matchItem($(el), type)).length; + $(`[data-count="${type}"]`).text(String(count)); + }); +} +function applyFilter() { + const type = $(".sr-tabs__item.is-active").attr("data-type") || "all"; + const $items = $(".sr-item"); + let visible = 0; + $items.each(function() { + const show = matchItem($(this), type); + this.hidden = !show; + if (show) visible += 1; + }); + updateCounts($items); + const $empty = $(".sr-tabs-empty"); + if ($empty.length) $empty.prop("hidden", visible > 0 || !$items.length); +} $(function() { const q = new URLSearchParams(window.location.search).get("q")?.trim() || ""; if (q) $(".sr-search .s-search__input").val(q); + $(".sr-tabs__item").on("click", function() { + const $btn = $(this); + $btn.addClass("is-active").attr("aria-selected", "true"); + $btn.siblings(".sr-tabs__item").removeClass("is-active").attr("aria-selected", "false"); + applyFilter(); + }); $(".sr-hot__tag").on("click", function() { const keyword = $(this).attr("data-keyword") || $(this).text().trim(); $(".sr-search .s-search__input").val(keyword); $(".sr-search").trigger("submit"); }); + if ($(".sr-tabs").length) applyFilter(); }); //#endregion diff --git a/public/themes/website/1/zh/demo/components/header.html b/public/themes/website/1/zh/demo/components/header.html index 08d1440..a1cc56d 100644 --- a/public/themes/website/1/zh/demo/components/header.html +++ b/public/themes/website/1/zh/demo/components/header.html @@ -164,7 +164,7 @@