Skip to content

Commit

Permalink
Fix processMath script for IE8, hopefully
Browse files Browse the repository at this point in the history
IE8 doesn't like .text() on a script element; see http://stackoverflow.com/q/6720257/49485. Move to the same solution for setting text that we use in a couple of other places.

Test Plan:
Loaded quadrilateral_angles.html?seed=186&problem=isoscelesTrap1 without errors in Chrome.

Auditors: emily
  • Loading branch information
sophiebits committed Sep 1, 2013
1 parent 177bbb0 commit 2dea81b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions utils/tex.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ $.extend(KhanUtil, {
// would update the formula by updating the contents of the script
// tag, which shouldn't happen any more, but we manage them just in
// case.
var $script = $mathjaxHolder.find("script[type='math/tex']");
var script = $mathjaxHolder.find("script[type='math/tex']")[0];

// If text wasn't provided, we look in two places
if (text == null) {
if ($elem.attr("data-math-formula")) {
// The old typeset formula
text = $elem.attr("data-math-formula");
} else if ($script.length) {
} else if (script) {
// The contents of the <script> tag
text = $script.html();
text = script.text || script.textContent;
}
}

Expand All @@ -87,7 +87,7 @@ $.extend(KhanUtil, {
// mathjax, do some mathjax cleanup
if ($elem.attr("data-math-type") === "mathjax") {
// Remove the old mathjax stuff
var jax = MathJax.Hub.getJaxFor($script[0]);
var jax = MathJax.Hub.getJaxFor(script);
if (jax) {
var e = jax.SourceElement();
if (e.previousSibling &&
Expand Down Expand Up @@ -117,11 +117,16 @@ $.extend(KhanUtil, {
// KaTeX is smart and cleans itself up)
$elem.attr("data-math-type", "mathjax");
// Update the script tag, or add one if necessary
if (!$script.length) {
if (!script) {
$mathjaxHolder.append("<script type='math/tex'>" +
text.replace(/<\//g, "< /") + "</script>");
} else {
$script.text(text);
if ("text" in script) {
// IE8, etc
script.text = text;
} else {
script.textContent = text;
}
}
if (typeof MathJax !== "undefined") {
// Put the process, a debug log, and the callback into the
Expand Down

0 comments on commit 2dea81b

Please sign in to comment.