mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-12-12 06:14:09 +01:00
chat: theming support, hide chat when not needed, other minor changes
This commit is contained in:
@@ -6,6 +6,7 @@ window.APP = {
|
||||
style: CONFIG.style,
|
||||
showInput: false,
|
||||
showWindow: false,
|
||||
shouldHide: true,
|
||||
backingSuggestions: [],
|
||||
removedSuggestions: [],
|
||||
templates: CONFIG.templates,
|
||||
@@ -13,6 +14,8 @@ window.APP = {
|
||||
messages: [],
|
||||
oldMessages: [],
|
||||
oldMessagesIndex: -1,
|
||||
tplBackups: [],
|
||||
msgTplBackups: []
|
||||
};
|
||||
},
|
||||
destroyed() {
|
||||
@@ -48,6 +51,9 @@ window.APP = {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
ON_SCREEN_STATE_CHANGE({ shouldHide }) {
|
||||
this.shouldHide = shouldHide;
|
||||
},
|
||||
ON_OPEN() {
|
||||
this.showInput = true;
|
||||
this.showWindow = true;
|
||||
@@ -91,6 +97,85 @@ window.APP = {
|
||||
this.templates[template.id] = template.html;
|
||||
}
|
||||
},
|
||||
ON_UPDATE_THEMES({ themes }) {
|
||||
this.removeThemes();
|
||||
|
||||
this.setThemes(themes);
|
||||
},
|
||||
removeThemes() {
|
||||
for (let i = 0; i < document.styleSheets.length; i++) {
|
||||
const styleSheet = document.styleSheets[i];
|
||||
const node = styleSheet.ownerNode;
|
||||
|
||||
if (node.getAttribute('data-theme')) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
this.tplBackups.reverse();
|
||||
|
||||
for (const [ elem, oldData ] of this.tplBackups) {
|
||||
elem.innerText = oldData;
|
||||
}
|
||||
|
||||
this.tplBackups = [];
|
||||
|
||||
this.msgTplBackups.reverse();
|
||||
|
||||
for (const [ id, oldData ] of this.msgTplBackups) {
|
||||
this.templates[id] = oldData;
|
||||
}
|
||||
|
||||
this.msgTplBackups = [];
|
||||
},
|
||||
setThemes(themes) {
|
||||
for (const [ id, data ] of Object.entries(themes)) {
|
||||
if (data.style) {
|
||||
const style = document.createElement('style');
|
||||
style.type = 'text/css';
|
||||
style.setAttribute('data-theme', id);
|
||||
style.appendChild(document.createTextNode(data.style));
|
||||
|
||||
document.head.appendChild(style);
|
||||
}
|
||||
|
||||
if (data.styleSheet) {
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.type = 'text/css';
|
||||
link.href = data.baseUrl + data.styleSheet;
|
||||
link.setAttribute('data-theme', id);
|
||||
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
|
||||
if (data.templates) {
|
||||
for (const [ tplId, tpl ] of Object.entries(data.templates)) {
|
||||
const elem = document.getElementById(tplId);
|
||||
|
||||
if (elem) {
|
||||
this.tplBackups.push([ elem, elem.innerText ]);
|
||||
elem.innerText = tpl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.script) {
|
||||
const script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = data.baseUrl + data.script;
|
||||
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
if (data.msgTemplates) {
|
||||
for (const [ tplId, tpl ] of Object.entries(data.msgTemplates)) {
|
||||
this.msgTplBackups.push([ tplId, this.templates[tplId] ]);
|
||||
this.templates[tplId] = tpl;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
warn(msg) {
|
||||
this.messages.push({
|
||||
args: [msg],
|
||||
|
||||
Reference in New Issue
Block a user