feat(frontend): restore Zibll-like global search panel

Render full search overlay with types/history/suggestions for tabbar
and desktop header toggle. Open panel on all viewports (not mobile-only)
and wire data-toggle-class/.navbar-search compatibility hooks.
This commit is contained in:
2026-07-11 18:57:41 +08:00
parent 752b9a93bf
commit bf8b125f3b
5 changed files with 257 additions and 20 deletions
+49 -17
View File
@@ -248,24 +248,33 @@
}, 180);
}
function isMobileSearchMode() {
return window.innerWidth < 768 && !!mobileOverlay;
}
function setOpen(open) {
if (isMobileSearchMode()) {
if (open) {
mobileOverlay.removeAttribute("hidden");
document.body.classList.add("tabbar-search-open");
if (mobileInput) mobileInput.focus();
if (historyEnabled) renderHistory();
if (suggestionsEnabled) requestSuggestions();
} else {
mobileOverlay.setAttribute("hidden", "");
document.body.classList.remove("tabbar-search-open");
if (suggestionsSection) suggestionsSection.hidden = true;
if (!mobileOverlay) return;
var toggles = document.querySelectorAll(".main-search-btn, .nav-search-toggle, [data-aksrt-open-search]");
if (open) {
mobileOverlay.removeAttribute("hidden");
mobileOverlay.setAttribute("aria-hidden", "false");
mobileOverlay.classList.add("is-open", "show");
document.body.classList.add("tabbar-search-open");
if (mobileInput) {
try { mobileInput.focus(); } catch (e) {}
}
return;
if (historyEnabled) {
if (aksrtData.isLoggedIn) {
requestHistorySync("get", null, function (items) { renderHistory(items); });
} else {
renderHistory();
}
}
if (suggestionsEnabled) requestSuggestions();
toggles.forEach(function (btn) { btn.setAttribute("aria-expanded", "true"); });
} else {
mobileOverlay.setAttribute("hidden", "");
mobileOverlay.setAttribute("aria-hidden", "true");
mobileOverlay.classList.remove("is-open", "show");
document.body.classList.remove("tabbar-search-open");
if (suggestionsSection) suggestionsSection.hidden = true;
toggles.forEach(function (btn) { btn.setAttribute("aria-expanded", "false"); });
}
}
@@ -280,6 +289,22 @@
});
}
document.querySelectorAll(".main-search-btn, .nav-search-toggle, [data-aksrt-open-search]").forEach(function (btn) {
btn.addEventListener("click", function (e) {
e.preventDefault();
setOpen(true);
});
});
// Zibll-compatible data-toggle-class for .navbar-search
document.addEventListener("click", function (e) {
var toggle = e.target.closest('[data-toggle-class][data-target=".navbar-search"], [data-toggle-class][data-target=".main-search"]');
if (!toggle) return;
e.preventDefault();
var isOpen = mobileOverlay && !mobileOverlay.hasAttribute("hidden");
setOpen(!isOpen);
});
if (historyClear) {
historyClear.addEventListener("click", function () {
if (aksrtData.isLoggedIn) {
@@ -317,6 +342,13 @@
});
});
// Panel type buttons should also sync desktop/drawer forms
document.querySelectorAll("#tabbar-search-types [data-search-type], [data-aksrt-search-form] [data-search-type]").forEach(function (button) {
button.addEventListener("click", function () {
setSearchType(button.getAttribute("data-search-type") || "post");
});
});
if (mobileInput) {
mobileInput.addEventListener("input", requestSuggestions);
}
@@ -351,7 +383,7 @@
}
document.addEventListener("keydown", function (e) {
if (e.key === "Escape" && isMobileSearchMode() && mobileOverlay && !mobileOverlay.hasAttribute("hidden")) {
if (e.key === "Escape" && mobileOverlay && !mobileOverlay.hasAttribute("hidden")) {
setOpen(false);
}
});