keeweb/app/scripts/util/theme-changer.js

32 lines
937 B
JavaScript
Raw Normal View History

2015-10-31 07:18:24 +01:00
'use strict';
var ThemeChanger = {
setBySettings: function(settings) {
if (settings.get('theme')) {
this.setTheme(settings.get('theme'));
}
if (settings.get('fontSize')) {
this.setFontSize(settings.get('fontSize'));
}
},
2015-10-31 07:18:24 +01:00
setTheme: function(theme) {
2016-07-17 13:30:38 +02:00
_.forEach(document.body.classList, cls => {
2015-10-31 07:18:24 +01:00
if (/^th\-/.test(cls)) {
document.body.classList.remove(cls);
}
});
document.body.classList.add('th-' + theme);
var metaThemeColor = document.head.querySelector('meta[name=theme-color]');
if (metaThemeColor) {
metaThemeColor.content = window.getComputedStyle(document.body).backgroundColor;
}
},
setFontSize: function(fontSize) {
document.documentElement.style.fontSize = fontSize ? (12 + fontSize * 2) + 'px' : '';
2015-10-31 07:18:24 +01:00
}
};
module.exports = ThemeChanger;