diff options
author | tv <tv@nomic.retiolum> | 2013-11-06 18:31:00 +0100 |
---|---|---|
committer | tv <tv@nomic.retiolum> | 2013-11-06 18:31:00 +0100 |
commit | ec217561231481671be9e33ce8270ca2b7041a9c (patch) | |
tree | fd954d47e94f85b6cddb5212f16637356ea0f687 /webchat/public/client.js | |
parent | 20c7db3f85c066fc6c2abbf0ff7af47bdfdaadc9 (diff) | |
parent | b8035a82c362d24c2adf464a1c99fcc098b743c4 (diff) |
Merge branch 'master' of https://github.com/krebscode/painload
Diffstat (limited to 'webchat/public/client.js')
-rw-r--r-- | webchat/public/client.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/webchat/public/client.js b/webchat/public/client.js index 6bcb24cd..95b67ad0 100644 --- a/webchat/public/client.js +++ b/webchat/public/client.js @@ -1,7 +1,15 @@ -function replaceURLWithHTMLLinks(text) { +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]; + } +} + +var nick; $(function connect() { sock = new SockJS('/echo'); @@ -34,14 +42,21 @@ $(function connect() { }); $(function() { - $("#input").keydown(function(e) { - if( e.keyCode === 13) { + $('#input').keydown(function(e) { + if (e.keyCode === 13) { e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); - sock.send(JSON.stringify({ + setMaybeNick($('#input').val()); + var sendObj = { message: $('#input').val(), - })); + }; + + if (typeof nick === 'string') { + sendObj.nick = nick; + }; + + sock.send(JSON.stringify(sendObj)); $('#input').val(''); return; } |