Merge "Auto-hyperlink URLs"

This commit is contained in:
Zuul 2018-02-28 12:24:49 +00:00 committed by Gerrit Code Review
commit 1b7c9c851e
2 changed files with 6 additions and 3 deletions

View File

@ -31,7 +31,7 @@
{{#if (lookup @root.now track) }}
<tr>
<td class="col-sm-1"><span class="label label-primary {{track}}">{{track}}</span></td>
<td>{{#hashtag}}{{lookup @root.now track}}{{/hashtag}}</td>
<td>{{#trackContentLine}}{{lookup @root.now track}}{{/trackContentLine}}</td>
<td>{{lookup @root.location track}}</td>
</tr>
{{/if}}
@ -49,7 +49,7 @@
<td class="col-sm-1"><span class="label label-primary {{track}}">{{track}}</span></td>
<td>
{{#each (lookup @root.next track) as |item|}}
{{#hashtag}}{{item}}{{/hashtag}} <br/>
{{#trackContentLine}}{{item}}{{/trackContentLine}} <br/>
{{/each}}
</td>
</tr>

View File

@ -4,13 +4,16 @@ var source = document.getElementById("PTGtemplate").innerHTML;
// Handlebars compiles the above source into a template
var template = Handlebars.compile(source);
Handlebars.registerHelper('hashtag', function(options) {
Handlebars.registerHelper('trackContentLine', function(options) {
var words = options.fn(this).split(" ");
var sentence = "";
for (var i = 0; i < words.length; i++) {
if (words[i].startsWith("#")) {
sentence += '<span class="label label-info">'
+ words[i].substring(1) + '</span> ';
} else if (words[i].match(/^https?:\/\//)) {
sentence += '<a href="' + words[i] + '">'
+ words[i] + '</a>';
} else {
sentence += words[i] + " ";
}