aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/Main.hx
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2023-06-20 23:33:13 +0300
committerRblSb <msrblsb@gmail.com>2023-06-20 23:33:13 +0300
commitc476a16ad982e778580d74b8e4120ed29118129a (patch)
treec326895bc9eb57cf50123eadb049ec73b3a201f2 /src/client/Main.hx
parentcdf7f00f613d636e587b7840ec8b263017513486 (diff)
Scroll to chat end button
Diffstat (limited to 'src/client/Main.hx')
-rw-r--r--src/client/Main.hx28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/client/Main.hx b/src/client/Main.hx
index a7417fb..69450d9 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -52,6 +52,7 @@ class Main {
}
function new() {
+ haxe.Log.trace = Utils.nativeTrace;
player = new Player(this);
host = Browser.location.hostname;
if (host == "") host = "localhost";
@@ -790,22 +791,22 @@ class Main {
ws.send(Json.stringify(data));
}
- static function chatMessageConnected():Void {
+ function chatMessageConnected():Void {
final div = document.createDivElement();
div.className = "server-msg-reconnect";
div.textContent = Lang.get("msgConnected");
final msgBuf = ge("#messagebuffer");
msgBuf.appendChild(div);
- msgBuf.scrollTop = msgBuf.scrollHeight;
+ scrollChatToEnd();
}
- static function chatMessageDisconnected():Void {
+ function chatMessageDisconnected():Void {
final div = document.createDivElement();
div.className = "server-msg-disconnect";
div.textContent = Lang.get("msgDisconnected");
final msgBuf = ge("#messagebuffer");
msgBuf.appendChild(div);
- msgBuf.scrollTop = msgBuf.scrollHeight;
+ scrollChatToEnd();
}
public static function serverMessage(text:String, isText = true, withTimestamp = true):Void {
@@ -897,7 +898,8 @@ class Main {
text = filter.regex.replace(text, filter.replace);
}
textDiv.innerHTML = text;
- final isInChatEnd = msgBuf.scrollTop + msgBuf.clientHeight >= msgBuf.scrollHeight - 1;
+ final isInChatEnd = msgBuf.scrollTop
+ + msgBuf.clientHeight >= msgBuf.scrollHeight - 50;
if (isInChatEnd) { // scroll chat to end after images loaded
for (img in textDiv.getElementsByTagName("img")) {
@@ -917,17 +919,27 @@ class Main {
while (msgBuf.children.length > 200) {
msgBuf.removeChild(msgBuf.firstChild);
}
- msgBuf.scrollTop = msgBuf.scrollHeight;
}
- if (name == personal.name) {
- msgBuf.scrollTop = msgBuf.scrollHeight;
+ if (isInChatEnd || name == personal.name) {
+ scrollChatToEnd();
+ } else {
+ showScrollToChatEndBtn();
}
if (onBlinkTab == null) blinkTabWithTitle("*Chat*");
}
+ function showScrollToChatEndBtn() {
+ final btn = ge("#scroll-to-chat-end");
+ btn.style.display = "block";
+ Timer.delay(() -> btn.style.opacity = "1", 0);
+ }
+
function onChatImageLoaded(e:Event):Void {
scrollChatToEnd();
(cast e.target : Element).onload = null;
+ final btn = ge("#scroll-to-chat-end");
+ btn.style.opacity = "0";
+ btn.style.display = "none";
}
var emoteMaxSize:Null<Int>;
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage