The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Rocket.Chat/packages/rocketchat-ui-master/server/dynamic-css.js

35 lines
1.1 KiB

'use strict';
export default () => {
const debounce = (func, wait, immediate) => {
let timeout;
return function(...args) {
const later = () => {
timeout = null;
!immediate && func.apply(this, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
callNow && func.apply(this, args);
};
};
const style = document.createElement('style');
style.type = 'text/css';
DynamicCss = typeof DynamicCss !=='undefined'? DynamicCss : {list:[]};
const settingBackground = (setting) => `.${ setting._id }-background { background-color: ${ setting.value }; }`;
const settingColor = (setting) => `.${ setting._id }-color { color: ${ setting.value }; }`;
const properties = [settingBackground, settingColor];
const run = list => list.map(setting => properties.map(f => f(setting)).join('')).join('');
DynamicCss.run = debounce(() => {
const list = typeof RocketChat !== 'undefined' ? RocketChat.settings.collection.find({_id:/theme/}).fetch() : [];
return style.innerHTML = run(list.length && list || DynamicCss.list);
}, 1000);
document.head.appendChild(style);
DynamicCss.run();
};