55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
// 聊天室图片预览层控制,迁出 Blade 内联脚本后仍通过 window 全局函数兼容现有 onclick。
|
|
|
|
/**
|
|
* 打开聊天图片大图预览层。
|
|
*
|
|
* @param {string} imageUrl 图片地址
|
|
* @param {string} imageName 图片名称
|
|
* @returns {void}
|
|
*/
|
|
export function openChatImageLightbox(imageUrl, imageName = "聊天图片") {
|
|
const lightbox = document.getElementById("chat-image-lightbox");
|
|
const imageEl = document.getElementById("chat-image-lightbox-img");
|
|
const nameEl = document.getElementById("chat-image-lightbox-name");
|
|
|
|
if (!lightbox || !imageEl || !imageUrl) {
|
|
return;
|
|
}
|
|
|
|
imageEl.src = imageUrl;
|
|
imageEl.alt = imageName;
|
|
|
|
if (nameEl) {
|
|
nameEl.textContent = imageName;
|
|
}
|
|
|
|
lightbox.style.display = "block";
|
|
document.body.style.overflow = "hidden";
|
|
}
|
|
|
|
/**
|
|
* 关闭聊天图片大图预览层。
|
|
*
|
|
* @param {Event|null} event 点击事件
|
|
* @returns {void}
|
|
*/
|
|
export function closeChatImageLightbox(event = null) {
|
|
if (event && event.target !== event.currentTarget) {
|
|
return;
|
|
}
|
|
|
|
const lightbox = document.getElementById("chat-image-lightbox");
|
|
if (!lightbox) {
|
|
return;
|
|
}
|
|
|
|
lightbox.style.display = "none";
|
|
|
|
const imageEl = document.getElementById("chat-image-lightbox-img");
|
|
if (imageEl) {
|
|
imageEl.src = "";
|
|
}
|
|
|
|
document.body.style.overflow = "";
|
|
}
|