web-apps/apps/common/main/lib/util/themeinit.js

28 lines
963 B
JavaScript
Raw Normal View History

2021-06-25 08:53:43 +00:00
+function init_themes() {
var objtheme = localStorage.getItem("ui-theme");
if ( typeof(objtheme) == 'string' &&
objtheme.startsWith("{") && objtheme.endsWith("}") )
{
objtheme = JSON.parse(objtheme);
}
var ui_theme_name = objtheme && typeof(objtheme) == 'object' ? objtheme.id :
typeof(objtheme) == 'string' ? objtheme : localStorage.getItem("ui-theme-id");
if ( !!ui_theme_name ) {
if ( !!objtheme && !!objtheme.colors ) {
var colors = [];
for ( var c in objtheme.colors ) {
colors.push('--' + c + ':' + objtheme.colors[c]);
}
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '.' + ui_theme_name + '{'+ colors.join(';') +';}';
document.getElementsByTagName('head')[0].appendChild(style);
window.currentLoaderTheme = objtheme;
}
}
}();