Commit 4110a4e2 by Victor Shnayder Committed by Victor Shnayder

Protect against failure to load MathJax

- e.g. if on a train and don't have access to S3 or the rest of the web
parent 6b468df5
...@@ -11,8 +11,9 @@ class @Problem ...@@ -11,8 +11,9 @@ class @Problem
$(selector, @el) $(selector, @el)
bind: => bind: =>
@el.find('.problem > div').each (index, element) => if MathJax?
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element] @el.find('.problem > div').each (index, element) =>
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element]
window.update_schematics() window.update_schematics()
...@@ -31,8 +32,9 @@ class @Problem ...@@ -31,8 +32,9 @@ class @Problem
# Dynamath # Dynamath
@$('input.math').keyup(@refreshMath) @$('input.math').keyup(@refreshMath)
@$('input.math').each (index, element) => if MathJax?
MathJax.Hub.Queue [@refreshMath, null, element] @$('input.math').each (index, element) =>
MathJax.Hub.Queue [@refreshMath, null, element]
updateProgress: (response) => updateProgress: (response) =>
if response.progress_changed if response.progress_changed
...@@ -230,8 +232,9 @@ class @Problem ...@@ -230,8 +232,9 @@ class @Problem
showMethod = @inputtypeShowAnswerMethods[cls] showMethod = @inputtypeShowAnswerMethods[cls]
showMethod(inputtype, display, answers) if showMethod? showMethod(inputtype, display, answers) if showMethod?
@el.find('.problem > div').each (index, element) => if MathJax?
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element] @el.find('.problem > div').each (index, element) =>
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element]
@$('.show').val 'Hide Answer' @$('.show').val 'Hide Answer'
@el.addClass 'showed' @el.addClass 'showed'
...@@ -273,7 +276,7 @@ class @Problem ...@@ -273,7 +276,7 @@ class @Problem
preprocessor_tag = "inputtype_" + elid preprocessor_tag = "inputtype_" + elid
mathjax_preprocessor = @inputtypeDisplays[preprocessor_tag] mathjax_preprocessor = @inputtypeDisplays[preprocessor_tag]
if jax = MathJax.Hub.getAllJax(target)[0] if MathJax? and 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)
...@@ -286,7 +289,8 @@ class @Problem ...@@ -286,7 +289,8 @@ class @Problem
$("##{element.id}_dynamath").val(jax.root.toMathML '') $("##{element.id}_dynamath").val(jax.root.toMathML '')
catch exception catch exception
throw exception unless exception.restart throw exception unless exception.restart
MathJax.Callback.After [@refreshMath, jax], exception.restart if MathJax?
MathJax.Callback.After [@refreshMath, jax], exception.restart
refreshAnswers: => refreshAnswers: =>
@$('input.schematic').each (index, element) -> @$('input.schematic').each (index, 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