Added scrollback option to webchat.

New configuration option "scrollback". false or 0 to disable, any
numeric >0 value to enable/set the maximum scrollback length.

Doesn't show chat messages prior to the user loading the map page,
but at least it allows users to scroll back and view messages they
may have missed while not paying full attention ot the map.
This commit is contained in:
Mark Riedesel 2011-09-27 04:02:02 +08:00 committed by mikeprimm
parent 515b2f4afc
commit 8cb615e291
3 changed files with 39 additions and 12 deletions

View File

@ -63,6 +63,7 @@ components:
type: chatbox type: chatbox
showplayerfaces: true showplayerfaces: true
messagettl: 5 messagettl: 5
scrollback: 100
- class: org.dynmap.ClientComponent - class: org.dynmap.ClientComponent
type: playermarkers type: playermarkers
showplayerfaces: true showplayerfaces: true

View File

@ -717,6 +717,15 @@
padding: 1px; padding: 1px;
} }
.scrollback {
max-height:6em !important;
}
.scrollback:hover {
overflow-y: auto !important;
}
.messagerow { .messagerow {
position: relative; position: relative;
max-height: 200px; max-height: 200px;

View File

@ -7,6 +7,11 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
.addClass('messagelist') .addClass('messagelist')
.appendTo(chat); .appendTo(chat);
if (dynmap.options.scrollback) {
messagelist.addClass('scrollback')
.click( function() { $(this).hide(); } );
}
if (dynmap.options.allowwebchat) { if (dynmap.options.allowwebchat) {
var chatinput = $('<input/>') var chatinput = $('<input/>')
.addClass('chatinput') .addClass('chatinput')
@ -25,10 +30,22 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
} }
}) })
.appendTo(chat); .appendTo(chat);
if (dynmap.options.scrollback) {
chatinput.click(function(){
var m = $('.messagelist');
m.show().scrollTop(m.scrollHeight());
});
}
} }
var addrow = function(row) { var addrow = function(row) {
setTimeout(function() { row.remove(); }, (configuration.messagettl * 1000)); if (dynmap.options.scrollback) {
var c = messagelist.children();
c.slice(0, Math.max(0, c.length-dynmap.options.scrollback)).each(function(index, elem){ $(elem).remove(); });
} else {
setTimeout(function() { row.remove(); }, (configuration.messagettl * 1000));
}
messagelist.append(row); messagelist.append(row);
messagelist.show(); messagelist.show();
messagelist.scrollTop(messagelist.scrollHeight()); messagelist.scrollTop(messagelist.scrollHeight());
@ -50,7 +67,7 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
$(dynmap).bind('chat', function(event, message) { $(dynmap).bind('chat', function(event, message) {
var playerName = message.name; var playerName = message.name;
var playerAccount = message.account; var playerAccount = message.account;
var messageRow = $('<div/>') var messageRow = $('<div/>')
.addClass('messagerow'); .addClass('messagerow');
@ -58,7 +75,7 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
.addClass('messageicon'); .addClass('messageicon');
if (message.source === 'player' && configuration.showplayerfaces && if (message.source === 'player' && configuration.showplayerfaces &&
playerAccount) { playerAccount) {
getMinecraftHead(playerAccount, 16, function(head) { getMinecraftHead(playerAccount, 16, function(head) {
messageRow.icon = $(head) messageRow.icon = $(head)
.addClass('playerIcon') .addClass('playerIcon')
@ -66,12 +83,12 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
}); });
} }
var playerChannelContainer = ''; var playerChannelContainer = '';
if (message.channel) { if (message.channel) {
playerChannelContainer = $('<span/>').addClass('messagetext') playerChannelContainer = $('<span/>').addClass('messagetext')
.text('[' + message.channel + '] ') .text('[' + message.channel + '] ')
.appendTo(messageRow); .appendTo(messageRow);
} }
if (message.source === 'player' && configuration.showworld) { if (message.source === 'player' && configuration.showworld) {
var playerWorldContainer = $('<span/>') var playerWorldContainer = $('<span/>')