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.
43 lines
1.5 KiB
43 lines
1.5 KiB
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
|