39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
// 聊天室图片上传控件事件绑定,逐步替代 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);
|
|
}
|
|
});
|
|
}
|