This commit is contained in:
Daniel Brendel
2023-05-12 14:03:02 +02:00
parent b2f5eecbf1
commit 20d4b03628
11 changed files with 538 additions and 123 deletions

View File

@ -74,11 +74,15 @@
{
var req = new XMLHttpRequest();
var self = this;
if ((typeof self.custom_events !== 'undefined') && (typeof self.custom_events.eventOnInit !== 'undefined')) {
self.dispatchEvent(self.custom_events.eventOnInit);
}
req.onreadystatechange = function() {
if (req.readyState == XMLHttpRequest.DONE) {
let json = JSON.parse(req.responseText);
if (!document.getElementById('steamwidgets-user-styles')) {
let link = document.createElement('link');
link.id = 'steamwidgets-user-styles';
@ -170,6 +174,10 @@
`;
self.innerHTML = html;
if ((typeof self.custom_events !== 'undefined') && (typeof self.custom_events.eventOnCompleted !== 'undefined')) {
self.dispatchEvent(self.custom_events.eventOnCompleted);
}
}
};
req.open('GET', STEAMWIDGETS_USER_ENDPOINT + '/api/query/user?steamid=' + steamid, true);
@ -281,6 +289,9 @@
var styleColorBackground = null;
var styleColorTextBright = null;
var styleColorTextDark = null;
var evtOnInit = null;
var evtOnCompleted = null;
if (typeof config.style !== 'undefined') {
styleBorder = (typeof config.style.border !== 'undefined') ? config.style.border : null;
@ -289,6 +300,11 @@
styleColorTextBright = (typeof config.style.colorTextBright !== 'undefined') ? config.style.colorTextBright : null;
styleColorTextDark = (typeof config.style.colorTextDark !== 'undefined') ? config.style.colorTextDark : null;
}
if (typeof config.events !== 'undefined') {
evtOnInit = (typeof config.events.onInit === 'function') ? config.events.onInit : null;
evtOnCompleted = (typeof config.events.onCompleted === 'function') ? config.events.onCompleted : null;
}
if (typeof styleShadow === 'boolean') {
styleShadow = (styleShadow) ? 1 : 0;
@ -314,6 +330,18 @@
if (height !== null) {
this.elem.setAttribute('height', height);
}
this.elem.custom_events = {};
if (evtOnInit !== null) {
this.elem.custom_events.eventOnInit = new CustomEvent('onInit', { detail: this });
this.elem.addEventListener('onInit', evtOnInit, false);
}
if (evtOnCompleted !== null) {
this.elem.custom_events.eventOnCompleted = new CustomEvent('onCompleted', { detail: this });
this.elem.addEventListener('onCompleted', evtOnCompleted, false);
}
let sel = document.querySelector(selector);
if (sel) {