+ this.writeToLog = function(action, style, msg) {
+ $('#log').append(
+ $('<div>').addClass('logline').append(
+ $('<span>').addClass(style).text(action),
+ $('<span>').addClass('msg').text(msg)
+ )
+ );
+ $("#log").animate({ scrollTop: $('#log')[0].scrollHeight}, 1000);
+ }
+ $('#submit').click(function() {
+ var text = $('#chat').val();
+ var parts = text.match(/^(\w+)\s(.*)/);
+ if (parts) {
+ var cmd = parts[1];
+ text = parts[2];
+ if (commands[cmd] != undefined) {
+ commands[cmd](text);
+ $('#chat').val('');
+ }
+ }
+ });
+ $('#chat').keydown(function(e) {
+ if (e.which == '13') {
+ typeof self.player == 'undefined' ?
+ $('#join').click() : $('#submit').click();
+ } else if (e.which >= 37 && e.which <= 40)
+ e.stopPropagation();
+ });
+ $('#join').click(function() {
+ var chat = $('#chat');
+ if (chat.val() == '') {
+ chat.css('border-color', 'red');
+ return;
+ }
+ mud.join(chat.val());
+ chat.css('border-color', 'black').val('');
+ $(this).fadeOut('slow', function() {
+ $('#log, #submit').fadeIn('slow')
+ .css('display', 'inline-block');
+ });
+ });