迁移全局弹窗按钮事件绑定
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// 聊天室全局弹窗事件绑定,替代 Blade 内联 onclick。
|
||||
|
||||
let globalDialogEventsBound = false;
|
||||
|
||||
/**
|
||||
* 绑定全局弹窗确认与取消按钮。
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function bindGlobalDialogControls() {
|
||||
if (globalDialogEventsBound || typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
globalDialogEventsBound = true;
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!(event.target instanceof Element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const actionButton = event.target.closest("[data-chat-dialog-action]");
|
||||
if (!actionButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
const action = actionButton.getAttribute("data-chat-dialog-action");
|
||||
if (action === "confirm") {
|
||||
window.chatDialog?._confirm?.();
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "cancel") {
|
||||
window.chatDialog?._cancel?.();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user