v0.1.40 홈 피드 및 문서 버전 정리
Made-with: Cursor
This commit is contained in:
@@ -197,7 +197,7 @@
|
||||
function renderSearchResults(keyword) {
|
||||
var normalized = keyword.trim().toLowerCase();
|
||||
if (!normalized) {
|
||||
searchResults.innerHTML = '<p class="search-modal__hint">Start typing to filter visible posts, tags, and authors in the current page.</p>';
|
||||
searchResults.innerHTML = '<p class="search-modal__hint">현재 페이지에 표시되는 게시물, 태그 및 작성자를 필터링하려면 입력을 시작하세요.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@
|
||||
});
|
||||
|
||||
if (!items.length) {
|
||||
searchResults.innerHTML = '<p class="search-empty">No matching items in the current view.</p>';
|
||||
searchResults.innerHTML = '<p class="search-empty">현재 보기에 일치하는 항목이 없습니다.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -258,4 +258,84 @@
|
||||
toggleSearch(false);
|
||||
}
|
||||
});
|
||||
|
||||
function updateLoadMoreState(pagination, nextUrl, loading) {
|
||||
var trigger = pagination.querySelector("[data-load-more-trigger]");
|
||||
if (!trigger) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!nextUrl) {
|
||||
pagination.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
pagination.dataset.nextUrl = nextUrl;
|
||||
trigger.disabled = !!loading;
|
||||
trigger.textContent = loading ? "Loading..." : "Load More";
|
||||
pagination.classList.toggle("is-loading", !!loading);
|
||||
}
|
||||
|
||||
function initializeLoadMore(root) {
|
||||
var pagination = root.querySelector("[data-load-more-pagination]");
|
||||
var list = root.querySelector("[data-load-more-list]");
|
||||
|
||||
if (!pagination || !list || pagination.dataset.bound === "true") {
|
||||
return;
|
||||
}
|
||||
|
||||
var trigger = pagination.querySelector("[data-load-more-trigger]");
|
||||
if (!trigger) {
|
||||
return;
|
||||
}
|
||||
|
||||
pagination.dataset.bound = "true";
|
||||
|
||||
trigger.addEventListener("click", function () {
|
||||
var nextUrl = pagination.dataset.nextUrl;
|
||||
|
||||
if (!nextUrl || pagination.classList.contains("is-loading")) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateLoadMoreState(pagination, nextUrl, true);
|
||||
|
||||
fetch(nextUrl, {
|
||||
headers: {
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
}
|
||||
})
|
||||
.then(function (response) {
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to load more posts");
|
||||
}
|
||||
|
||||
return response.text();
|
||||
})
|
||||
.then(function (html) {
|
||||
var parser = new DOMParser();
|
||||
var documentFragment = parser.parseFromString(html, "text/html");
|
||||
var nextRoot = documentFragment.querySelector("[data-load-more-root]");
|
||||
var nextList = nextRoot ? nextRoot.querySelector("[data-load-more-list]") : null;
|
||||
var nextPagination = nextRoot ? nextRoot.querySelector("[data-load-more-pagination]") : null;
|
||||
|
||||
if (!nextList) {
|
||||
throw new Error("Post list not found");
|
||||
}
|
||||
|
||||
Array.prototype.forEach.call(nextList.children, function (item) {
|
||||
list.appendChild(item.cloneNode(true));
|
||||
});
|
||||
|
||||
updateLoadMoreState(pagination, nextPagination ? nextPagination.dataset.nextUrl : "", false);
|
||||
})
|
||||
.catch(function () {
|
||||
updateLoadMoreState(pagination, pagination.dataset.nextUrl, false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelectorAll("[data-load-more-root]").forEach(function (rootNode) {
|
||||
initializeLoadMore(rootNode);
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user