fix(header): wire multi-function page-type enable like zibll
Connect header_components_show_on through aksrt_header_slide_is_show with zibll page-type matching, drop the homepage-only gate, align admin options, apply nav color, enqueue by is_show, remove dead float-btn schema, and consume footer_tabbar_single extend mode on post singles.
This commit is contained in:
1 parent
3e3a4631f0
commit
bfb64211ee
12 files changed
+445
-285
No files matched your search
+103
-72
@@ -157,85 +157,116 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
function collectActionButtons(scope, selector) {
|
||||
scope = scope || document;
|
||||
var list = [];
|
||||
if (!scope) return list;
|
||||
if (scope.nodeType === 1 && scope.matches && scope.matches(selector)) {
|
||||
list.push(scope);
|
||||
}
|
||||
if (typeof scope.querySelectorAll === "function") {
|
||||
var found = scope.querySelectorAll(selector);
|
||||
for (var i = 0; i < found.length; i++) list.push(found[i]);
|
||||
} else if (scope.nodeType === 9) {
|
||||
var all = document.querySelectorAll(selector);
|
||||
for (var j = 0; j < all.length; j++) list.push(all[j]);
|
||||
}
|
||||
// also keep legacy id hooks
|
||||
var legacyId = selector.indexOf("action-like") >= 0 ? "action-like" : (selector.indexOf("action-favorite") >= 0 ? "action-favorite" : "");
|
||||
if (legacyId) {
|
||||
var legacy = findInScope(scope, legacyId);
|
||||
if (legacy && list.indexOf(legacy) === -1) list.push(legacy);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
function initInteractionBar(root) {
|
||||
var scope = root || document;
|
||||
// Element roots (AJAX rehydrate) do not implement getElementById
|
||||
var likeBtn = findInScope(scope, "action-like");
|
||||
var favBtn = findInScope(scope, "action-favorite");
|
||||
// Bind all like/favorite controls (in-content + footer tabbar extend).
|
||||
var likeBtns = collectActionButtons(scope, ".action-like[data-post-id]");
|
||||
var favBtns = collectActionButtons(scope, ".action-favorite[data-post-id]");
|
||||
|
||||
if (likeBtn && likeBtn.dataset.aksrtInteractionBound) return;
|
||||
if (favBtn && favBtn.dataset.aksrtInteractionBound) return;
|
||||
|
||||
if (likeBtn) {
|
||||
var likePostId = likeBtn.dataset.postId ? String(likeBtn.dataset.postId) : "";
|
||||
|
||||
function applyLikeState(isActive, count) {
|
||||
likeBtn.dataset.initialActive = isActive ? "1" : "0";
|
||||
likeBtn.classList.toggle("is-active", isActive);
|
||||
var likeIcon = likeBtn.querySelector("i");
|
||||
if (likeIcon) {
|
||||
likeIcon.className = isActive ? "fas fa-heart" : "far fa-heart";
|
||||
}
|
||||
if ("number" === typeof count && !isNaN(count)) {
|
||||
setBaseStatCount("likes", count);
|
||||
} else {
|
||||
updateStatCounts("likes", getBaseStatCount("likes"));
|
||||
}
|
||||
}
|
||||
|
||||
applyLikeState(likeBtn.dataset.initialActive === "1", getBaseStatCount("likes"));
|
||||
|
||||
likeBtn.addEventListener("click", function () {
|
||||
if (!likePostId || likeBtn.disabled) return;
|
||||
var nextState = likeBtn.dataset.initialActive !== "1";
|
||||
setButtonBusy(likeBtn, true);
|
||||
requestInteraction("aksrt_toggle_like", likePostId, nextState).then(function (data) {
|
||||
applyLikeState(!!data.active, parseInt(data.count, 10) || 0);
|
||||
showToast(data.active ? "感谢你的点赞" : "已取消点赞", "success");
|
||||
}).catch(function (error) {
|
||||
showToast(error && error.message ? error.message : "点赞失败", "error");
|
||||
}).finally(function () {
|
||||
setButtonBusy(likeBtn, false);
|
||||
});
|
||||
});
|
||||
function paintLike(btn, isActive) {
|
||||
btn.dataset.initialActive = isActive ? "1" : "0";
|
||||
btn.classList.toggle("is-active", isActive);
|
||||
var icon = btn.querySelector("i");
|
||||
if (icon) icon.className = isActive ? "fas fa-heart" : "far fa-heart";
|
||||
}
|
||||
|
||||
if (favBtn) {
|
||||
var favoritePostId = favBtn.dataset.postId ? String(favBtn.dataset.postId) : "";
|
||||
|
||||
function applyFavoriteState(isActive, count) {
|
||||
favBtn.dataset.initialActive = isActive ? "1" : "0";
|
||||
favBtn.classList.toggle("is-active", isActive);
|
||||
var favoriteIcon = favBtn.querySelector("i");
|
||||
if (favoriteIcon) {
|
||||
favoriteIcon.className = isActive ? "fas fa-star" : "far fa-star";
|
||||
}
|
||||
if ("number" === typeof count && !isNaN(count)) {
|
||||
setBaseStatCount("favorites", count);
|
||||
} else {
|
||||
updateStatCounts("favorites", getBaseStatCount("favorites"));
|
||||
}
|
||||
}
|
||||
|
||||
applyFavoriteState(favBtn.dataset.initialActive === "1", getBaseStatCount("favorites"));
|
||||
|
||||
favBtn.addEventListener("click", function () {
|
||||
if (!favoritePostId || favBtn.disabled) return;
|
||||
var nextState = favBtn.dataset.initialActive !== "1";
|
||||
setButtonBusy(favBtn, true);
|
||||
requestInteraction("aksrt_toggle_favorite", favoritePostId, nextState).then(function (data) {
|
||||
applyFavoriteState(!!data.active, parseInt(data.count, 10) || 0);
|
||||
showToast(data.active ? "收藏成功" : "已取消收藏", "success");
|
||||
}).catch(function (error) {
|
||||
showToast(error && error.message ? error.message : "收藏失败", "error");
|
||||
}).finally(function () {
|
||||
setButtonBusy(favBtn, false);
|
||||
});
|
||||
});
|
||||
function paintFavorite(btn, isActive) {
|
||||
btn.dataset.initialActive = isActive ? "1" : "0";
|
||||
btn.classList.toggle("is-active", isActive);
|
||||
var icon = btn.querySelector("i");
|
||||
if (icon) icon.className = isActive ? "fas fa-star" : "far fa-star";
|
||||
}
|
||||
|
||||
if (likeBtn) likeBtn.dataset.aksrtInteractionBound = "1";
|
||||
if (favBtn) favBtn.dataset.aksrtInteractionBound = "1";
|
||||
function applyLikeState(isActive, count) {
|
||||
for (var i = 0; i < likeBtns.length; i++) paintLike(likeBtns[i], isActive);
|
||||
if ("number" === typeof count && !isNaN(count)) {
|
||||
setBaseStatCount("likes", count);
|
||||
} else {
|
||||
updateStatCounts("likes", getBaseStatCount("likes"));
|
||||
}
|
||||
}
|
||||
|
||||
function applyFavoriteState(isActive, count) {
|
||||
for (var i = 0; i < favBtns.length; i++) paintFavorite(favBtns[i], isActive);
|
||||
if ("number" === typeof count && !isNaN(count)) {
|
||||
setBaseStatCount("favorites", count);
|
||||
} else {
|
||||
updateStatCounts("favorites", getBaseStatCount("favorites"));
|
||||
}
|
||||
}
|
||||
|
||||
if (likeBtns.length) {
|
||||
var seedLike = likeBtns[0];
|
||||
if (!seedLike.dataset.aksrtInteractionBound) {
|
||||
applyLikeState(seedLike.dataset.initialActive === "1", getBaseStatCount("likes"));
|
||||
likeBtns.forEach(function (likeBtn) {
|
||||
if (likeBtn.dataset.aksrtInteractionBound) return;
|
||||
likeBtn.dataset.aksrtInteractionBound = "1";
|
||||
likeBtn.addEventListener("click", function () {
|
||||
var postId = likeBtn.dataset.postId ? String(likeBtn.dataset.postId) : "";
|
||||
if (!postId || likeBtn.disabled) return;
|
||||
var nextState = likeBtn.dataset.initialActive !== "1";
|
||||
setButtonBusy(likeBtn, true);
|
||||
requestInteraction("aksrt_toggle_like", postId, nextState).then(function (data) {
|
||||
applyLikeState(!!data.active, parseInt(data.count, 10) || 0);
|
||||
showToast(data.active ? "感谢你的点赞" : "已取消点赞", "success");
|
||||
}).catch(function (error) {
|
||||
showToast(error && error.message ? error.message : "点赞失败", "error");
|
||||
}).finally(function () {
|
||||
setButtonBusy(likeBtn, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (favBtns.length) {
|
||||
var seedFav = favBtns[0];
|
||||
if (!seedFav.dataset.aksrtInteractionBound) {
|
||||
applyFavoriteState(seedFav.dataset.initialActive === "1", getBaseStatCount("favorites"));
|
||||
favBtns.forEach(function (favBtn) {
|
||||
if (favBtn.dataset.aksrtInteractionBound) return;
|
||||
favBtn.dataset.aksrtInteractionBound = "1";
|
||||
favBtn.addEventListener("click", function () {
|
||||
var postId = favBtn.dataset.postId ? String(favBtn.dataset.postId) : "";
|
||||
if (!postId || favBtn.disabled) return;
|
||||
var nextState = favBtn.dataset.initialActive !== "1";
|
||||
setButtonBusy(favBtn, true);
|
||||
requestInteraction("aksrt_toggle_favorite", postId, nextState).then(function (data) {
|
||||
applyFavoriteState(!!data.active, parseInt(data.count, 10) || 0);
|
||||
showToast(data.active ? "收藏成功" : "已取消收藏", "success");
|
||||
}).catch(function (error) {
|
||||
showToast(error && error.message ? error.message : "收藏失败", "error");
|
||||
}).finally(function () {
|
||||
setButtonBusy(favBtn, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.AksrtFrontend.register("aksrt-search-clear", function () { initSearchClear(); });
|
||||
|
||||
+12
-1
@@ -123,8 +123,9 @@
|
||||
}
|
||||
|
||||
function initShareDropdown() {
|
||||
var trigger = document.getElementById('action-share-trigger');
|
||||
var dropdown = document.getElementById('share-dropdown');
|
||||
var triggers = Array.prototype.slice.call(document.querySelectorAll('#action-share-trigger, .action-share[data-type="share"], .footer-tabbar .action-share')).filter(function (el, idx, arr) { return arr.indexOf(el) === idx; });
|
||||
var trigger = triggers[0] || null;
|
||||
if (!trigger || !dropdown || dropdown.dataset.aksrtShareBound === '1') return;
|
||||
|
||||
dropdown.dataset.aksrtShareBound = '1';
|
||||
@@ -160,6 +161,16 @@
|
||||
toggleDropdown();
|
||||
});
|
||||
|
||||
triggers.slice(1).forEach(function (extraTrigger) {
|
||||
extraTrigger.addEventListener('click', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
// Reuse primary trigger click semantics by synthetic toggle
|
||||
trigger.click();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
if (!trigger.contains(event.target) && !dropdown.contains(event.target)) {
|
||||
closeDropdown();
|
||||
|
||||
Reference in new issue
Block a user