Commit b7a164dd by kimth

Allow textinputdynamath to specify its Mathjax preprocessor per-problem

parent 04f221e3
......@@ -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)
......
......@@ -3,8 +3,10 @@
###
<section class="text-input-dynamath textinputdynamath capa_inputtype" id="inputtype_${id}">
<div class="textinputdynamath_data" data-preprocessor="MathjaxPreprocessorFor6002x"/>
<div class="script_placeholder" data-src="/static/js/mathjax_preprocessor_for_6002x.js"/>
% if preprocessor is not None:
<div class="textinputdynamath_data" data-preprocessor="${preprocessor['class_name']}"/>
<div class="script_placeholder" data-src="${preprocessor['script_src']}"/>
% endif
% if state == 'unsubmitted':
<div class="unanswered" id="status_${id}">
......
......@@ -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,11 +328,17 @@ 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]
if typeof(preprocessorClass) == 'undefined'
return false
else
preprocessor = new preprocessorClass()
return preprocessor.fn
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment