1
0
mirror of https://github.com/citizenfx/cfx-server-data.git synced 2025-01-11 00:03:18 +08:00
cfx-server-data/resources/[system]/chat/html/Message.js

62 lines
1.5 KiB
JavaScript
Raw Normal View History

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() {
let s = this.template ? this.template : this.templates[this.templateId];
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
});
return this.colorize(s);
2017-05-18 01:22:20 +08:00
},
},
methods: {
2017-05-21 22:52:55 +08:00
colorizeOld(str) {
return `<strong style="color: rgb(${this.color[0]}, ${this.color[1]}, ${this.color[2]})">${str}</strong>`
},
colorize(str) {
const s = "<span>" + (str.replace(/\^([0-9]+)/g, (str, color) => `</span><span class="color-${color}">`)) + "</span>";
return s.replace(/<span[^>]*><\/span[^>]*>/g, '');
},
escape(unsafe) {
return String(unsafe)
2017-05-18 01:22:20 +08:00
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
},
},
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
});