2017-05-21 22:52:55 +08:00
|
|
|
Vue.component('message', {
|
2017-05-18 01:22:20 +08:00
|
|
|
template: '#message_template',
|
|
|
|
data() {
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
textEscaped() {
|
2017-05-22 04:54:39 +08:00
|
|
|
let s = this.template ? this.template : this.templates[this.templateId];
|
2017-05-26 06:51:34 +08:00
|
|
|
|
|
|
|
//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 :/
|
|
|
|
}
|
|
|
|
|
2017-05-22 04:54:39 +08:00
|
|
|
s = s.replace(/{(\d+)}/g, (match, number) => {
|
2017-05-21 22:52:55 +08:00
|
|
|
const argEscaped = this.args[number] != undefined ? this.escape(this.args[number]) : match
|
|
|
|
if (number == 0 && this.color) {
|
|
|
|
//color is deprecated, use templates or ^1 etc.
|
|
|
|
return this.colorizeOld(argEscaped);
|
|
|
|
}
|
|
|
|
return argEscaped;
|
2017-05-18 01:22:20 +08:00
|
|
|
});
|
2017-05-22 04:54:39 +08:00
|
|
|
return this.colorize(s);
|
2017-05-18 01:22:20 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2017-05-21 22:52:55 +08:00
|
|
|
colorizeOld(str) {
|
2017-05-26 06:51:34 +08:00
|
|
|
return `<span style="color: rgb(${this.color[0]}, ${this.color[1]}, ${this.color[2]})">${str}</span>`
|
2017-05-21 22:52:55 +08:00
|
|
|
},
|
|
|
|
colorize(str) {
|
2017-05-26 07:00:41 +08:00
|
|
|
const s = "<span>" + (str.replace(/\^([0-9]+)([\*\_\~r])|\^([0-9]+)|\^([\*\_\~r])/g,
|
2017-05-26 06:51:34 +08:00
|
|
|
(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>";
|
2017-05-21 22:52:55 +08:00
|
|
|
return s.replace(/<span[^>]*><\/span[^>]*>/g, '');
|
|
|
|
},
|
|
|
|
escape(unsafe) {
|
|
|
|
return String(unsafe)
|
2017-05-18 01:22:20 +08:00
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
.replace(/'/g, ''');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
props: {
|
2017-05-21 22:52:55 +08:00
|
|
|
templates: {
|
|
|
|
type: Object,
|
|
|
|
},
|
2017-05-18 01:22:20 +08:00
|
|
|
args: {
|
2017-05-21 22:52:55 +08:00
|
|
|
type: Array,
|
2017-05-18 01:22:20 +08:00
|
|
|
},
|
|
|
|
template: {
|
|
|
|
type: String,
|
2017-05-21 22:52:55 +08:00
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
templateId: {
|
|
|
|
type: String,
|
|
|
|
default: CONFIG.defaultTemplateId,
|
2017-05-18 01:22:20 +08:00
|
|
|
},
|
|
|
|
multiline: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2017-05-21 22:52:55 +08:00
|
|
|
color: { //deprecated
|
|
|
|
type: Array,
|
|
|
|
default: false,
|
2017-05-18 01:22:20 +08:00
|
|
|
},
|
|
|
|
},
|
2017-05-21 22:52:55 +08:00
|
|
|
});
|