refactor(chat): decompose core.js into scroll.js, messages.js, input.js, and core.js
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* ===============================================================================
|
||||
* FILE: modules/web_api/static/js/chat/scroll.js
|
||||
* ROLE: Изолированный движок скролла чата (Gemini-style scroll to top).
|
||||
* ===============================================================================
|
||||
*/
|
||||
|
||||
window.scrollToUserMessageTop = function() {
|
||||
const container = document.getElementById("chat-messages-container");
|
||||
if (!container) return;
|
||||
|
||||
// Обеспечиваем невидимый эластичный спейсер в конце ленты
|
||||
let spacer = document.getElementById("chat-scroll-spacer");
|
||||
if (!spacer) {
|
||||
spacer = document.createElement("div");
|
||||
spacer.id = "chat-scroll-spacer";
|
||||
spacer.style.height = "calc(100vh - 220px)";
|
||||
spacer.style.flexShrink = "0";
|
||||
spacer.style.pointerEvents = "none";
|
||||
container.appendChild(spacer);
|
||||
} else {
|
||||
container.appendChild(spacer);
|
||||
}
|
||||
|
||||
const userBubbles = container.querySelectorAll(".user-chat-bubble");
|
||||
const targetEl = userBubbles[userBubbles.length - 1];
|
||||
if (!targetEl) return;
|
||||
|
||||
setTimeout(() => {
|
||||
const containerRect = container.getBoundingClientRect();
|
||||
const targetRect = targetEl.getBoundingClientRect();
|
||||
const targetScrollTop = container.scrollTop + (targetRect.top - containerRect.top) - 16;
|
||||
|
||||
container.scrollTo({
|
||||
top: Math.max(0, targetScrollTop),
|
||||
behavior: 'smooth'
|
||||
});
|
||||
}, 40);
|
||||
};
|
||||
|
||||
window.ensureScrollSpacerAtEnd = function() {
|
||||
const container = document.getElementById("chat-messages-container");
|
||||
const spacer = document.getElementById("chat-scroll-spacer");
|
||||
if (container && spacer) {
|
||||
container.appendChild(spacer);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user