summaryrefslogtreecommitdiffstats
path: root/webchat/public/client.js
diff options
context:
space:
mode:
authorlassulus <lassulus@googlemail.com>2013-11-08 13:15:52 +0100
committerlassulus <lassulus@googlemail.com>2013-11-08 13:15:52 +0100
commit2d823c8f8557f0a49e4307717e99a90b24052e9c (patch)
treee4f8bb03435b5385189ee6a9552c5afe616e7835 /webchat/public/client.js
parent9210cdcdd8f9b7cf1bc48dcc01914b1d2530820d (diff)
webchat: refactored code
Diffstat (limited to 'webchat/public/client.js')
-rw-r--r--webchat/public/client.js58
1 files changed, 7 insertions, 51 deletions
diff --git a/webchat/public/client.js b/webchat/public/client.js
index ca71b537..4842d9c2 100644
--- a/webchat/public/client.js
+++ b/webchat/public/client.js
@@ -1,34 +1,4 @@
-function replaceURLWithHTMLLinks (text) {
- var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
- return text.replace(exp,"<a href='$1'>$1</a>");
-}
-function setMaybeNick (input) {
- var match = /^\/nick\s+(.+)$/.exec(input);
- if (match) {
- nick = match[1];
- $('#nick').html(nick);
- }
-}
-
-function getCurTime () {
- date = new Date;
- h = date.getHours();
- if(h<10)
- {
- h = "0"+h;
- }
- m = date.getMinutes();
- if(m<10)
- {
- m = "0"+m;
- }
- s = date.getSeconds();
- if(s<10)
- {
- s = "0"+s;
- }
- return ''+h+':'+m+':'+s;
-};
+var settings = {}
$(function updateTime () {
$('#time').html(getCurTime());
@@ -36,8 +6,6 @@ $(function updateTime () {
return true;
});
-var nick;
-
$(function connect() {
sock = new SockJS('/echo');
@@ -50,16 +18,11 @@ $(function connect() {
try {
var object = JSON.parse(e.data);
console.log(object.message);
- var safe_message = $('<div/>').text(object.message).html();
- safe_message = replaceURLWithHTMLLinks(safe_message);
- var safe_from = $('<div/>').text(object.from).html();
- $('<tr><td class="chat_date">'+getCurTime()+'</td><td class="chat_from">'+safe_from+'</td><td class="chat_msg">'+safe_message+'</td></tr>').insertBefore('#foot');
-
- var elem = document.getElementById('chatter');
- elem.scrollTop = elem.scrollHeight;
+ clientParser(object);
} catch (error) {
console.log(error);
+ throw error;
}
};
sock.onclose = function(event) {
@@ -77,18 +40,11 @@ $(function() {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
- setMaybeNick($('#input').val());
- var sendObj = {
- message: $('#input').val(),
- };
-
- if (typeof nick === 'string') {
- sendObj.nick = nick;
- };
-
- sock.send(JSON.stringify(sendObj));
+ var input = ($('#input').val());
$('#input').val('');
- return;
+
+ var command = inputParser(input)
+ return (commands[command.method] || commands.badcommand)(settings, command.params)
}
});