Browse Source

Moved files from src/htmlcards to iwmlib.

obersalzberg
Uwe Oestermeier 1 year ago
parent
commit
54912ad37e
2 changed files with 2605 additions and 0 deletions
  1. +2559
    -0
      lib/card/card.js
  2. +46
    -0
      lib/card/theme.js

+ 2559
- 0
lib/card/card.js
File diff suppressed because it is too large
View File


+ 46
- 0
lib/card/theme.js View 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…
Cancel
Save