nightTab/js/theme.js

57 lines
1001 B
JavaScript
Raw Normal View History

2018-12-26 07:45:53 +00:00
var theme = (function() {
var state = {
2018-12-26 07:45:53 +00:00
r: 255,
g: 170,
b: 51,
};
var get = function() {
return state;
2018-12-26 07:45:53 +00:00
};
var bind = function() {
var themeAccent = helper.e(".theme-input");
themeAccent.addEventListener("change", function() {
_updateAcent(this);
render();
data.save();
});
};
var _updateAcent = function(input) {
state = helper.hexToRgb(input.value);
2018-12-26 07:45:53 +00:00
};
var _updateInput = function() {
var themeAccent = helper.e(".theme-input");
themeAccent.value = helper.rgbToHex(state);
2018-12-26 07:45:53 +00:00
};
var render = function(input) {
var html = helper.e("html");
html.style.setProperty("--accent", state.r + ", " + state.g + ", " + state.b);
2018-12-26 07:45:53 +00:00
};
var restore = function(object) {
2018-12-26 23:46:53 +00:00
if (object) {
state = object;
2018-12-26 23:46:53 +00:00
_updateInput();
render();
};
2018-12-26 07:45:53 +00:00
};
var init = function() {
bind();
};
// exposed methods
return {
init: init,
get: get,
restore: restore,
render: render
};
})();