diff options
author | =Corey Hulen <corey@hulen.com> | 2015-10-26 22:11:42 -0700 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-10-26 22:11:42 -0700 |
commit | aec99ceb9d47d6354ac5a96bbc290126b55d30f5 (patch) | |
tree | ecb72b0d51f6edc7341ac5bef0a4f61583f81dde /web/react/utils/utils.jsx | |
parent | e750a8fd361ef6dfce557530a10aaf5ce5a7f37e (diff) | |
parent | 28847c6b4b864d747bbfdf5c53354dcb24e5f895 (diff) | |
download | chat-aec99ceb9d47d6354ac5a96bbc290126b55d30f5.tar.gz chat-aec99ceb9d47d6354ac5a96bbc290126b55d30f5.tar.bz2 chat-aec99ceb9d47d6354ac5a96bbc290126b55d30f5.zip |
Merge branch 'master' into PLT-25
Diffstat (limited to 'web/react/utils/utils.jsx')
-rw-r--r-- | web/react/utils/utils.jsx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 67a9d6983..7a876d518 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -20,6 +20,7 @@ export function isEmail(email) { export function cleanUpUrlable(input) { var cleaned = input.trim().replace(/-/g, ' ').replace(/[^\w\s]/gi, '').toLowerCase().replace(/\s/g, '-'); + cleaned = cleaned.replace(/-{2,}/, '-'); cleaned = cleaned.replace(/^\-+/, ''); cleaned = cleaned.replace(/\-+$/, ''); return cleaned; @@ -402,6 +403,11 @@ export function toTitleCase(str) { } export function applyTheme(theme) { + if (!theme.codeTheme) { + theme.codeTheme = Constants.DEFAULT_CODE_THEME; + } + updateCodeTheme(theme.codeTheme); + if (theme.sidebarBg) { changeCss('.sidebar--left, .settings-modal .settings-table .settings-links, .sidebar--menu', 'background:' + theme.sidebarBg, 1); } @@ -588,6 +594,27 @@ export function rgb2hex(rgbIn) { return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } +export function updateCodeTheme(theme) { + const path = '/static/css/highlight/' + theme + '.css'; + const $link = $('link.code_theme'); + if (path !== $link.attr('href')) { + changeCss('code.hljs', 'visibility: hidden'); + var xmlHTTP = new XMLHttpRequest(); + xmlHTTP.open('GET', path, true); + xmlHTTP.onload = function onLoad() { + $link.attr('href', path); + if (isBrowserFirefox()) { + $link.one('load', () => { + changeCss('code.hljs', 'visibility: visible'); + }); + } else { + changeCss('code.hljs', 'visibility: visible'); + } + }; + xmlHTTP.send(); + } +} + export function placeCaretAtEnd(el) { el.focus(); if (typeof window.getSelection != 'undefined' && typeof document.createRange != 'undefined') { |