From dd5b66247c1f69821888d4edca8f38f7b87665c4 Mon Sep 17 00:00:00 2001 From: neauoire Date: Sat, 9 Nov 2019 12:41:55 -0500 Subject: [PATCH] Updated theme --- desktop/sources/scripts/lib/theme.js | 33 +++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/desktop/sources/scripts/lib/theme.js b/desktop/sources/scripts/lib/theme.js index 8856e47..5104277 100644 --- a/desktop/sources/scripts/lib/theme.js +++ b/desktop/sources/scripts/lib/theme.js @@ -10,17 +10,20 @@ function Theme (client) { this.active = {} this.default = { - background: '#eee', - f_high: '#000', - f_med: '#999', - f_low: '#ccc', - f_inv: '#000', - b_high: '#000', - b_med: '#888', - b_low: '#aaa', + background: '#eeeeee', + f_high: '#000000', + f_med: '#666666', + f_low: '#888888', + f_inv: '#000000', + b_high: '#ffffff', + b_med: '#cccccc', + b_low: '#dddddd', b_inv: '#ffb545' } + // Callbacks + this.onLoad = () => {} + this.install = (host = document.body) => { window.addEventListener('dragover', this.drag) window.addEventListener('drop', this.drop) @@ -67,12 +70,22 @@ function Theme (client) { }` localStorage.setItem('theme', JSON.stringify(theme)) this.active = theme + if (this.onLoad) { + this.onLoad(data) + } } this.reset = () => { this.load(this.default) } + this.set = (key, val) => { + if (!val) { return } + const hex = (`${val}`.substr(0, 1) !== '#' ? '#' : '') + `${val}` + if (!isColor(hex)) { console.warn('Theme', `${hex} is not a valid color.`); return } + this.active[key] = hex + } + this.read = (key) => { return this.active[key] } @@ -143,6 +156,10 @@ function Theme (client) { return true } + function isColor (hex) { + return /^#([0-9A-F]{3}){1,2}$/i.test(hex) + } + function isJson (text) { try { JSON.parse(text); return true } catch (error) { return false } }