From d49ee1326b3eeff37bc32de7f1e68e1a543e2e25 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Mon, 21 Apr 2014 12:27:43 +0200 Subject: [PATCH] Parse URLs with Handlebars --- client/index.html | 2 +- client/js/chat.js | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/client/index.html b/client/index.html index 0e5ffc8..e50fcbe 100644 --- a/client/index.html +++ b/client/index.html @@ -114,7 +114,7 @@
{{time}}
{{from}}
{{type}}
-
{{text}}
+
{{{uri text}}}
{{/each}} diff --git a/client/js/chat.js b/client/js/chat.js index 68c54fa..1331b2c 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -35,13 +35,6 @@ $(function() { return tpl[id](json); } - Handlebars.registerHelper( - "partial", - function(id) { - return new Handlebars.SafeString(render(id, this)); - } - ); - function handleEvent(event, json) { var data = json.data; switch (event) { @@ -244,12 +237,6 @@ $(function() { chat.on("focus", "input[type=text]", function() { $(this).closest(".window").find(".messages").scrollToBottom(); }); - - function uri(text) { - return URI.withinString(text, function(url) { - return "" + url + ""; - }); - } var highest = 1; $.fn.bringToTop = function() { @@ -262,4 +249,34 @@ $(function() { .removeClass("active") .end(); }; + + function uri(text) { + return URI.withinString(text, function(url) { + return "" + url + ""; + }); + } + + function escape(string) { + var e = { + "<": "<", + ">": ">", + }; + return string.replace(/[<>]/g, function (s) { + return e[s]; + }); + } + + Handlebars.registerHelper( + "uri", + function(text) { + return uri(escape(text)); + } + ); + + Handlebars.registerHelper( + "partial", + function(id) { + return new Handlebars.SafeString(render(id, this)); + } + ); });