aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/Main.hx
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-04-26 06:14:07 +0300
committerRblSb <msrblsb@gmail.com>2020-04-26 11:00:30 +0300
commite0f2520fb03ed07a38e96c012c0f599b2fbe7f04 (patch)
tree3b990453720b8193350ab5557abd410119160dd6 /src/client/Main.hx
parent3c5fda212a8b895027c3853d9979b12a8f6c5798 (diff)
Fix autoscroll with unloaded images
Diffstat (limited to 'src/client/Main.hx')
-rw-r--r--src/client/Main.hx31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/client/Main.hx b/src/client/Main.hx
index 5ee14d6..fda93c7 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -510,7 +510,7 @@ class Main {
});
}
for (emote in config.emotes) {
- final tag = emote.image.endsWith("mp4") ? 'video autoplay="" loop=""' : "img";
+ final tag = emote.image.endsWith("mp4") ? 'video autoplay="" loop="" muted=""' : "img";
filters.push({
regex: new EReg("(^| )" + escapeRegExp(emote.name) + "(?!\\S)", "g"),
replace: '$1<$tag class="channel-emote" src="${emote.image}" title="${emote.name}"/>'
@@ -656,8 +656,17 @@ class Main {
}
}
textDiv.innerHTML = text;
-
final isInChatEnd = msgBuf.scrollTop + msgBuf.clientHeight >= msgBuf.scrollHeight - 1;
+
+ if (isInChatEnd) { // scroll chat to end after images loaded
+ for (img in textDiv.getElementsByTagName("img")) {
+ img.onload = onChatImageLoaded;
+ }
+ for (video in textDiv.getElementsByTagName("video")) {
+ video.onloadedmetadata = onChatVideoLoaded;
+ }
+ }
+
userDiv.appendChild(tstamp);
userDiv.appendChild(nameDiv);
userDiv.appendChild(textDiv);
@@ -680,6 +689,24 @@ class Main {
}
}
+ function onChatImageLoaded(e:Event):Void {
+ scrollChatToEnd();
+ (cast e.target : Element).onload = null;
+ }
+
+ function onChatVideoLoaded(e:Event):Void {
+ // for some time default video size is 300x150px
+ Timer.delay(() -> {
+ scrollChatToEnd();
+ (cast e.target : Element).onloadedmetadata = null;
+ }, 100);
+ }
+
+ public function scrollChatToEnd():Void {
+ final msgBuf = ge("#messagebuffer");
+ msgBuf.scrollTop = msgBuf.scrollHeight;
+ }
+
final matchNumbers = ~/^-?[0-9]+$/;
function handleCommands(text:String):Void {
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage