Clickable URLs in text messages

This commit is contained in:
Mattias Erming 2014-04-10 23:58:08 +02:00
parent 30ea34ffd3
commit b574c87028

View file

@ -64,7 +64,12 @@ $(function() {
.first() .first()
.addClass("active"); .addClass("active");
chat.find(".messages").scrollGlue({animate: 400}).scrollToBottom(); chat.find(".messages")
.scrollGlue({animate: 400})
.scrollToBottom()
.find(".text")
.uri()
.end();
chat.find(".window") chat.find(".window")
.find("input") .find("input")
.tabComplete(commands, {appendSpace: true}) .tabComplete(commands, {appendSpace: true})
@ -122,9 +127,14 @@ $(function() {
if (message.type == "error") { if (message.type == "error") {
target = target.parent().find(".active"); target = target.parent().find(".active");
} }
var msg = $(render("#message", {messages: message}))
.find(".text")
.uri()
.end();
target = target.find(".messages"); target = target.find(".messages");
target.append(render("#message", {messages: message})); target.append(msg);
break; break;
} }
@ -247,8 +257,21 @@ $(function() {
.removeClass("active") .removeClass("active")
.end(); .end();
}; };
$.fn.uri = function() {
return this.each(function() {
var html = $(this).html();
return $(this).html(URI.withinString(html, function(url) {
return "<a href='" + url + "' target='_blank'>" + url + "</a>";
}));
});
};
}); });
function linkify(text) {
}
//Handlebars.registerHelper("link", function(text) { //Handlebars.registerHelper("link", function(text) {
// var text = Handlebars.Utils.escapeExpression(text); // var text = Handlebars.Utils.escapeExpression(text);
// return URI.withinString(text, function(url) { // return URI.withinString(text, function(url) {