summaryrefslogtreecommitdiffstats
path: root/webchat/public/client.js
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2013-11-06 15:46:13 +0100
committertv <tv@nomic.retiolum>2013-11-06 15:46:13 +0100
commit99f2dcbdf02d917ae10828ae6b9a34013d6f233b (patch)
tree9c1bc5260130ac532661c88b072bbbbdf8dede76 /webchat/public/client.js
parent088b7ec8246ed240b256afc9c0a0a496c73f2272 (diff)
parent7322fce37c76c0dd4a53ddc5be984d1d904c660a (diff)
Merge branch 'master' of https://github.com/krebscode/painload
Diffstat (limited to 'webchat/public/client.js')
-rw-r--r--webchat/public/client.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/webchat/public/client.js b/webchat/public/client.js
index 119913ae..6bcb24cd 100644
--- a/webchat/public/client.js
+++ b/webchat/public/client.js
@@ -1,3 +1,8 @@
+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 connect() {
sock = new SockJS('/echo');
@@ -10,9 +15,10 @@ $(function connect() {
try {
var object = JSON.parse(e.data);
console.log(object.message);
- var safe_message = $('<div/>').text(object.message).html()
- var safe_from = $('<div/>').text(object.from).html()
- $('#chatbox').append('<tr><td class="from">'+safe_from+'</td><td>'+safe_message+'</td></tr>');
+ var safe_message = $('<div/>').text(object.message).html();
+ safe_message = replaceURLWithHTMLLinks(safe_message);
+ var safe_from = $('<div/>').text(object.from).html();
+ $('#chatbox').append('<tr><td class="chat_from">'+safe_from+'</td><td class="chat_msg">'+safe_message+'</td></tr>');
} catch (error) {
console.log(error);