Make URLs in MOTD messages clickable
A long-wanted feature! Since the MOTD can only be controlled by an admin, the risk of abuse is very limited. Change-Id: Iff6263059d76c9b75ae26e029e3063992ab7cb76
This commit is contained in:
parent
a0d3fbab41
commit
415ae5a05e
@ -24,7 +24,7 @@
|
||||
</nav>
|
||||
<script id="MOTDTemplate" type="text/x-handlebars-template">
|
||||
{{#each motd}}
|
||||
<div class="alert alert-{{this.level}}" role="alert">{{this.message}}</div>
|
||||
<div class="alert alert-{{this.level}}" role="alert">{{ linkify this.message }}</div>
|
||||
{{/each}}
|
||||
</script>
|
||||
<div id="MOTD"></div>
|
||||
|
@ -24,7 +24,7 @@
|
||||
</nav>
|
||||
<script id="MOTDTemplate" type="text/x-handlebars-template">
|
||||
{{#each motd}}
|
||||
<div class="alert alert-{{this.level}}" role="alert">{{this.message}}</div>
|
||||
<div class="alert alert-{{this.level}}" role="alert">{{ linkify this.message }}</div>
|
||||
{{/each}}
|
||||
</script>
|
||||
<div id="MOTD"></div>
|
||||
|
@ -4,6 +4,14 @@ var dsource = document.getElementById("MOTDTemplate").innerHTML;
|
||||
// Handlebars compiles the above source into a template
|
||||
var dtemplate = Handlebars.compile(dsource);
|
||||
|
||||
Handlebars.registerHelper('linkify', function(str) {
|
||||
var pattern1 = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||
var str1 = str.replace(pattern1, '<a target="_blank" href="$1">$1</a>');
|
||||
var pattern2 =/(^|[^\/])(www\.[\S]+(\b|$))/gim;
|
||||
var str2 = str1.replace(pattern2, '$1<a target="_blank" href="http://$2">$2</a>');
|
||||
return new Handlebars.SafeString(str2);
|
||||
});
|
||||
|
||||
$.getJSON("ptg.json", function(json) {
|
||||
document.getElementById("MOTD").innerHTML = dtemplate(json);
|
||||
});
|
||||
|
@ -24,7 +24,7 @@
|
||||
</nav>
|
||||
<script id="MOTDTemplate" type="text/x-handlebars-template">
|
||||
{{#each motd}}
|
||||
<div class="alert alert-{{this.level}}" role="alert">{{this.message}}</div>
|
||||
<div class="alert alert-{{this.level}}" role="alert">{{ linkify this.message }}</div>
|
||||
{{/each}}
|
||||
</script>
|
||||
<div id="MOTD"></div>
|
||||
|
Loading…
Reference in New Issue
Block a user