迁移聊天室底部滚动工具
This commit is contained in:
@@ -249,7 +249,13 @@ export {
|
||||
updateRedPacketClaimsUI,
|
||||
} from "./chat-room/red-packet-panel.js";
|
||||
export { createMessageQueue } from "./chat-room/message-queue.js";
|
||||
export { isExpiredChatImageMessage, localClearScreen, syncAutoScrollControls, toggleAutoScroll } from "./chat-room/message-utils.js";
|
||||
export {
|
||||
isExpiredChatImageMessage,
|
||||
localClearScreen,
|
||||
scrollChatToBottom,
|
||||
syncAutoScrollControls,
|
||||
toggleAutoScroll,
|
||||
} from "./chat-room/message-utils.js";
|
||||
|
||||
import { escapeHtml, escapeHtmlWithLineBreaks, normalizeSafeChatUrl } from "./chat-room/html.js";
|
||||
import { bindAppointmentAnnouncementControls, showAppointmentBanner } from "./chat-room/appointment-announcement.js";
|
||||
@@ -442,7 +448,13 @@ import {
|
||||
updateRedPacketClaimsUI,
|
||||
} from "./chat-room/red-packet-panel.js";
|
||||
import { createMessageQueue } from "./chat-room/message-queue.js";
|
||||
import { isExpiredChatImageMessage, localClearScreen, syncAutoScrollControls, toggleAutoScroll } from "./chat-room/message-utils.js";
|
||||
import {
|
||||
isExpiredChatImageMessage,
|
||||
localClearScreen,
|
||||
scrollChatToBottom,
|
||||
syncAutoScrollControls,
|
||||
toggleAutoScroll,
|
||||
} from "./chat-room/message-utils.js";
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
// 保留聚合入口,给新迁移模块、测试和仍在 Blade 内的存量脚本统一读取工具。
|
||||
@@ -670,6 +682,7 @@ if (typeof window !== "undefined") {
|
||||
createMessageQueue,
|
||||
isExpiredChatImageMessage,
|
||||
localClearScreen,
|
||||
scrollChatToBottom,
|
||||
syncAutoScrollControls,
|
||||
toggleAutoScroll,
|
||||
};
|
||||
|
||||
@@ -117,3 +117,19 @@ export function toggleAutoScroll(getCurrent, setCurrent) {
|
||||
|
||||
return nextEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在允许自动滚屏时,把聊天容器滚动到最新消息。
|
||||
* Blade 仍负责传入真实容器和开关读取器,避免工具函数直接依赖大脚本闭包。
|
||||
*
|
||||
* @param {HTMLElement|null|undefined} container 聊天消息容器
|
||||
* @param {() => boolean} shouldScroll 判断当前是否允许自动滚屏
|
||||
* @returns {void}
|
||||
*/
|
||||
export function scrollChatToBottom(container, shouldScroll) {
|
||||
if (!container || !(typeof shouldScroll === "function" ? shouldScroll() : true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.scrollTop = container.scrollHeight;
|
||||
}
|
||||
|
||||
@@ -1770,6 +1770,11 @@
|
||||
* 将公聊窗口滚动到最新消息(受 autoScroll 开关控制)
|
||||
*/
|
||||
function scrollToBottom() {
|
||||
if (window.ChatRoomTools?.scrollChatToBottom) {
|
||||
window.ChatRoomTools.scrollChatToBottom(container, () => autoScroll);
|
||||
return;
|
||||
}
|
||||
|
||||
if (autoScroll) {
|
||||
container.scrollTop = container.scrollHeight;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user