Replace dynamite code with tested version

This commit is contained in:
Prem Sichanugrist
2012-06-07 16:30:52 -04:00
parent c340ffe0a3
commit ac4f09ac4e
5 changed files with 73 additions and 100 deletions

View File

@@ -15,6 +15,7 @@ class @Problem
@$('section.action input.reset').click @reset
@$('section.action input.show').click @show
@$('section.action input.save').click @save
@$('input.math').keyup(@refreshMath).each(@refreshMath)
render: (content) ->
if content
@@ -62,6 +63,20 @@ class @Problem
if response.success
alert 'Saved'
refreshMath: (event, element) =>
element = event.target unless element
target = "display_#{element.id.replace(/^input_/, '')}"
if jax = MathJax.Hub.getAllJax(target)[0]
MathJax.Hub.Queue ['Text', jax, $(element).val()]
try
output = jax.root.toMathML ''
$("##{element.id}_dynamath").val(output)
catch exception
throw exception unless exception.restart
MathJax.Callback.After [@refreshMath, jax], exception.restart
refreshAnswers: =>
@$('input.schematic').each (index, element) ->
element.schematic.update_value()