1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 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 = $('<p class="line">' + message + "</p>");
- 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('');
- };
- };
|