summaryrefslogtreecommitdiffstats
path: root/webchat/public
diff options
context:
space:
mode:
authorlassulus <lassulus@googlemail.com>2013-11-06 15:36:30 +0100
committerlassulus <lassulus@googlemail.com>2013-11-06 15:36:30 +0100
commita7f6ce941d3001649f7b51f53783e1c2e923b2c2 (patch)
treea7426d9d318175f30c2d8f170c6fa38d3024ec63 /webchat/public
parent54934a67b50d9e5f7b3050bb935b1a2a6997e578 (diff)
webchat: clickable links
Diffstat (limited to 'webchat/public')
-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);