From c8460ebf7360f12adcb0cbb95473933596fc1a38 Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Mon, 12 Sep 2011 16:47:00 +0000 Subject: [PATCH] Working on chat. --- .../gemp-lotr-web/src/main/webapp/js/chat.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/chat.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/chat.js index cdf9f8575..cffddf4eb 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/chat.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/chat.js @@ -19,8 +19,15 @@ var ChatBoxUI = Class.extend({ var that = this; this.communication.startChat(this.name, function(xml) { - that.processMessages(xml); + that.processMessages(xml, true); }) + + this.chatTalkDiv.bind("keypress", function(e) { + var code = (e.keyCode ? e.keyCode : e.which); + if (code == 13) { + that.sendMessage($(this).value); + } + }); }, setSize: function(width, height) { @@ -35,7 +42,7 @@ var ChatBoxUI = Class.extend({ } }, - processMessages: function(xml) { + processMessages: function(xml, processAgain) { var root = xml.documentElement; if (root.tagName == 'chat') { var messages = element.getElementsByTagName("message"); @@ -46,7 +53,8 @@ var ChatBoxUI = Class.extend({ this.appendMessage("" + from + ":" + text); } - setTimeout(this.updateChatMessages, 1000); + if (processAgain) + setTimeout(this.updateChatMessages, 1000); } }, @@ -54,7 +62,15 @@ var ChatBoxUI = Class.extend({ var that = this; this.communication.updateChat(this.name, function(xml) { - that.processMessages(xml); + that.processMessages(xml, true); + }); + }, + + sendMessage: function(message) { + var that = this; + + this.communication.sendChatMessage(this.name, message, function(xml) { + that.processMessages(xml, false); }); } }); \ No newline at end of file