Added styles support, fixed messages with no author, removed JQuery dep

This commit is contained in:
Jonas Dellinger
2017-05-26 00:51:34 +02:00
parent e750bbfac1
commit afa0b5bab2
6 changed files with 40 additions and 12 deletions

View File

@@ -6,6 +6,13 @@ Vue.component('message', {
computed: {
textEscaped() {
let s = this.template ? this.template : this.templates[this.templateId];
//This hack is required to preserve backwards compatability
if (this.templateId == CONFIG.defaultTemplateId
&& this.args.length == 1) {
s = this.templates[CONFIG.defaultAltTemplateId] //Swap out default template :/
}
s = s.replace(/{(\d+)}/g, (match, number) => {
const argEscaped = this.args[number] != undefined ? this.escape(this.args[number]) : match
if (number == 0 && this.color) {
@@ -19,10 +26,16 @@ Vue.component('message', {
},
methods: {
colorizeOld(str) {
return `<strong style="color: rgb(${this.color[0]}, ${this.color[1]}, ${this.color[2]})">${str}</strong>`
return `<span style="color: rgb(${this.color[0]}, ${this.color[1]}, ${this.color[2]})">${str}</span>`
},
colorize(str) {
const s = "<span>" + (str.replace(/\^([0-9]+)/g, (str, color) => `</span><span class="color-${color}">`)) + "</span>";
const s = "<span>" + (str.replace(/\^([0-9]+)([busr])|\^([0-9]+)|\^([busr])/g,
(match, color1, style1, color2, style2) => {
const color = (color1 || color2) ? `color-${color1 || color2} ` : '';
const style = (style1 || style2) ? `style-${style1 || style2} ` : '';
return `</span><span class="${color}${style}">`;
}
)) + "</span>";
return s.replace(/<span[^>]*><\/span[^>]*>/g, '');
},
escape(unsafe) {