迁移聊天图片上传事件绑定
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// 聊天室图片上传控件事件绑定,逐步替代 Blade 内联 onclick/onchange。
|
||||
|
||||
let imageUploadEventsBound = false;
|
||||
|
||||
/**
|
||||
* 绑定聊天图片选择按钮与文件框事件。
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function bindChatImageUploadControl() {
|
||||
if (imageUploadEventsBound || typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
imageUploadEventsBound = true;
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!(event.target instanceof Element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.target.closest("[data-chat-image-upload-trigger]")) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
document.getElementById("chat_image")?.click();
|
||||
});
|
||||
|
||||
document.addEventListener("change", (event) => {
|
||||
if (!(event.target instanceof HTMLInputElement) || event.target.id !== "chat_image") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof window.handleChatImageSelected === "function") {
|
||||
window.handleChatImageSelected(event.target);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user