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,6 +11,7 @@ class @Problem ...@@ -11,6 +11,7 @@ class @Problem
$(selector, @el) $(selector, @el)
bind: => bind: =>
if MathJax?
@el.find('.problem > div').each (index, element) => @el.find('.problem > div').each (index, element) =>
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element] MathJax.Hub.Queue ["Typeset", MathJax.Hub, element]
...@@ -31,6 +32,7 @@ class @Problem ...@@ -31,6 +32,7 @@ class @Problem
# Dynamath # Dynamath
@$('input.math').keyup(@refreshMath) @$('input.math').keyup(@refreshMath)
if MathJax?
@$('input.math').each (index, element) => @$('input.math').each (index, element) =>
MathJax.Hub.Queue [@refreshMath, null, element] MathJax.Hub.Queue [@refreshMath, null, element]
...@@ -230,6 +232,7 @@ class @Problem ...@@ -230,6 +232,7 @@ class @Problem
showMethod = @inputtypeShowAnswerMethods[cls] showMethod = @inputtypeShowAnswerMethods[cls]
showMethod(inputtype, display, answers) if showMethod? showMethod(inputtype, display, answers) if showMethod?
if MathJax?
@el.find('.problem > div').each (index, element) => @el.find('.problem > div').each (index, element) =>
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element] MathJax.Hub.Queue ["Typeset", MathJax.Hub, element]
...@@ -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,6 +289,7 @@ class @Problem ...@@ -286,6 +289,7 @@ 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
if MathJax?
MathJax.Callback.After [@refreshMath, jax], exception.restart MathJax.Callback.After [@refreshMath, jax], exception.restart
refreshAnswers: => refreshAnswers: =>
......
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