2015-10-31 07:18:24 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ThemeChanger = {
|
2016-05-15 09:57:29 +02:00
|
|
|
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);
|
2016-04-03 11:32:38 +02:00
|
|
|
var metaThemeColor = document.head.querySelector('meta[name=theme-color]');
|
|
|
|
if (metaThemeColor) {
|
|
|
|
metaThemeColor.content = window.getComputedStyle(document.body).backgroundColor;
|
|
|
|
}
|
2016-05-15 09:57:29 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setFontSize: function(fontSize) {
|
|
|
|
document.documentElement.style.fontSize = fontSize ? (12 + fontSize * 2) + 'px' : '';
|
2015-10-31 07:18:24 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ThemeChanger;
|