diff --git a/assets/css/frontend/widget-batch5.css b/assets/css/frontend/widget-batch5.css index e626266b..9f0ee489 100644 --- a/assets/css/frontend/widget-batch5.css +++ b/assets/css/frontend/widget-batch5.css @@ -409,24 +409,8 @@ .aksrt-bookmark-links__desc { font-size: 11px; color: var(--muted-2-color, #999); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } -/* Search keywords + history */ +/* Search keywords */ .aksrt-search-widget__keywords { margin-top: 10px; } -.aksrt-search-widget__field { position: relative; } -.aksrt-search-widget__history { - position: absolute; - z-index: 20; - top: calc(100% + 6px); - right: 0; - left: 0; - max-height: 240px; - overflow-y: auto; - padding: 10px; - border: 1px solid var(--border-color, rgba(0, 0, 0, .08)); - border-radius: var(--main-radius, 8px); - background: var(--main-bg-color, #fff); - box-shadow: 0 8px 24px rgba(0, 0, 0, .12); -} -.aksrt-search-widget__history[hidden] { display: none; } .aksrt-search-widget__kw-head { display: flex; align-items: center; @@ -440,15 +424,6 @@ margin-bottom: 6px; } .aksrt-search-widget__kw-head .aksrt-search-widget__kw-title { margin-bottom: 0; } -.aksrt-search-widget__history-clear { - border: 0; - background: transparent; - color: var(--muted-2-color, #999); - font-size: 12px; - cursor: pointer; - padding: 0; -} -.aksrt-search-widget__history-clear:hover { color: var(--color-primary, #3b82f6); } .aksrt-search-widget__kw-refresh { display: inline-flex; align-items: center; @@ -478,26 +453,6 @@ text-decoration: none; font-size: 12px; } -.aksrt-search-widget__history-list { display: grid; gap: 2px; } -.aksrt-search-widget__history-item { - display: block; - padding: 7px 8px; - border-radius: 6px; - color: inherit; - font-size: 13px; - line-height: 1.35; - text-decoration: none; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} -.aksrt-search-widget__history-item:hover, -.aksrt-search-widget__history-item:focus-visible { background: var(--surface-2, #f3f4f6); color: var(--color-primary, #3b82f6); } -.aksrt-search-widget__history-empty { - font-size: 12px; - color: var(--muted-2-color, #999); -} - /* Product list widgets (batch6) */ .aksrt-product-widget { margin-bottom: 8px; } .aksrt-product-widget__grid { diff --git a/assets/js/core/search.js b/assets/js/core/search.js index f16e0aa4..2d23a3c6 100644 --- a/assets/js/core/search.js +++ b/assets/js/core/search.js @@ -392,16 +392,6 @@ window.__aksrtOpenSearchPanel = function () { setOpen(true); }; window.__aksrtCloseSearchPanel = function () { setOpen(false); }; - // Sidebar / widget search history (zibll widget_ui_search show_history). - initWidgetSearchHistory({ - historyEnabled: historyEnabled, - readHistory: readHistory, - writeHistory: writeHistory, - requestHistorySync: requestHistorySync, - pushHistory: pushHistory, - getSearchType: getSearchType, - searchConfig: searchConfig, - }); initWidgetKeywordRefresh(); } @@ -465,133 +455,5 @@ }); } - function initWidgetSearchHistory(ctx) { - var panels = document.querySelectorAll("[data-aksrt-search-history]"); - if (!panels.length) return; - if (!ctx.historyEnabled) { - panels.forEach(function (el) { - el.hidden = true; - }); - return; - } - var activePanel = null; - - function escapeHtml(s) { - return String(s == null ? "" : s) - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/"/g, """); - } - - function close(panel) { - if (!panel) return; - panel.hidden = true; - var input = panel.parentElement ? panel.parentElement.querySelector('input[name="s"]') : null; - if (input) input.setAttribute("aria-expanded", "false"); - if (activePanel === panel) activePanel = null; - } - - function closeAll(except) { - panels.forEach(function (panel) { - if (panel !== except) close(panel); - }); - } - - function buildSearchUrl(form, keyword, type) { - var url = new URL(form.getAttribute("action") || window.location.href, window.location.href); - url.searchParams.set("s", keyword); - if (type) url.searchParams.set("aksrt_search_type", type); - return url.toString(); - } - - function paint(panel, items) { - var wrap = panel.querySelector("[data-aksrt-search-history-list]"); - var clearBtn = panel.querySelector("[data-aksrt-search-history-clear]"); - var form = panel.closest("form"); - var limit = parseInt(panel.getAttribute("data-history-limit"), 10); - var list = (Array.isArray(items) ? items : []).filter(function (item) { - return item && item.keyword; - }).slice(0, limit > 0 ? Math.min(limit, 8) : 8); - if (!wrap || !form || !list.length) { - if (clearBtn) clearBtn.hidden = true; - close(panel); - return; - } - if (clearBtn) clearBtn.hidden = false; - wrap.innerHTML = list.map(function (item) { - var keyword = String(item.keyword); - var type = item.type || "post"; - return ( - '' + escapeHtml(keyword) + "" - ); - }).join(""); - panel.hidden = false; - var input = panel.parentElement ? panel.parentElement.querySelector('input[name="s"]') : null; - if (input) input.setAttribute("aria-expanded", "true"); - } - - function load(panel) { - if (window.aksrtData && aksrtData.isLoggedIn) { - ctx.requestHistorySync("get", null, function (items) { - if (activePanel === panel) paint(panel, items); - }); - return; - } - if (activePanel === panel) paint(panel, ctx.readHistory()); - } - - panels.forEach(function (panel) { - var field = panel.parentElement; - var form = panel.closest("form"); - var input = field ? field.querySelector('input[name="s"]') : null; - if (!input || !form) return; - - function open() { - closeAll(panel); - activePanel = panel; - load(panel); - } - - input.addEventListener("focus", open); - input.addEventListener("click", open); - input.addEventListener("keydown", function (e) { - if (e.key === "Escape") { - close(panel); - input.focus(); - } - }); - form.addEventListener("submit", function () { - close(panel); - }); - panel.addEventListener("click", function (e) { - if (e.target.closest(".aksrt-search-widget__history-item")) close(panel); - }); - }); - - document.querySelectorAll("[data-aksrt-search-history-clear]").forEach(function (btn) { - btn.addEventListener("click", function (e) { - e.preventDefault(); - e.stopPropagation(); - var panel = btn.closest("[data-aksrt-search-history]"); - if (!panel) return; - if (window.aksrtData && aksrtData.isLoggedIn) { - ctx.requestHistorySync("save", [], function (items) { - paint(panel, items); - }); - return; - } - ctx.writeHistory([]); - paint(panel, []); - }); - }); - - document.addEventListener("pointerdown", function (e) { - if (activePanel && !activePanel.parentElement.contains(e.target)) close(activePanel); - }); - } - window.AksrtFrontend.register("aksrt-search-panel", function () { initSearchPanel(); }); })(); diff --git a/src/Widgets/SearchWidget.php b/src/Widgets/SearchWidget.php index 13244d10..affd5456 100644 --- a/src/Widgets/SearchWidget.php +++ b/src/Widgets/SearchWidget.php @@ -1,6 +1,6 @@ esc_html__('搜索框:热门关键词与搜索历史。', 'aksrt'), + 'description' => esc_html__('搜索框:热门关键词。', 'aksrt'), 'classname' => 'widget_aksrt_search', ]); } @@ -33,19 +33,14 @@ class SearchWidget extends \WP_Widget { $placeholder = aksrt_get_search_placeholder(); } $show_kw = !empty($instance['show_keywords']); - $show_history = !empty($instance['show_history']); $kw_title = sanitize_text_field((string) ($instance['keywords_title'] ?? __('热门搜索', 'aksrt'))); $keyword_limit = max(1, min(50, (int) ($instance['keyword_limit'] ?? 12))); - $history_limit = max(1, min(8, (int) ($instance['history_limit'] ?? 8))); // Affix helper (shared layer sidebar_affix). $affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => '']; $search_type = function_exists('aksrt_get_default_search_type') ? aksrt_get_default_search_type() : 'post'; - $history_enabled = function_exists('aksrt_search_history_enabled') - ? aksrt_search_history_enabled() - : true; $keywords = []; if ($show_kw) { @@ -96,30 +91,10 @@ class SearchWidget extends \WP_Widget { placeholder="" value="" autocomplete="off" - aria-haspopup="true" - aria-controls="-history" - aria-expanded="false" > - - - @@ -173,8 +148,7 @@ class SearchWidget extends \WP_Widget {

-
- +

-

- -

sanitize_text_field((string) ($new_instance['title'] ?? '')), 'placeholder' => sanitize_text_field((string) ($new_instance['placeholder'] ?? '')), 'show_keywords' => !empty($new_instance['show_keywords']) ? 1 : 0, - 'show_history' => !empty($new_instance['show_history']) ? 1 : 0, 'keywords_title' => sanitize_text_field((string) ($new_instance['keywords_title'] ?? '')), 'keywords' => sanitize_textarea_field((string) ($new_instance['keywords'] ?? '')), 'keyword_limit' => max(1, min(50, (int) ($new_instance['keyword_limit'] ?? 12))), - 'history_limit' => max(1, min(8, (int) ($new_instance['history_limit'] ?? 8))), ]); } }