Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move theme selector to settings page.

  • Loading branch information...
commit 57e8c6d4103581e3c03a62f7d9004a23f8c7b220 1 parent eb429c0
@nbeloglazov nbeloglazov authored
View
36 resources/public/css/style.css
@@ -561,26 +561,12 @@ button:active {
#instruct{
font-weight: bold;
- padding-top: 10px;
- float: left;
-}
-
-.theme-holder {
- float: right;
- font-weight: bold;
- padding-top: 10px;
-}
-
-.margin-right {
- margin-right: 10px;
-}
-
-#theme-selector {
- margin-left: 5px;
+ padding-top: 25px;
+ width: 100%;
}
-.clearfix {
- clear: both;
+#theme {
+ margin-bottom: 10px;
}
#golfheader{
@@ -634,16 +620,17 @@ a.graph-class :hover {color: #445599;}
font-weight: bold;
}
-.solution-user-code {
- border-left: #DDD solid 2px;
- padding: 15px;
- margin-bottom: 25px;
-}
-
.solution-code {
padding: 10px;
}
+.solution-user-code {
+ border: #AAA solid 10px;
+ padding: 0px;
+ margin-bottom: 25px;
+ border-radius: 5px;
+}
+
.CodeMirror {
font-size: 14px;
}
@@ -672,4 +659,3 @@ hr.solution {
margin-bottom: 20px;
}
-
View
33 resources/public/script/codebox.js
@@ -16,8 +16,9 @@ var CodeBox = {
|| $.browser.mobile;
this.element = $("#code-box");
this.submitButtons = $("#run-button, #submission-button");
+ var isSettingsPage = $('#settings #code-box').length > 0;
- if(!this.disableJavascript && this.submitButtons.length > 0) {
+ if(!this.disableJavascript && this.submitButtons.length > 0 || isSettingsPage) {
this.setupEditor();
}
@@ -29,13 +30,13 @@ var CodeBox = {
this.editor = CodeMirror.fromTextArea(this.element[0],
{mode: 'clojure',
lineNumbers: true,
- theme: this.getTheme()});
- this.registerEditor(this.editor);
+ theme: this.theme});
$(this.editor.getWrapperElement()).addClass('codebox');
- $('#theme-selector').live('change', function() {
- CodeBox.changeTheme($(this).val());
+ $('#theme').live('change', function() {
+ var theme = $(this).val();
+ CodeBox.editor.setOption('theme', theme);
});
- $('#theme-selector').val(this.getTheme());
+ $('#theme').val(this.theme);
},
getCode: function() {
@@ -47,7 +48,7 @@ var CodeBox = {
toggle: function() {
if(this.disableJavascript)
- $(".codebox").toggle('fast');
+ $("#code-box").toggle('fast');
else
$(".codebox").toggle('fast');
},
@@ -135,22 +136,4 @@ 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
6 resources/public/script/foreclojure.js
@@ -246,15 +246,15 @@ function updateProblemCount() {
function highlightPreElements() {
$('pre').each(function() {
var el = $(this);
- var hasLineNumbers = el.hasClass('test') ? false : true;
+ // Don't show line numbers if current element is test or it is an example on help page.
+ var hasLineNumbers = !(el.hasClass('test') || el.parents('#getting-started').length > 0);
var editor = CodeMirror(function(editor) {
el.replaceWith(editor);
}, {value: el.text(),
mode: 'clojure',
readOnly: true,
lineNumbers: hasLineNumbers,
- theme: CodeBox.getTheme()});
- CodeBox.registerEditor(editor);
+ theme: CodeBox.theme});
var editorDiv = $(editor.getWrapperElement());
editorDiv.attr('class', editorDiv.attr('class') + ' ' + el.attr('class'));
});
View
6 src/foreclojure/problems.clj
@@ -8,7 +8,7 @@
(:import [org.apache.commons.mail EmailException])
(:use [foreclojure.utils :only [from-mongo get-user get-solved login-link flash-msg flash-error row-class approver? can-submit? send-email image-builder if-user with-user as-int maybe-update escape-html]]
[foreclojure.ring-utils :only [*url*]]
- [foreclojure.template :only [def-page content-page codemirror-themes]]
+ [foreclojure.template :only [def-page content-page]]
[foreclojure.social :only [tweet-link]]
[foreclojure.feeds :only [create-feed]]
[foreclojure.users :only [golfer? get-user-id disable-codebox?]]
@@ -308,10 +308,6 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
[:br]
[:br]
[:p#instruct "Code which fills in the blank: "]
- [:div.theme-holder
- "High-lighting theme:"
- (drop-down :theme-selector codemirror-themes)]
- [:div.clearfix]
(when (wants-no-javascript-codebox?) [:span#disable-javascript-codebox])
(text-area {:id "code-box"
:name "code"
View
46 src/foreclojure/settings.clj
@@ -2,8 +2,9 @@
(:require [noir.session :as session]
[ring.util.response :as response])
(:import [org.jasypt.util.password StrongPasswordEncryptor])
- (:use [hiccup.form :only [form-to label text-field password-field check-box]]
- [foreclojure.utils :only [from-mongo flash-error flash-msg with-user form-row assuming send-email login-url plausible-email?]]
+ (:use [hiccup.form :only [form-to label text-field password-field check-box drop-down text-area]]
+ [foreclojure.utils :only [from-mongo flash-error flash-msg with-user form-row assuming send-email login-url plausible-email?
+ codemirror-themes default-theme get-theme]]
[foreclojure.template :only [def-page content-page]]
[foreclojure.users :only [disable-codebox? hide-solutions? gravatar-img]]
[foreclojure.messages :only [err-msg]]
@@ -26,7 +27,7 @@
(defn js-settings-box [user-obj]
(list
- [:p "Selecting this will disable the JavaScript code entry box and just give you plain text entry"]
+ [:p "Selecting this will disable the JavaScript code entry box and just give you plain text entry."]
(check-box :disable-codebox
(disable-codebox? user-obj))
[:label {:for "disable-codebox"}
@@ -42,13 +43,35 @@
"Hide my solutions"]
[:br]))
+(def code-example
+ "(defn balanced? [s]
+ \"Determine whether input string
+ is balanced bracket sequence\"
+ (loop [[first & coll] (seq s)
+ stack '()]
+ (if first
+ (if (= first \\[)
+ (recur coll (conj stack \\[))
+ (when (= (peek stack) \\[)
+ (recur coll (pop stack))))
+ (zero? (count stack)))))")
+
+(defn theme-settings-box [user-obj]
+ (list
+ [:p "Editor theme that will be used for higlighting editor and all code snippets."]
+ (drop-down :theme codemirror-themes "eclipse")
+ (text-area {:id "code-box"
+ :name "code"
+ :spellcheck "false"}
+ :code code-example)))
+
(def-page settings-page []
(with-user [{:keys [user email] :as user-obj}]
{:title "Account settings"
:content
(content-page
{:main
- (form-to [:post "/settings"]
+ (form-to {:id "settings"} [:post "/settings"]
(list
[:h2 "Change settings for " user]
[:div#account-settings (account-settings-box user email)]
@@ -59,17 +82,21 @@
[:h3 "Hide My Solutions"]
[:div#settings-follow (hide-settings-box user-obj)]
[:hr]
+ [:h3 "Editor theme"]
+ [:div#editor-theme (theme-settings-box user-obj)]
+ [:hr]
[:h3 "Profile Image"]
[:div (gravatar-img {:email email :size 64})]
[:p "To change your profile image, visit <a href='http://gravatar.com' target='_blank'>Gravatar</a> and edit the image for '" email "'."]
[:div#button-div
[:button {:type "submit"} "Submit"]]))})}))
-(defn do-update-settings! [new-username old-pwd new-pwd repeat-pwd email disable-codebox hide-solutions]
+(defn do-update-settings! [new-username old-pwd new-pwd repeat-pwd email disable-codebox hide-solutions theme]
(with-user [{:keys [user pwd]}]
(let [encryptor (StrongPasswordEncryptor.)
new-pwd-hash (.encryptPassword encryptor new-pwd)
- new-lower-user (.toLowerCase new-username)]
+ new-lower-user (.toLowerCase new-username)
+ theme (or ((set codemirror-themes) theme) default-theme)]
(assuming [(or (= new-lower-user user) (nil? (fetch-one :users :where {:user new-lower-user})))
(err-msg "settings.user-exists"),
(< 3 (.length new-lower-user) 14)
@@ -94,7 +121,8 @@
:user new-lower-user
:email email
:disable-code-box (boolean disable-codebox)
- :hide-solutions (boolean hide-solutions)}}
+ :hide-solutions (boolean hide-solutions)
+ :theme theme}}
:upsert false)
(session/put! :user new-lower-user)
(flash-msg "/problems"
@@ -103,5 +131,5 @@
(defroutes settings-routes
(GET "/settings" [] (settings-page))
- (POST "/settings" {{:strs [new-username old-pwd pwd repeat-pwd email disable-codebox hide-solutions]} :form-params}
- (do-update-settings! new-username old-pwd pwd repeat-pwd email disable-codebox hide-solutions)))
+ (POST "/settings" {{:strs [new-username old-pwd pwd repeat-pwd email disable-codebox hide-solutions theme]} :form-params}
+ (do-update-settings! new-username old-pwd pwd repeat-pwd email disable-codebox hide-solutions theme)))
View
8 src/foreclojure/template.clj
@@ -4,12 +4,11 @@
[hiccup.page :only [doctype]]
[hiccup.element :only [javascript-tag link-to]]
[foreclojure.config :only [config repo-url]]
- [foreclojure.utils :only [page-attributes rendering-info login-url approver? can-submit?]]
+ [foreclojure.utils :only [page-attributes rendering-info login-url approver? can-submit? codemirror-themes get-theme]]
[foreclojure.ring-utils :only [static-url]]
[foreclojure.version-utils :only [css js]]))
-(def codemirror-themes ["ambiance" "blackboard" "cobalt" "eclipse" "elegant" "erlang-dark"
- "lesser-dark" "monokai" "neat" "night" "rubyblue" "vibrant-ink" "xq-dark"])
+
;; Global wrapping template
(defn html-doc [body]
@@ -27,7 +26,8 @@
(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/codemirror-clojure-compressed.js")
- (js "vendor/script/detectmobilebrowser.js")]
+ (js "vendor/script/detectmobilebrowser.js")
+ (javascript-tag (format "CodeBox.theme = '%s';" (get-theme)))]
[:body
(when (:fork-banner attrs)
[:div#github-banner [:a {:href repo-url
View
12 src/foreclojure/utils.clj
@@ -203,4 +203,14 @@
(defn rank-class [x]
{:class (if (even? x)
"evenrank"
- "oddrank")})
+ "oddrank")})
+
+(def codemirror-themes ["ambiance" "blackboard" "cobalt" "eclipse" "elegant" "erlang-dark"
+ "lesser-dark" "monokai" "neat" "night" "rubyblue" "vibrant-ink" "xq-dark"])
+
+(def default-theme "eclipse")
+
+(defn get-theme []
+ (if-user [{:keys [theme]}]
+ (or theme default-theme)
+ default-theme))
Please sign in to comment.
Something went wrong with that request. Please try again.