diff options
author | Florian Orben <florian.orben@gmail.com> | 2015-10-24 15:50:20 +0200 |
---|---|---|
committer | Florian Orben <florian.orben@gmail.com> | 2015-10-24 21:55:44 +0200 |
commit | 0f62befef06f7fc467571a87affdfa95fa1fbb81 (patch) | |
tree | e1bff7bd1da78a199053f76eb92ce6567417a87d /web/react/utils | |
parent | 113741243bee612b9e65530e1827a0891d96474c (diff) | |
download | chat-0f62befef06f7fc467571a87affdfa95fa1fbb81.tar.gz chat-0f62befef06f7fc467571a87affdfa95fa1fbb81.tar.bz2 chat-0f62befef06f7fc467571a87affdfa95fa1fbb81.zip |
code style theme chooser
Diffstat (limited to 'web/react/utils')
-rw-r--r-- | web/react/utils/constants.jsx | 7 | ||||
-rw-r--r-- | web/react/utils/utils.jsx | 26 |
2 files changed, 33 insertions, 0 deletions
diff --git a/web/react/utils/constants.jsx b/web/react/utils/constants.jsx index 1a1d7f39f..9c079bb87 100644 --- a/web/react/utils/constants.jsx +++ b/web/react/utils/constants.jsx @@ -300,6 +300,13 @@ module.exports = { uiName: 'Mention Highlight Link' } ], + CODE_THEMES: { + github: 'GitHub', + solarized_light: 'Solarized light', + monokai: 'Monokai', + solarized_dark: 'Solarized Dark' + }, + DEFAULT_CODE_THEME: 'github', Preferences: { CATEGORY_DIRECT_CHANNEL_SHOW: 'direct_channel_show', CATEGORY_DISPLAY_SETTINGS: 'display_settings' diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 67a9d6983..4074c1767 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -402,6 +402,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 +593,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') { |