componentconstructors['chatbox'] = function(dynmap, configuration) { var me = this; var chat = $('
') .addClass('chat') .appendTo(dynmap.options.container); var messagelist = $('') .addClass('messagelist') .appendTo(chat); if (configuration.scrollback) { messagelist.addClass('scrollback') .click( function() { $(this).hide(); } ); } if (dynmap.options.allowwebchat) { var chatinput = $('') .addClass('chatinput') .attr({ id: 'chatinput', type: 'text', value: '' }) .keydown(function(event) { if (event.keyCode == '13') { event.preventDefault(); if(chatinput.val() != '') { $(dynmap).trigger('sendchat', [chatinput.val()]); chatinput.val(''); } } }) .appendTo(chat); if (configuration.scrollback) { chatinput.click(function(){ var m = $('.messagelist'); m.show().scrollTop(m.scrollHeight()); }); } } var addrow = function(row) { if (configuration.scrollback) { var c = messagelist.children(); c.slice(0, Math.max(0, c.length-configuration.scrollback)).each(function(index, elem){ $(elem).remove(); }); } else { setTimeout(function() { row.remove(); }, (configuration.messagettl * 1000)); } messagelist.append(row); messagelist.show(); messagelist.scrollTop(messagelist.scrollHeight()); }; $(dynmap).bind('playerjoin', function(event, playername) { addrow($('') .addClass('messagerow') .text(dynmap.options.joinmessage.replace('%playername%', playername)) ); }); $(dynmap).bind('playerquit', function(event, playername) { addrow($('') .addClass('messagerow') .text(dynmap.options.quitmessage.replace('%playername%', playername)) ); }); $(dynmap).bind('chat', function(event, message) { var playerName = message.name; var playerAccount = message.account; var messageRow = $('') .addClass('messagerow'); var playerIconContainer = $('') .addClass('messageicon'); if (message.source === 'player' && configuration.showplayerfaces && playerAccount) { getMinecraftHead(playerAccount, 16, function(head) { messageRow.icon = $(head) .addClass('playerIcon') .appendTo(playerIconContainer); }); } var playerChannelContainer = ''; if (message.channel) { playerChannelContainer = $('').addClass('messagetext') .text('[' + message.channel + '] ') .appendTo(messageRow); } if (message.source === 'player' && configuration.showworld) { var playerWorldContainer = $('') .addClass('messagetext') .text('['+dynmap.players[message.name].location.world.name+']') .appendTo(messageRow); } var playerNameContainer = ''; if(message.name) { playerNameContainer = $('').addClass('messagetext').text(' '+message.name+': '); } var playerMessageContainer = $('') .addClass('messagetext') .text(chat_encoder(message)); messageRow.append(playerIconContainer,playerChannelContainer,playerNameContainer,playerMessageContainer); addrow(messageRow); }); };