feat(frontend): replace article system with Zibll 9.0
This commit is contained in:
@@ -4,6 +4,102 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function renderGradientBackground(container) {
|
||||
if (!container || container.dataset.aksrtGradientState || typeof window.Grade !== "function") return;
|
||||
|
||||
var source = container.querySelector("img");
|
||||
if (!source || (!source.classList.contains("lazyloaded") && !(source.complete && source.naturalWidth > 0))) return;
|
||||
|
||||
container.dataset.aksrtGradientState = "loading";
|
||||
window.Grade(container, null, function (result) {
|
||||
var gradientData = result && result[0];
|
||||
var colors = gradientData && gradientData.gradientData;
|
||||
if (!gradientData || !colors || !colors[0] || !colors[1]) {
|
||||
delete container.dataset.aksrtGradientState;
|
||||
return;
|
||||
}
|
||||
|
||||
var opacity = container.getAttribute("data-opacity");
|
||||
var colorName = opacity ? "rgba" : "rgb";
|
||||
var alpha = opacity ? "," + opacity : "";
|
||||
var color1 = colorName + "(" + colors[0].rgba.slice(0, 3).join(",") + alpha + ") 10%";
|
||||
var color2 = colorName + "(" + colors[1].rgba.slice(0, 3).join(",") + alpha + ") 80%";
|
||||
|
||||
gradientData.element.classList.add("gradient-bg-loaded");
|
||||
gradientData.element.style.backgroundImage = "linear-gradient(135deg, " + color1 + ", " + color2 + ")";
|
||||
container.dataset.aksrtGradientState = "loaded";
|
||||
});
|
||||
}
|
||||
|
||||
function initGradientBackgrounds(root) {
|
||||
var scope = root || document;
|
||||
if (scope.nodeType === 1 && scope.matches(".gradient-bg")) {
|
||||
renderGradientBackground(scope);
|
||||
}
|
||||
scope.querySelectorAll(".gradient-bg").forEach(renderGradientBackground);
|
||||
}
|
||||
|
||||
document.addEventListener("lazyloaded", function (event) {
|
||||
if (!(event.target instanceof Element) || !event.target.matches(".gradient-bg img")) return;
|
||||
renderGradientBackground(event.target.closest(".gradient-bg"));
|
||||
}, true);
|
||||
|
||||
function initPostThumbMedia(root) {
|
||||
var scope = root || document;
|
||||
|
||||
scope.querySelectorAll("[data-post-thumb-slider]").forEach(function (el) {
|
||||
if (el.dataset.aksrtThumbSliderBound === "1" || typeof Swiper === "undefined") return;
|
||||
el.dataset.aksrtThumbSliderBound = "1";
|
||||
new Swiper(el, {
|
||||
slidesPerView: 1,
|
||||
loop: el.querySelectorAll(".swiper-slide").length > 1,
|
||||
pagination: {
|
||||
el: el.querySelector(".swiper-pagination"),
|
||||
clickable: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
scope.querySelectorAll("[data-post-thumb-video]").forEach(function (box) {
|
||||
if (box.dataset.aksrtThumbVideoBound === "1") return;
|
||||
box.dataset.aksrtThumbVideoBound = "1";
|
||||
var video = box.querySelector("video");
|
||||
if (!video) return;
|
||||
|
||||
function loadVideo() {
|
||||
if (!video.getAttribute("src") && video.dataset.src) {
|
||||
video.setAttribute("src", video.dataset.src);
|
||||
video.load();
|
||||
}
|
||||
}
|
||||
|
||||
function playVideo() {
|
||||
loadVideo();
|
||||
var result = video.play();
|
||||
var postItem = box.closest(".posts-item");
|
||||
if (postItem) postItem.classList.add("thumb-dplayer-playing");
|
||||
if (result && typeof result.catch === "function") result.catch(function () {});
|
||||
}
|
||||
|
||||
function pauseVideo() {
|
||||
video.pause();
|
||||
var postItem = box.closest(".posts-item");
|
||||
if (postItem) postItem.classList.remove("thumb-dplayer-playing");
|
||||
}
|
||||
|
||||
var item = box.closest(".item-thumbnail") || box;
|
||||
item.addEventListener("mouseenter", playVideo);
|
||||
item.addEventListener("mouseleave", pauseVideo);
|
||||
item.addEventListener("focusin", playVideo);
|
||||
item.addEventListener("focusout", pauseVideo);
|
||||
});
|
||||
}
|
||||
|
||||
window.AksrtFrontend.register("aksrt-post-thumb-media", function (root) {
|
||||
initPostThumbMedia(root);
|
||||
initGradientBackgrounds(root);
|
||||
});
|
||||
|
||||
function initRelatedSwiper() {
|
||||
var el = document.querySelector(".related-swiper[data-swiper-config]");
|
||||
if (!el || typeof Swiper === "undefined") return;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
}
|
||||
|
||||
function initAjaxPagination(root) {
|
||||
var containers = (root || document).querySelectorAll(".aksrt-pagination-ajax, .ajax-pagination");
|
||||
var containers = (root || document).querySelectorAll("[data-aksrt-pagination], .aksrt-comment-pagination");
|
||||
if (!containers.length) return;
|
||||
|
||||
var triggerText = (window.aksrtData && aksrtData.ajaxTrigger) || "加载更多";
|
||||
@@ -29,8 +29,9 @@
|
||||
var commentOrder = container.dataset.commentOrder || "newest";
|
||||
var loading = false;
|
||||
var failed = false;
|
||||
var loadMoreBtn = container.querySelector(".aksrt-load-more-btn, .ajax-next");
|
||||
var indicator = container.querySelector(".aksrt-loading-indicator");
|
||||
var clickTarget = container.querySelector(".next-page.ajax-next, .ias-btn") || container;
|
||||
var loadMoreBtn = container.querySelector("[data-aksrt-load-more]") || clickTarget;
|
||||
var indicator = container.querySelector(".post_ajax_loader");
|
||||
var successfulAutoLoads = 0;
|
||||
var iasMax = isComment
|
||||
? ((window.aksrtData && typeof aksrtData.commentIasMax !== "undefined") ? parseInt(aksrtData.commentIasMax, 10) : 0)
|
||||
@@ -68,13 +69,19 @@
|
||||
function stopInfinite(markNomore) {
|
||||
container.classList.remove("ias-pending");
|
||||
if (markNomore && loadMoreBtn) {
|
||||
loadMoreBtn.textContent = nomoreText;
|
||||
loadMoreBtn.innerHTML = nomoreText;
|
||||
loadMoreBtn.classList.remove("is-loading");
|
||||
loadMoreBtn.classList.add("ajax-nomore");
|
||||
var nextWrap = loadMoreBtn.closest(".next-page");
|
||||
if (nextWrap) nextWrap.classList.add("no-more");
|
||||
loadMoreBtn.style.pointerEvents = "none";
|
||||
} else if (loadMoreBtn && !loadMoreBtn.classList.contains("ajax-nomore")) {
|
||||
loadMoreBtn.classList.remove("is-loading");
|
||||
loadMoreBtn.textContent = failed ? errorText : triggerText;
|
||||
if (failed) {
|
||||
loadMoreBtn.textContent = errorText;
|
||||
} else {
|
||||
loadMoreBtn.innerHTML = triggerText;
|
||||
}
|
||||
loadMoreBtn.style.pointerEvents = "";
|
||||
}
|
||||
}
|
||||
@@ -164,7 +171,7 @@
|
||||
target.appendChild(newItems[0]);
|
||||
}
|
||||
}
|
||||
if (isComment && window.AksrtFrontend) {
|
||||
if (window.AksrtFrontend) {
|
||||
AksrtFrontend.rehydrate(target, "ajax");
|
||||
}
|
||||
nextPage++;
|
||||
@@ -191,13 +198,16 @@
|
||||
if (indicator) indicator.style.display = "none";
|
||||
if (loadMoreBtn && !loadMoreBtn.classList.contains("ajax-nomore") && !failed) {
|
||||
loadMoreBtn.classList.remove("is-loading");
|
||||
loadMoreBtn.textContent = triggerText;
|
||||
loadMoreBtn.innerHTML = triggerText;
|
||||
if (mode === "infinite") {
|
||||
var lazyTrigger = clickTarget.closest(".next-page") || clickTarget;
|
||||
if (iasMax > 0 && successfulAutoLoads >= iasMax) {
|
||||
stopInfinite(true);
|
||||
container.classList.remove("ias-pending");
|
||||
lazyTrigger.classList.remove("lazyload", "lazyloaded", "lazyloading");
|
||||
lazyTrigger.removeAttribute("lazyload-action");
|
||||
} else {
|
||||
loadMoreBtn.classList.remove("lazyloaded", "lazyloading");
|
||||
loadMoreBtn.classList.add("lazyload");
|
||||
lazyTrigger.classList.remove("lazyloaded", "lazyloading");
|
||||
lazyTrigger.classList.add("lazyload");
|
||||
if (window.lazySizes && lazySizes.loader) {
|
||||
lazySizes.loader.checkElems();
|
||||
}
|
||||
@@ -208,7 +218,7 @@
|
||||
}
|
||||
|
||||
if (loadMoreBtn) {
|
||||
loadMoreBtn.addEventListener("click", function(e) {
|
||||
clickTarget.addEventListener("click", function(e) {
|
||||
e.preventDefault();
|
||||
if (loadMoreBtn.dataset.jumpComments === "1") {
|
||||
var jumpInput = container.querySelector(".jump-input");
|
||||
@@ -228,14 +238,14 @@
|
||||
var archiveMax = parseInt(archiveJumpInput.dataset.maxPages || String(maxPages), 10) || maxPages;
|
||||
archiveTargetPage = Math.max(1, Math.min(archiveMax, archiveTargetPage));
|
||||
var archiveUrl = new URL(window.location.href);
|
||||
archiveUrl.searchParams.set("paged", String(archiveTargetPage));
|
||||
archiveUrl.searchParams.set(loadMoreBtn.dataset.pageVar || "paged", String(archiveTargetPage));
|
||||
window.location.href = archiveUrl.toString();
|
||||
return;
|
||||
}
|
||||
var fromAuto = loadMoreBtn.dataset.lazyAuto === "1";
|
||||
delete loadMoreBtn.dataset.lazyAuto;
|
||||
var fromAuto = clickTarget.dataset.lazyAuto === "1";
|
||||
delete clickTarget.dataset.lazyAuto;
|
||||
if (fromAuto && iasMax > 0 && successfulAutoLoads >= iasMax) {
|
||||
stopInfinite(true);
|
||||
container.classList.remove("ias-pending");
|
||||
return;
|
||||
}
|
||||
// Manual click can recover from a previous auto-load failure.
|
||||
@@ -246,8 +256,9 @@
|
||||
|
||||
if (mode === "infinite") {
|
||||
if ((isComment && window.aksrtData && aksrtData.commentIasAuto === false) || !hasAjaxConfig()) {
|
||||
loadMoreBtn.classList.remove("lazyload");
|
||||
loadMoreBtn.removeAttribute("lazyload-action");
|
||||
var autoTrigger = clickTarget.closest(".next-page") || clickTarget;
|
||||
autoTrigger.classList.remove("lazyload");
|
||||
autoTrigger.removeAttribute("lazyload-action");
|
||||
return;
|
||||
}
|
||||
container.classList.add("ias-pending");
|
||||
|
||||
Reference in New Issue
Block a user