Linkify urls in chat

This commit is contained in:
Mattias Erming 2014-03-23 00:42:07 +01:00
parent 8049e93703
commit 98331decd6
4 changed files with 2012 additions and 5 deletions

View file

@ -100,7 +100,7 @@
<div class="message {{type}}">
<span class="time">{{time}}</span>
<a href="{{user}}" class="user">{{mode}}{{user}}</a>
<span class="text">{{type}} {{text}}</span>
<span class="text">{{type}} {{{autoLink text}}}</span>
</div>
{{/each}}
</div>
@ -125,7 +125,7 @@
<div class="message {{type}}">
<span class="time">{{time}}</span>
<a href="{{user}}" class="user">{{mode}}{{user}}</a>
<span class="text">{{type}} {{text}}</span>
<span class="text">{{type}} {{{autoLink text}}}</span>
</div>
{{/messages}}
</script>
@ -136,6 +136,7 @@
<script src="/js/lib/jquery.cookie.js"></script>
<script src="/js/lib/jquery.scrollGlue.js"></script>
<script src="/js/lib/bootstrap.js"></script>
<script src="/js/lib/URI.js"></script>
<script src="/js/chat.js"></script>
</div>

View file

@ -14,7 +14,7 @@ $(function() {
tpl[id] = tpl[id] || Handlebars.compile($(id).html());
return tpl[id](json);
}
function event(type, json) {
switch (type) {
@ -213,4 +213,11 @@ $(function() {
.removeClass("active")
.end();
};
});
});
Handlebars.registerHelper("autoLink", function(text) {
var text = Handlebars.Utils.escapeExpression(text);
return URI.withinString(text, function(url) {
return "<a href='" + url + "' target='_blank'>" + url + "</a>";
});
});

2000
client/js/lib/URI.js Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long