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=''): ...@@ -326,8 +326,16 @@ def textline_dynamath(element, value, status, render_template, msg=''):
count = int(eid.split('_')[-2]) - 1 # HACK count = int(eid.split('_')[-2]) - 1 # HACK
size = element.get('size') 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 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, context = {'id': eid, 'value': value, 'state': status, 'count': count, 'size': size,
'msg': msg, 'hidden': hidden, 'msg': msg, 'hidden': hidden,
'preprocessor': preprocessor,
} }
html = render_template("textinput_dynamath.html", context) html = render_template("textinput_dynamath.html", context)
return etree.XML(html) return etree.XML(html)
......
...@@ -3,8 +3,10 @@ ...@@ -3,8 +3,10 @@
### ###
<section class="text-input-dynamath textinputdynamath capa_inputtype" id="inputtype_${id}"> <section class="text-input-dynamath textinputdynamath capa_inputtype" id="inputtype_${id}">
<div class="textinputdynamath_data" data-preprocessor="MathjaxPreprocessorFor6002x"/> % if preprocessor is not None:
<div class="script_placeholder" data-src="/static/js/mathjax_preprocessor_for_6002x.js"/> <div class="textinputdynamath_data" data-preprocessor="${preprocessor['class_name']}"/>
<div class="script_placeholder" data-src="${preprocessor['script_src']}"/>
% endif
% if state == 'unsubmitted': % if state == 'unsubmitted':
<div class="unanswered" id="status_${id}"> <div class="unanswered" id="status_${id}">
......
...@@ -6,7 +6,6 @@ class @Problem ...@@ -6,7 +6,6 @@ class @Problem
@element_id = @el.attr('id') @element_id = @el.attr('id')
@url = @el.data('url') @url = @el.data('url')
@render() @render()
@mathjax_preprocessor = false
$: (selector) -> $: (selector) ->
$(selector, @el) $(selector, @el)
...@@ -301,6 +300,7 @@ class @Problem ...@@ -301,6 +300,7 @@ class @Problem
target = "display_" + elid target = "display_" + elid
# MathJax preprocessor is loaded by 'setupInputTypes'
preprocessor_tag = "inputtype_" + elid preprocessor_tag = "inputtype_" + elid
mathjax_preprocessor = @inputtypeDisplays[preprocessor_tag] mathjax_preprocessor = @inputtypeDisplays[preprocessor_tag]
...@@ -308,7 +308,6 @@ class @Problem ...@@ -308,7 +308,6 @@ class @Problem
eqn = $(element).val() eqn = $(element).val()
if mathjax_preprocessor if mathjax_preprocessor
eqn = mathjax_preprocessor(eqn) eqn = mathjax_preprocessor(eqn)
MathJax.Hub.Queue ['Text', jax, eqn], MathJax.Hub.Queue ['Text', jax, eqn],
[@updateMathML, jax, element] [@updateMathML, jax, element]
...@@ -329,13 +328,19 @@ class @Problem ...@@ -329,13 +328,19 @@ class @Problem
inputtypeSetupMethods: inputtypeSetupMethods:
textinputdynamath: (element) => 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') data = $(element).find('.textinputdynamath_data')
preprocessorClassName = data.data('preprocessor') preprocessorClassName = data.data('preprocessor')
preprocessorClass = window[preprocessorClassName] preprocessorClass = window[preprocessorClassName]
if typeof(preprocessorClass) == 'undefined'
preprocessor = new preprocessorClass() return false
return preprocessor.fn else
preprocessor = new preprocessorClass()
return preprocessor.fn
javascriptinput: (element) => javascriptinput: (element) =>
......
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