if(MIDAS == undefined) { var MIDAS = {}; } MIDAS.Console = function(inputField, outputField, sendButton) { var self = this; var maxLines = 20; var lines = []; var sentCallback = function(message) {}; this.register = function(sendResponse) { sentCallback = sendResponse; }; this.init = function() { inputField.keypress(inputTyping); sendButton.click(userSend); inputField.focus(); }; this.output = function(message) { addLine(message, function(){}); } function addLine(message, callback) { var messageOutput = $('
' + message + "
"); lines.push(messageOutput); messageOutput.hide(); outputField.append(messageOutput); messageOutput.fadeIn('fast', callback); if(lines.length >= maxLines) { lines[0].fadeOut(); lines = lines.slice(1); } }; function inputTyping(event) { if(event.which == 13) { userSend(); } }; function userSend() { var message = inputField.val(); addLine(message, function() { sentCallback(message);}); inputField.val(''); }; };