feat(widget): simplify search and user card widgets
This commit is contained in:
1 parent
8a23a3d526
commit
1067b9717b
3 files changed
+118
-171
No files matched your search
@@ -434,6 +434,23 @@
|
||||
padding: 0;
|
||||
}
|
||||
.aksrt-search-widget__history-clear:hover { color: var(--color-primary, #3b82f6); }
|
||||
.aksrt-search-widget__kw-refresh {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background: transparent;
|
||||
color: var(--muted-2-color, #999);
|
||||
cursor: pointer;
|
||||
}
|
||||
.aksrt-search-widget__kw-refresh:hover,
|
||||
.aksrt-search-widget__kw-refresh:focus-visible { color: var(--color-primary, #3b82f6); }
|
||||
.aksrt-search-widget__kw-refresh.is-refreshing i { animation: aksrt-search-keyword-refresh .2s linear; }
|
||||
@keyframes aksrt-search-keyword-refresh { to { transform: rotate(360deg); } }
|
||||
.aksrt-search-widget__kw-list,
|
||||
.aksrt-search-widget__history-list { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.aksrt-search-widget__kw,
|
||||
@@ -450,8 +467,6 @@
|
||||
font-size: 12px;
|
||||
color: var(--muted-2-color, #999);
|
||||
}
|
||||
.aksrt-search-widget__more { margin-top: 8px; text-align: right; font-size: 12px; }
|
||||
.aksrt-search-widget__more a { color: var(--color-primary, #3b82f6); text-decoration: none; }
|
||||
|
||||
/* Product list widgets (batch6) */
|
||||
.aksrt-product-widget { margin-bottom: 8px; }
|
||||
|
||||
@@ -402,6 +402,67 @@
|
||||
getSearchType: getSearchType,
|
||||
searchConfig: searchConfig,
|
||||
});
|
||||
initWidgetKeywordRefresh();
|
||||
}
|
||||
|
||||
function initWidgetKeywordRefresh() {
|
||||
document.querySelectorAll("[data-aksrt-search-keywords]").forEach(function (list) {
|
||||
if (list.dataset.aksrtSearchKeywordsBound === "1") return;
|
||||
list.dataset.aksrtSearchKeywordsBound = "1";
|
||||
|
||||
var keywords;
|
||||
try {
|
||||
keywords = JSON.parse(list.getAttribute("data-keywords") || "[]");
|
||||
} catch (e) {
|
||||
keywords = [];
|
||||
}
|
||||
if (!Array.isArray(keywords) || !keywords.length) return;
|
||||
|
||||
keywords = keywords
|
||||
.map(function (keyword) { return String(keyword || "").trim(); })
|
||||
.filter(function (keyword, index, values) { return keyword && values.indexOf(keyword) === index; });
|
||||
var limit = Math.max(1, parseInt(list.getAttribute("data-keyword-limit") || "12", 10) || 12);
|
||||
var searchType = list.getAttribute("data-search-type") || "post";
|
||||
var searchUrl = list.getAttribute("data-search-url") || window.location.href;
|
||||
var refreshButton = list.parentElement
|
||||
? list.parentElement.querySelector("[data-aksrt-search-keyword-refresh]")
|
||||
: null;
|
||||
|
||||
function shuffledKeywords() {
|
||||
var shuffled = keywords.slice();
|
||||
for (var i = shuffled.length - 1; i > 0; i--) {
|
||||
var j = Math.floor(Math.random() * (i + 1));
|
||||
var current = shuffled[i];
|
||||
shuffled[i] = shuffled[j];
|
||||
shuffled[j] = current;
|
||||
}
|
||||
return shuffled.slice(0, limit);
|
||||
}
|
||||
|
||||
function renderKeywords() {
|
||||
list.replaceChildren();
|
||||
shuffledKeywords().forEach(function (keyword) {
|
||||
var link = document.createElement("a");
|
||||
var url = new URL(searchUrl, window.location.href);
|
||||
url.searchParams.set("s", keyword);
|
||||
url.searchParams.set("aksrt_search_type", searchType);
|
||||
link.className = "aksrt-search-widget__kw";
|
||||
link.href = url.toString();
|
||||
link.textContent = keyword;
|
||||
list.appendChild(link);
|
||||
});
|
||||
}
|
||||
|
||||
if (refreshButton) {
|
||||
refreshButton.addEventListener("click", function () {
|
||||
refreshButton.classList.add("is-refreshing");
|
||||
renderKeywords();
|
||||
window.setTimeout(function () {
|
||||
refreshButton.classList.remove("is-refreshing");
|
||||
}, 200);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initWidgetSearchHistory(ctx) {
|
||||
|
||||
Reference in new issue
Block a user