From aa8922f9a7d2a2a539bfd2dbb5b2bebffa004f0a Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 2 Sep 2023 00:23:25 +0200 Subject: [PATCH] fix scroll-to-bottom functionality --- htdocs/lib/MessagePanel.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/htdocs/lib/MessagePanel.js b/htdocs/lib/MessagePanel.js index 9bd65b64..e1f71629 100644 --- a/htdocs/lib/MessagePanel.js +++ b/htdocs/lib/MessagePanel.js @@ -49,7 +49,12 @@ MessagePanel.prototype.initClearButton = function() { MessagePanel.prototype.htmlEscape = function(input) { return $('
').text(input).html() -} +}; + +MessagePanel.prototype.scrollToBottom = function() { + var $t = $(this.el).find('table'); + $t.scrollTop($t[0].scrollHeight); +}; function WsjtMessagePanel(el) { MessagePanel.call(this, el); @@ -113,7 +118,7 @@ WsjtMessagePanel.prototype.pushMessage = function(msg) { '' + linkedmsg + '' + '' )); - $b.scrollTop($b[0].scrollHeight); + this.scrollToBottom(); } $.fn.wsjtMessagePanel = function(){ @@ -219,7 +224,7 @@ PacketMessagePanel.prototype.pushMessage = function(msg) { '' + this.htmlEscape(msg.comment || msg.message || '') + '' + '' )); - $b.scrollTop($b[0].scrollHeight); + this.scrollToBottom(); }; $.fn.packetMessagePanel = function() { @@ -260,7 +265,7 @@ PocsagMessagePanel.prototype.pushMessage = function(msg) { '' + this.htmlEscape(msg.message) + '' + '' )); - $b.scrollTop($b[0].scrollHeight); + this.scrollToBottom(); }; $.fn.pocsagMessagePanel = function() { @@ -422,8 +427,7 @@ IsmMessagePanel.prototype.render = function() { }; IsmMessagePanel.prototype.pushMessage = function(message) { - var $t = $(this.el).find('table'); - var $b = $t.find('tbody'); + var $b = $(this.el).find('tbody'); var ifDefined = function(input, formatter) { if (typeof(input) !== 'undefined') { @@ -448,7 +452,7 @@ IsmMessagePanel.prototype.pushMessage = function(message) { '' + this.htmlEscape(mergeRemainingMessage(message, ['model', 'id', 'channel', 'mode', 'time'])) + '' + '' )); - $t.scrollTop($t[0].scrollHeight); + this.scrollToBottom(); }; $.fn.ismMessagePanel = function() {