From bd72fbdfd8ee4783f15baff82bdf48e09dd8fad7 Mon Sep 17 00:00:00 2001 From: kimth Date: Mon, 10 Sep 2012 19:42:40 -0400 Subject: [PATCH] Allow textinputdynamath to specify its Mathjax preprocessor per-problem --- common/lib/capa/capa/inputtypes.py | 8 ++++++++ .../capa/capa/templates/textinput_dynamath.html | 6 ++++-- .../xmodule/xmodule/js/src/capa/display.coffee | 15 ++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index d9b864c5bc..187d2fd422 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -326,8 +326,16 @@ def textline_dynamath(element, value, status, render_template, msg=''): count = int(eid.split('_')[-2]) - 1 # HACK size = element.get('size') hidden = element.get('hidden', '') # if specified, then textline is hidden and id is stored in div of name given by hidden + + # Preprocessor to insert between raw input and Mathjax + preprocessor = {'class_name': element.get('preprocessorClassName',''), + 'script_src': element.get('preprocessorSrc','')} + if '' in preprocessor.values(): + preprocessor = None + context = {'id': eid, 'value': value, 'state': status, 'count': count, 'size': size, 'msg': msg, 'hidden': hidden, + 'preprocessor': preprocessor, } html = render_template("textinput_dynamath.html", context) return etree.XML(html) diff --git a/common/lib/capa/capa/templates/textinput_dynamath.html b/common/lib/capa/capa/templates/textinput_dynamath.html index be37af481c..856c29b3a0 100644 --- a/common/lib/capa/capa/templates/textinput_dynamath.html +++ b/common/lib/capa/capa/templates/textinput_dynamath.html @@ -3,8 +3,10 @@ ###
-
-
+ % if preprocessor is not None: +
+
+ % endif % if state == 'unsubmitted':
diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index a589179240..177a1e8806 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -6,7 +6,6 @@ class @Problem @element_id = @el.attr('id') @url = @el.data('url') @render() - @mathjax_preprocessor = false $: (selector) -> $(selector, @el) @@ -301,6 +300,7 @@ class @Problem target = "display_" + elid + # MathJax preprocessor is loaded by 'setupInputTypes' preprocessor_tag = "inputtype_" + elid mathjax_preprocessor = @inputtypeDisplays[preprocessor_tag] @@ -308,7 +308,6 @@ class @Problem eqn = $(element).val() if mathjax_preprocessor eqn = mathjax_preprocessor(eqn) - MathJax.Hub.Queue ['Text', jax, eqn], [@updateMathML, jax, element] @@ -329,13 +328,19 @@ class @Problem inputtypeSetupMethods: textinputdynamath: (element) => + ### + Return: function (eqn) -> eqn that preprocesses the user formula input before + it is fed into MathJax. Return 'false' if no preprocessor specified + ### data = $(element).find('.textinputdynamath_data') preprocessorClassName = data.data('preprocessor') preprocessorClass = window[preprocessorClassName] - - preprocessor = new preprocessorClass() - return preprocessor.fn + if typeof(preprocessorClass) == 'undefined' + return false + else + preprocessor = new preprocessorClass() + return preprocessor.fn javascriptinput: (element) =>