From f8ee3efc7a064c3359b146142cbaa5c1cacc2e4d Mon Sep 17 00:00:00 2001
From: Tom Giannattasio
Date: Thu, 8 Nov 2012 14:16:42 -0500
Subject: [PATCH] simplified syntax to match arjun's for string and numerical
response
---
cms/static/js/speed-editor.js | 56 ++++++++++++++++-------------------
1 file changed, 25 insertions(+), 31 deletions(-)
diff --git a/cms/static/js/speed-editor.js b/cms/static/js/speed-editor.js
index fbb73be530..7540dd185e 100644
--- a/cms/static/js/speed-editor.js
+++ b/cms/static/js/speed-editor.js
@@ -156,25 +156,22 @@ function updateXML() {
// replace videos
xml = xml.replace(/\{\{video\s(.*)\}\}/g, '\n\n');
- // replace string input
- xml = xml.replace(/\_\_\_\[(.+)\]/g, '\n \n\n\n');
-
- // replace numerical input
- xml = xml.replace(/\#\#\#\[(.+)\]/g, function(match, p) {
- var solution = extractNumericalSolution(p);
- var string = '\n';
-
- var params = extractNumericalSettings(p);
-
- if(params) {
- for(var i = 0; i < params.length; i++) {
- var splitProp = params[i].split(/:\s*/);
- string += ' \n';
+ // replace string and numerical
+ xml = xml.replace(/\=\s*(.*)/g, function(match, p) {
+ var string;
+ var params = /(.*)\+\-\s*(.*)/.exec(p);
+ if(parseFloat(p)) {
+ if(params) {
+ string = '\n';
+ string += ' \n';
+ } else {
+ string = '\n';
}
+ string += ' \n';
+ string += '\n\n';
+ } else {
+ string = '\n \n\n\n';
}
-
- string += ' \n';
- string += '\n\n';
return string;
});
@@ -256,6 +253,12 @@ function updatePreview() {
return groupString;
});
+ html = html.replace(/\=\s*(.*)/g, function(match, p) {
+ var value = p.replace(/\+\-.*/g, '');
+ var string = '\n';
+ return string;
+ });
+
// wrap the paragraphs
html = html.replace(/(^(?!\<\/*ul|\s*\$1
\n');
@@ -272,16 +275,7 @@ function updatePreview() {
// replace radios
html = html.replace(/\(\s*\)/g, '');
- html = html.replace(/\(x\)/gi, '');
-
- // replace string input
- html = html.replace(/\_\_\_\[(.+)\]/g, function(match, p) {
- var string = '\n';
- return string;
- });
-
- // replace numerical input
- html = html.replace(/\#\#\#\[(.+)\]/g, '$1');
+ html = html.replace(/\(x\)/gi, '');
// replace selects
html = html.replace(/\[\[(.+)\]\]/g, function(match, p) {
@@ -387,10 +381,10 @@ function makeMultipleChoice() {
function makeStringInput() {
var selection = simpleEditor.getSelection();
if(selection.length > 0) {
- var revisedSelection = '___[' + selection + ']';
+ var revisedSelection = '= ' + selection + '';
simpleEditor.replaceSelection(revisedSelection);
} else {
- var template = '___[answer]\n';
+ var template = '= answer\n';
simpleEditor.replaceSelection(template);
setFocus();
}
@@ -399,10 +393,10 @@ function makeStringInput() {
function makeNumberInput() {
var selection = simpleEditor.getSelection();
if(selection.length > 0) {
- var revisedSelection = '###[' + selection + ']';
+ var revisedSelection = '= ' + selection + '';
simpleEditor.replaceSelection(revisedSelection);
} else {
- var template = '###[answer +-tolerance]\n';
+ var template = '= answer +- x%\n';
simpleEditor.replaceSelection(template);
setFocus();
}