Skip to content
Browse files

Add highlighting theme support.

  • Loading branch information...
1 parent 0d2a0a0 commit a79617c4090739b0735cc7308d4a881c42dff72b @nbeloglazov nbeloglazov committed Sep 1, 2012
Showing with 34 additions and 15 deletions.
  1. +26 −7 resources/public/script/codebox.js
  2. +6 −4 resources/public/script/foreclojure.js
  3. +2 −4 src/foreclojure/template.clj
View
33 resources/public/script/codebox.js
@@ -4,8 +4,7 @@ var CodeBox = {
element: null,
submitButtons: null,
editor: null,
- editorSession: null,
- editorElement: null,
+ allEditors: [],
high: false,
animationTime: 800,
waitTimePerItem: 500,
@@ -27,14 +26,16 @@ var CodeBox = {
},
setupEditor: function() {
-
- this.editorElement = $("#editor");
-
this.editor = CodeMirror.fromTextArea(this.element[0],
{mode: 'clojure',
- lineNumbers: true});
+ lineNumbers: true,
+ theme: this.getTheme()});
+ this.registerEditor(this.editor);
$(this.editor.getWrapperElement()).addClass('codebox');
-
+ $('#theme-selector').live('change', function() {
+ CodeBox.changeTheme($(this).val());
+ });
+ $('#theme-selector').val(this.getTheme());
},
getCode: function() {
@@ -134,4 +135,22 @@ var CodeBox = {
stopAnimation: function() {
this.images.stop(true).removeClass("animated").css({ opacity: 1.0, });
},
+
+ registerEditor: function(editor) {
+ this.allEditors.push(editor);
+ },
+
+ getTheme: function() {
+ var theme = window.localStorage && localStorage.getItem('theme');
+ return theme && theme.length > 0 ? theme : 'eclipse';
+ },
+
+ changeTheme: function(theme) {
+ $(this.allEditors).each(function(_, editor) {
+ editor.setOption('theme', theme);
+ });
+ if (window.localStorage) {
+ localStorage.setItem('theme', theme);
+ }
+ }
}
View
10 resources/public/script/foreclojure.js
@@ -248,10 +248,12 @@ function highlightPreElements() {
var hasLineNumbers = el.hasClass('test') ? false : true;
var editor = CodeMirror(function(editor) {
el.replaceWith(editor);
- }, { value: el.text(),
- mode: 'clojure',
- readOnly: true,
- lineNumbers: hasLineNumbers });
+ }, {value: el.text(),
+ mode: 'clojure',
+ readOnly: true,
+ lineNumbers: hasLineNumbers,
+ theme: CodeBox.getTheme()});
+ CodeBox.registerEditor(editor);
var editorDiv = $(editor.getWrapperElement());
editorDiv.attr('class', editorDiv.attr('class') + ' ' + el.attr('class'));
});
View
6 src/foreclojure/template.clj
@@ -8,7 +8,7 @@
[foreclojure.ring-utils :only [static-url]]
[foreclojure.version-utils :only [css js]]))
-(def codemirror-themes ["default" "ambiance" "blackboard" "cobalt" "eclipse" "elegant" "erlang-dark"
+(def codemirror-themes ["ambiance" "blackboard" "cobalt" "eclipse" "elegant" "erlang-dark"
"lesser-dark" "monokai" "neat" "night" "rubyblue" "vibrant-ink" "xq-dark"])
;; Global wrapping template
@@ -25,9 +25,7 @@
[:style {:type "text/css"}
".syntaxhighlighter { overflow-y: hidden !important; }"]
(css "css/style.css" "css/demo_table.css" "css/shCore.css" "css/shThemeDefault.css" "css/codemirror.css")
- (->> (rest codemirror-themes)
- (map #(format "css/themes/%s.css" %))
- (apply css))
+ (apply css (map #(format "css/theme/%s.css" %) codemirror-themes))
(js "vendor/script/jquery-1.5.2.min.js" "vendor/script/jquery.dataTables.min.js" "vendor/script/jquery.flipCounter.1.1.pack.js" "vendor/script/jquery.easing.1.3.js" "vendor/script/jquery.dataTables.fnSetFilteringDelay.js")
(js "script/codebox.js" "script/foreclojure.js")
(js "vendor/script/xregexp.js" "vendor/script/shCore.js" "vendor/script/shBrushClojure.js")

0 comments on commit a79617c

Please sign in to comment.
Something went wrong with that request. Please try again.