Commit 04f221e3 by kimth

Another step towards Javascriptinput-style script loading

parent 37acade6
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
### version of textline.html which does dynamic math ### version of textline.html which does dynamic math
### ###
<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"/>
<div class="script_placeholder" data-src="/static/js/mathjax_preprocessor_for_6002x.js"/>
% if state == 'unsubmitted': % if state == 'unsubmitted':
<div class="unanswered" id="status_${id}"> <div class="unanswered" id="status_${id}">
% elif state == 'correct': % elif state == 'correct':
...@@ -15,27 +19,26 @@ ...@@ -15,27 +19,26 @@
<div style="display:none;" name="${hidden}" inputid="input_${id}" /> <div style="display:none;" name="${hidden}" inputid="input_${id}" />
% endif % endif
<input type="text" name="input_${id}" id="input_${id}" value="${value}" class="math" size="${size if size else ''}" <input type="text" name="input_${id}" id="input_${id}" value="${value}" class="math" size="${size if size else ''}"
% if hidden: % if hidden:
style="display:none;" style="display:none;"
% endif % endif
/> />
<div class="script_placeholder" data-src="/static/js/mathjax_preprocessor_for_6002x.js"/> <p class="status">
<p class="status"> % if state == 'unsubmitted':
% if state == 'unsubmitted': unanswered
unanswered % elif state == 'correct':
% elif state == 'correct': correct
correct % elif state == 'incorrect':
% elif state == 'incorrect': incorrect
incorrect % elif state == 'incomplete':
% elif state == 'incomplete': incomplete
incomplete % endif
% endif </p>
</p>
<p id="answer_${id}" class="answer"></p> <p id="answer_${id}" class="answer"></p>
<div id="display_${id}" class="equation">`{::}`</div> <div id="display_${id}" class="equation">`{::}`</div>
</div> </div>
<textarea style="display:none" id="input_${id}_dynamath" name="input_${id}_dynamath"> </textarea> <textarea style="display:none" id="input_${id}_dynamath" name="input_${id}_dynamath"> </textarea>
......
...@@ -297,12 +297,17 @@ class @Problem ...@@ -297,12 +297,17 @@ class @Problem
refreshMath: (event, element) => refreshMath: (event, element) =>
element = event.target unless element element = event.target unless element
target = "display_#{element.id.replace(/^input_/, '')}" elid = element.id.replace(/^input_/,'')
target = "display_" + elid
preprocessor_tag = "inputtype_" + elid
mathjax_preprocessor = @inputtypeDisplays[preprocessor_tag]
if jax = MathJax.Hub.getAllJax(target)[0] if jax = MathJax.Hub.getAllJax(target)[0]
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]
...@@ -324,9 +329,13 @@ class @Problem ...@@ -324,9 +329,13 @@ class @Problem
inputtypeSetupMethods: inputtypeSetupMethods:
textinputdynamath: (element) => textinputdynamath: (element) =>
preprocessorClass = window['MathjaxPreprocessorFor6002x'] data = $(element).find('.textinputdynamath_data')
preprocessorClassName = data.data('preprocessor')
preprocessorClass = window[preprocessorClassName]
preprocessor = new preprocessorClass() preprocessor = new preprocessorClass()
alert preprocessor.fn 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