Moved files from src/htmlcards to iwmlib.
This commit is contained in:
parent
9a399ecfe9
commit
54912ad37e
2559
lib/card/card.js
Normal file
2559
lib/card/card.js
Normal file
File diff suppressed because it is too large
Load Diff
46
lib/card/theme.js
Normal file
46
lib/card/theme.js
Normal file
@ -0,0 +1,46 @@
|
||||
/* 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
|
||||
*/
|
||||
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:')
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user