fix(comments): open the action dropdown with theme-owned delegation
The comment three-dot menu relied on the legacy data-toggle=dropdown delegation living in comment-move-form.js; when that bundle chain does not evaluate (stale cache or an earlier top-level error), the menu appears dead. Move the comment action dropdown to its own top-level document delegation in comments.js (data-aksrt-comment-drop), keep the .open-driven CSS contract including the mobile drop-fixed-sm sheet, sync aria-expanded, close on outside click / Escape / menu item click, and stay idempotent for AJAX-injected comments.
This commit is contained in:
1 parent
7c730b83d6
commit
913958820c
3 files changed
+54
-2
No files matched your search
@@ -616,6 +616,51 @@
|
||||
});
|
||||
}
|
||||
|
||||
/* ====== 评论操作三点下拉(主题自有交互,替代 vendor data-toggle 遗留委托) ======
|
||||
* 一次性文档级委托:AJAX 注入的新评论无需重绑;
|
||||
* open 类驱动的 .dropdown-menu 显隐 CSS 契约(含移动端 drop-fixed-sm 底部抽屉)保持不变。 */
|
||||
function closeAllCommentDropdowns() {
|
||||
document.querySelectorAll("#postcomments .dropdown.open").forEach(function (wrap) {
|
||||
wrap.classList.remove("open");
|
||||
var trigger = wrap.querySelector("[data-aksrt-comment-drop]");
|
||||
if (trigger) trigger.setAttribute("aria-expanded", "false");
|
||||
});
|
||||
}
|
||||
|
||||
function initCommentActionDropdowns() {
|
||||
if (document.documentElement.dataset.aksrtCommentDropBound === "1") return;
|
||||
document.documentElement.dataset.aksrtCommentDropBound = "1";
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var trigger = event.target.closest ? event.target.closest("[data-aksrt-comment-drop]") : null;
|
||||
if (trigger) {
|
||||
event.preventDefault();
|
||||
var wrap = trigger.closest(".dropdown");
|
||||
if (!wrap) return;
|
||||
var wasOpen = wrap.classList.contains("open");
|
||||
closeAllCommentDropdowns();
|
||||
if (!wasOpen) {
|
||||
wrap.classList.add("open");
|
||||
trigger.setAttribute("aria-expanded", "true");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 点击菜单项(举报/置顶/编辑/批准/删除)后收起菜单。
|
||||
var menuItem = event.target.closest ? event.target.closest("#postcomments .dropdown.open .dropdown-menu a") : null;
|
||||
if (menuItem) {
|
||||
closeAllCommentDropdowns();
|
||||
return;
|
||||
}
|
||||
if (!event.target.closest || !event.target.closest("#postcomments .dropdown.open")) {
|
||||
closeAllCommentDropdowns();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", function (event) {
|
||||
if (event.key === "Escape") closeAllCommentDropdowns();
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
stripCommentUrlParams();
|
||||
initCommentSystem();
|
||||
@@ -623,6 +668,10 @@
|
||||
initCommentOrder();
|
||||
}
|
||||
|
||||
// 顶层立即绑定:纯文档级委托,不依赖 DOM 就绪与 init() 是否成功;
|
||||
// 保证即使同文件后续初始化在异常环境中中断,三点菜单仍可开合。
|
||||
initCommentActionDropdowns();
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user