diff --git a/www/code/main.js b/www/code/main.js
index f0354292c..42b34567a 100644
--- a/www/code/main.js
+++ b/www/code/main.js
@@ -10,10 +10,11 @@ define([
'/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js',
'/code/modes.js',
+ '/code/themes.js',
'/bower_components/file-saver/FileSaver.min.js',
'/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js'
-], function (Config, /*RTCode,*/ Messages, Crypto, Realtime, TextPatcher, Toolbar, JSONSortify, JsonOT, Cryptpad, Modes) {
+], function (Config, /*RTCode,*/ Messages, Crypto, Realtime, TextPatcher, Toolbar, JSONSortify, JsonOT, Cryptpad, Modes, Themes) {
var $ = window.jQuery;
var saveAs = window.saveAs;
var module = window.APP = {};
@@ -51,15 +52,46 @@ define([
readOnly: true
});
- var setMode = module.setMode = function (mode) {
+ var setMode = module.setMode = function (mode, $select) {
if (mode === 'text') {
editor.setOption('mode', 'text');
return;
}
CodeMirror.autoLoadMode(editor, mode);
editor.setOption('mode', mode);
+ if ($select && select.val) { $select.val(mode); }
};
+
+ var setTheme = module.setTheme = (function () {
+ var path = './theme/';
+
+ var $head = $(ifrw.document.head);
+
+ var themeLoaded = module.themeLoaded = function (theme) {
+ return $head.find('link[href*="'+theme+'"]').length;
+ };
+
+ var loadTheme = module.loadTheme = function (theme) {
+ $head.append($('', {
+ rel: 'stylesheet',
+ href: path + theme + '.css',
+ }));
+ };
+
+ return function (theme, $select) {
+ if (!theme) {
+ editor.setOption('theme', 'default');
+ } else {
+ if (!themeLoaded(theme)) {
+ loadTheme(theme);
+ }
+ editor.setOption('theme', theme);
+ }
+ if ($select && select.val) { $select.val(theme || 'default'); }
+ };
+ }());
+
var setEditable = module.setEditable = function (bool) {
editor.setOption('readOnly', !bool);
};
@@ -177,21 +209,40 @@ define([
onLocal();
}));
- var dropdown = '