2011-03-31 11:25:09 +02:00
|
|
|
componentconstructors['chatbox'] = function(dynmap, configuration) {
|
2011-03-31 12:54:32 +02:00
|
|
|
var me = this;
|
|
|
|
var chat = $('<div/>')
|
|
|
|
.addClass('chat')
|
|
|
|
.appendTo(dynmap.options.container);
|
|
|
|
var messagelist = $('<div/>')
|
|
|
|
.addClass('messagelist')
|
|
|
|
.appendTo(chat);
|
|
|
|
|
|
|
|
if (dynmap.options.allowwebchat) {
|
|
|
|
var chatinput = $('<input/>')
|
|
|
|
.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);
|
|
|
|
}
|
|
|
|
|
2011-04-05 22:58:46 +02:00
|
|
|
var addrow = function(row) {
|
|
|
|
setTimeout(function() { row.remove(); }, (configuration.messagettl * 1000));
|
|
|
|
messagelist.append(row);
|
|
|
|
messagelist.show();
|
|
|
|
messagelist.scrollTop(messagelist.scrollHeight());
|
|
|
|
};
|
|
|
|
|
|
|
|
$(dynmap).bind('playerjoin', function(event, playername) {
|
|
|
|
addrow($('<div/>')
|
|
|
|
.addClass('messagerow')
|
|
|
|
.text(dynmap.options.joinmessage.replace('%playername%', playername))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(dynmap).bind('playerquit', function(event, playername) {
|
|
|
|
addrow($('<div/>')
|
|
|
|
.addClass('messagerow')
|
|
|
|
.text(dynmap.options.quitmessage.replace('%playername%', playername))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2011-03-31 12:54:32 +02:00
|
|
|
$(dynmap).bind('chat', function(event, message) {
|
|
|
|
var playerName = message.name;
|
2011-05-22 06:58:48 +02:00
|
|
|
var playerAccount = message.account;
|
2011-03-31 12:54:32 +02:00
|
|
|
var messageRow = $('<div/>')
|
|
|
|
.addClass('messagerow');
|
2011-03-31 11:25:09 +02:00
|
|
|
|
2011-03-31 12:54:32 +02:00
|
|
|
var playerIconContainer = $('<span/>')
|
|
|
|
.addClass('messageicon');
|
2011-03-31 11:25:09 +02:00
|
|
|
|
2011-05-22 06:58:48 +02:00
|
|
|
if (message.source === 'player' && configuration.showplayerfaces &&
|
|
|
|
playerAccount) {
|
|
|
|
getMinecraftHead(playerAccount, 16, function(head) {
|
2011-03-31 12:54:32 +02:00
|
|
|
messageRow.icon = $(head)
|
|
|
|
.addClass('playerIcon')
|
|
|
|
.appendTo(playerIconContainer);
|
|
|
|
});
|
|
|
|
}
|
2011-03-31 11:25:09 +02:00
|
|
|
|
2011-05-22 06:58:48 +02:00
|
|
|
var playerChannelContainer = '';
|
|
|
|
if (message.channel) {
|
|
|
|
playerChannelContainer = $('<span/>').addClass('messagetext')
|
|
|
|
.text('[' + message.channel + '] ')
|
|
|
|
.appendTo(messageRow);
|
|
|
|
}
|
|
|
|
|
2011-03-31 12:54:32 +02:00
|
|
|
if (message.source === 'player' && configuration.showworld) {
|
|
|
|
var playerWorldContainer = $('<span/>')
|
|
|
|
.addClass('messagetext')
|
|
|
|
.text('['+dynmap.players[message.name].location.world.name+']')
|
|
|
|
.appendTo(messageRow);
|
|
|
|
}
|
2011-03-31 11:25:09 +02:00
|
|
|
|
2011-03-31 12:54:32 +02:00
|
|
|
var playerNameContainer = $('<span/>')
|
|
|
|
.addClass('messagetext')
|
|
|
|
.text(' '+message.name+': ');
|
2011-03-31 11:25:09 +02:00
|
|
|
|
2011-03-31 12:54:32 +02:00
|
|
|
var playerMessageContainer = $('<span/>')
|
|
|
|
.addClass('messagetext')
|
|
|
|
.text(message.text);
|
2011-03-31 11:25:09 +02:00
|
|
|
|
2011-05-22 06:58:48 +02:00
|
|
|
messageRow.append(playerIconContainer,playerChannelContainer,playerNameContainer,playerMessageContainer);
|
2011-04-05 22:58:46 +02:00
|
|
|
addrow(messageRow);
|
2011-03-31 12:54:32 +02:00
|
|
|
});
|
2011-03-31 11:25:09 +02:00
|
|
|
};
|