Tumortisch-Dist/resources/app/node_modules/iwmlib/lib/card/theme.js
2021-06-15 16:00:08 +02:00

44 lines
1.4 KiB
JavaScript

/* eslint-disable no-unused-vars */
/**
* The Theme class helps manage the card themes.
* Usually it overrides or enhances aspects of the card.js.
*
* @class Theme
*/
export default class Theme {
/**
* Loads a config file and parses it to JSON.
*
* @static
* @param {string} [path=null] - Optional: A path where the config file is located at (including the filename and extension).
* @returns {Promise} - Returns a promise, that returns the parsed json file when resolved.
* @memberof Theme
*/
static loadConfig(path = null) {
return new Promise((resolve, reject) => {
path = path ? path : './config.json'
let xhttp = new XMLHttpRequest()
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200 || Theme._isLocal()) {
try {
const json = JSON.parse(this.responseText)
resolve(json)
} catch (e) {
reject(e)
}
} else reject('Invalid request : ' + this.status)
}
}
xhttp.open('GET', path, true)
xhttp.send()
})
}
static _isLocal() {
return window.location.protocol == 'file:'
}
}