2019-07-16 09:21:28 +02:00
|
|
|
/* 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
|
|
|
|
*/
|
2019-07-16 09:27:48 +02:00
|
|
|
export default class Theme {
|
2019-07-16 09:21:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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:')
|
|
|
|
}
|
|
|
|
}
|