diff --git a/public/themes/dist_static/static/js/download.js b/public/themes/dist_static/static/js/download.js index 2b56146..248e195 100644 --- a/public/themes/dist_static/static/js/download.js +++ b/public/themes/dist_static/static/js/download.js @@ -18,10 +18,31 @@ $(function() { $("[data-dropdown]").prop("hidden", true); $("[data-dropdown-trigger]").removeClass("is-open").attr("aria-expanded", "false"); }; + const getActiveTabId = () => { + const $active = $(".d-tabs__item.is-active").first(); + const $group = $active.closest(".d-tabs__group"); + if ($group.length) { + const $activeChild = $group.find(".d-tabs__dropdown-item.is-active[data-tab]").first(); + if ($activeChild.length) return $activeChild.attr("data-tab") || ""; + } + return $active.attr("data-tab") || ""; + }; + const activateTabById = (tabId) => { + if (!tabId) return; + const $dropdownItem = $(`.d-tabs__dropdown-item[data-tab="${tabId}"]`).first(); + if ($dropdownItem.length) { + $dropdownItem.addClass("is-active").siblings().removeClass("is-active"); + const $trigger = $dropdownItem.closest(".d-tabs__group").find("[data-dropdown-trigger]"); + $trigger.find("span").text($dropdownItem.text()); + activateTab($trigger); + return; + } + const $target = $(`.d-tabs__item[data-tab="${tabId}"]`).first(); + if ($target.length) activateTab($target); + }; $(".d-tabs__item:not([data-dropdown-trigger])").on("click", function() { activateTab($(this)); closeDropdowns(); - $("[data-dropdown-trigger] span").text("样本手册"); }); $("[data-dropdown-trigger]").on("click", function() { const $btn = $(this); @@ -44,10 +65,20 @@ $(function() { $(document).on("click", function(event) { if (!$(event.target).closest(".d-tabs__group").length) closeDropdowns(); }); - const tabParam = new URLSearchParams(window.location.search).get("tab"); - if (tabParam) { - const $target = $(`[data-tab="${tabParam}"]`); - if ($target.length) activateTab($target); - } + $("[data-download-search]").on("submit", function(event) { + event.preventDefault(); + const params = new URLSearchParams(); + const keywords = $(this).find('[name="keywords"]').val().trim(); + const tabId = getActiveTabId(); + if (tabId) params.set("tab", tabId); + if (keywords) params.set("keywords", keywords); + const query = params.toString(); + window.location.href = query ? `${window.location.pathname}?${query}` : window.location.pathname; + }); + const searchParams = new URLSearchParams(window.location.search); + const tabParam = searchParams.get("tab"); + const keywordsParam = searchParams.get("keywords"); + if (keywordsParam) $("[data-download-search] [name='keywords']").val(keywordsParam); + if (tabParam) activateTabById(tabParam); }); //#endregion diff --git a/public/themes/website/1/zh/demo/download.html b/public/themes/website/1/zh/demo/download.html index 8b7617e..05f6801 100644 --- a/public/themes/website/1/zh/demo/download.html +++ b/public/themes/website/1/zh/demo/download.html @@ -1,6 +1,8 @@ +{php}$download_keywords = input('keywords', '');{/php} +
@@ -68,7 +70,7 @@ {/php} {if $count > 0}