diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-05-31 08:15:33 -0400 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2016-05-31 08:15:33 -0400 |
commit | c5deb333db40e4e527f98edb93b41d1b66cfec5f (patch) | |
tree | 8585da3f41551592c23e4fb54c514a4c069ee957 /webapp/utils | |
parent | 64cce071a9ae28444e95b6389b229d80f20acf68 (diff) | |
download | chat-c5deb333db40e4e527f98edb93b41d1b66cfec5f.tar.gz chat-c5deb333db40e4e527f98edb93b41d1b66cfec5f.tar.bz2 chat-c5deb333db40e4e527f98edb93b41d1b66cfec5f.zip |
Added validation to make sure theme entries are colours (#3107)
* Added validation to make sure theme entries are colours
* Added serverside validation for theme
Diffstat (limited to 'webapp/utils')
-rw-r--r-- | webapp/utils/utils.jsx | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx index 9b0e370bf..7d904387d 100644 --- a/webapp/utils/utils.jsx +++ b/webapp/utils/utils.jsx @@ -556,6 +556,10 @@ export function toTitleCase(str) { return str.replace(/\w\S*/g, doTitleCase); } +export function isHexColor(value) { + return value && (/^#[0-9a-f]{3}([0-9a-f]{3})?$/i).test(value); +} + export function applyTheme(theme) { if (theme.sidebarBg) { changeCss('.app__body .sidebar--left, .app__body .sidebar--left .sidebar__divider .sidebar__divider__text, .app__body .modal .settings-modal .settings-table .settings-links, .app__body .sidebar--menu', 'background:' + theme.sidebarBg, 1); @@ -782,18 +786,6 @@ export function changeCss(className, classValue, classRepeat) { classContainer.html('<style>' + className + ' {' + classValue + '}</style>'); } -export function rgb2hex(rgbIn) { - if (/^#[0-9A-F]{6}$/i.test(rgbIn)) { - return rgbIn; - } - - var rgb = rgbIn.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); - function hex(x) { - return ('0' + parseInt(x, 10).toString(16)).slice(-2); - } - return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); -} - export function updateCodeTheme(userTheme) { let cssPath = ''; Constants.THEME_ELEMENTS.forEach((element) => { |