diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index 2e6fe40..148245c 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -1,7 +1,7 @@ // 聊天室 Vite 入口,集中导出从 Blade 内联脚本迁移出的纯前端工具。 export { escapeHtml, escapeHtmlWithLineBreaks } from "./chat-room/html.js"; -export { applyFontSize, CHAT_FONT_SIZE_STORAGE_KEY, restoreChatFontSize } from "./chat-room/font-size.js"; +export { applyFontSize, bindChatFontSizeControl, CHAT_FONT_SIZE_STORAGE_KEY, restoreChatFontSize } from "./chat-room/font-size.js"; export { closeChatImageLightbox, initChatImageLightboxEvents, openChatImageLightbox } from "./chat-room/lightbox.js"; export { BLOCKABLE_SYSTEM_SENDERS, @@ -27,7 +27,7 @@ export { export { createMessageQueue } from "./chat-room/message-queue.js"; import { escapeHtml, escapeHtmlWithLineBreaks } from "./chat-room/html.js"; -import { applyFontSize, CHAT_FONT_SIZE_STORAGE_KEY, restoreChatFontSize } from "./chat-room/font-size.js"; +import { applyFontSize, bindChatFontSizeControl, CHAT_FONT_SIZE_STORAGE_KEY, restoreChatFontSize } from "./chat-room/font-size.js"; import { closeChatImageLightbox, initChatImageLightboxEvents, openChatImageLightbox } from "./chat-room/lightbox.js"; import { BLOCKABLE_SYSTEM_SENDERS, @@ -57,6 +57,7 @@ if (typeof window !== "undefined") { escapeHtml, escapeHtmlWithLineBreaks, applyFontSize, + bindChatFontSizeControl, CHAT_FONT_SIZE_STORAGE_KEY, restoreChatFontSize, closeChatImageLightbox, @@ -85,4 +86,5 @@ if (typeof window !== "undefined") { window.closeChatImageLightbox = closeChatImageLightbox; window.openChatImageLightbox = openChatImageLightbox; window.applyFontSize = applyFontSize; + bindChatFontSizeControl(); } diff --git a/resources/js/chat-room/font-size.js b/resources/js/chat-room/font-size.js index 238654e..e630963 100644 --- a/resources/js/chat-room/font-size.js +++ b/resources/js/chat-room/font-size.js @@ -1,6 +1,7 @@ // 聊天室字号偏好控制,保留旧的 localStorage key 以兼容已有用户设置。 export const CHAT_FONT_SIZE_STORAGE_KEY = "chat_font_size"; +let fontSizeEventsBound = false; /** * 应用字号到聊天消息窗口,并保存到 localStorage。 @@ -43,3 +44,23 @@ export function restoreChatFontSize() { return saved ? applyFontSize(saved) : false; } + +/** + * 绑定字号选择器事件。 + * + * @returns {void} + */ +export function bindChatFontSizeControl() { + if (fontSizeEventsBound || typeof document === "undefined") { + return; + } + + fontSizeEventsBound = true; + document.addEventListener("change", (event) => { + if (!(event.target instanceof HTMLSelectElement) || event.target.id !== "font_size_select") { + return; + } + + applyFontSize(event.target.value); + }); +} diff --git a/resources/views/chat/partials/layout/input-bar.blade.php b/resources/views/chat/partials/layout/input-bar.blade.php index 2c14dad..6d5754b 100644 --- a/resources/views/chat/partials/layout/input-bar.blade.php +++ b/resources/views/chat/partials/layout/input-bar.blade.php @@ -56,7 +56,7 @@