From ca61dd42f7c6e6bfaf71abe3495b6adab658738b Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 25 Apr 2026 03:40:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=AD=97=E5=8F=B7=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=99=A8=E4=BA=8B=E4=BB=B6=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/chat-room.js | 6 ++++-- resources/js/chat-room/font-size.js | 21 +++++++++++++++++++ .../chat/partials/layout/input-bar.blade.php | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) 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 @@