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

@ -80,6 +80,10 @@ class SteamWorkshopElem extends HTMLElement
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);
@ -164,6 +168,10 @@ class SteamWorkshopElem extends HTMLElement
`;
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_WORKSHOP_ENDPOINT + '/api/query/workshop?itemid=' + itemid, true);
@ -296,6 +304,9 @@ class SteamWorkshop
var styleColorDescription = null;
var styleColorStatsCount = null;
var styleColorStatsLabel = null;
var evtOnInit = null;
var evtOnCompleted = null;
if (typeof config.style !== 'undefined') {
styleBorder = (typeof config.style.border !== 'undefined') ? config.style.border : null;
@ -307,6 +318,11 @@ class SteamWorkshop
styleColorStatsLabel = (typeof config.style.colorStatsLabel !== 'undefined') ? config.style.colorStatsLabel : 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;
}
@ -327,6 +343,18 @@ class SteamWorkshop
this.elem.setAttribute('style-color-stats-count', styleColorStatsCount);
this.elem.setAttribute('style-color-stats-label', styleColorStatsLabel);
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) {
sel.appendChild(this.elem);