4 changed files with 99 additions and 3 deletions
-
30public/themes/dist_static/static/js/search.js
-
2public/themes/website/1/zh/demo/components/header.html
-
35public/themes/website/1/zh/demo/search.html
-
35public/themes/website/1/zh/demo/single_search.html
@ -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
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue