迁移聊天表单提交事件
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// 聊天输入区事件绑定,逐步替代底部输入栏内联提交事件。
|
||||
|
||||
let chatComposerEventsBound = false;
|
||||
|
||||
/**
|
||||
* 绑定聊天表单提交事件。
|
||||
* 发送主流程仍由 Blade 主脚本的 sendMessage 维护,这里只统一 submit 入口。
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function bindChatComposerControls() {
|
||||
if (chatComposerEventsBound || typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
chatComposerEventsBound = true;
|
||||
document.addEventListener("submit", (event) => {
|
||||
const form = event.target;
|
||||
if (!(form instanceof HTMLFormElement) || !form.matches("[data-chat-form]")) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if (typeof window.sendMessage === "function") {
|
||||
void window.sendMessage(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user