Commit 9c942d7e by Waqas Khalid

Merge pull request #4910 from mlkwaqas/waqas/bld1199-mathjax-error

MaxJax error while submitting answer
parents 14d0ac01 4834e51a
......@@ -62,7 +62,17 @@ describe("Formula Equation Preview", function () {
window.MathJax = {Hub: {}};
MathJax.Hub.getAllJax = jasmine.createSpy('MathJax.Hub.getAllJax')
.andReturn([this.jax]);
MathJax.Hub.Queue = jasmine.createSpy('MathJax.Hub.Queue');
MathJax.Hub.Queue = function (callback) {
if (typeof (callback) == 'function') {
callback();
}
}
spyOn(MathJax.Hub, 'Queue').andCallThrough()
MathJax.Hub.Startup = jasmine.createSpy('MathJax.Hub.Startup');
MathJax.Hub.Startup.signal = jasmine.createSpy('MathJax.Hub.Startup.signal');
MathJax.Hub.Startup.signal.Interest = function (callback) {
callback('End');
}
});
it('(the test) is able to swap out the behavior of $', function () {
......@@ -245,7 +255,7 @@ describe("Formula Equation Preview", function () {
// Cannot find MathJax.
MathJax.Hub.getAllJax.andReturn([]);
spyOn(console, 'warn');
spyOn(console, 'log');
callback({
preview: 'THE_FORMULA',
......@@ -253,7 +263,7 @@ describe("Formula Equation Preview", function () {
});
// Tests.
expect(console.warn).toHaveBeenCalled();
expect(console.log).toHaveBeenCalled();
// We should look in the preview div for the MathJax.
var previewElement = $("#input_THE_ID_preview")[0];
......
......@@ -127,27 +127,31 @@ formulaEquationPreview.enable = function () {
}
function display(latex) {
// Load jax if it failed before.
var previewElement = inputData.$preview[0];
if (!inputData.jax) {
inputData.jax = MathJax.Hub.getAllJax(previewElement)[0];
}
// MathJax might not be loaded yet (still).
if (inputData.jax) {
// Set the text as the latex code, and then update the MathJax.
MathJax.Hub.Queue(
['Text', inputData.jax, latex],
['Reprocess', inputData.jax]
);
}
else if (latex) {
console.warn("[FormulaEquationInput] Oops no mathjax for ", latex);
// Fall back to modifying the actual element.
var textNode = previewElement.childNodes[0];
textNode.data = "\\[" + latex + "\\]";
MathJax.Hub.Queue(["Typeset", MathJax.Hub, previewElement]);
}
MathJax.Hub.Startup.signal.Interest(function (message) {
if(message === "End") {
var previewElement = inputData.$preview[0];
MathJax.Hub.Queue(function () {
inputData.jax = MathJax.Hub.getAllJax(previewElement)[0];
});
MathJax.Hub.Queue(function () {
// Check if MathJax is loaded
if (inputData.jax) {
// Set the text as the latex code, and then update the MathJax.
MathJax.Hub.Queue(
['Text', inputData.jax, latex],
['Reprocess', inputData.jax]
);
} else if (latex) {
console.log("[FormulaEquationInput] Oops no mathjax for ", latex);
// Fall back to modifying the actual element.
var textNode = previewElement.childNodes[0];
textNode.data = "\\[" + latex + "\\]";
MathJax.Hub.Queue(["Typeset", MathJax.Hub, previewElement]);
}
});
}
});
}
if (response.error) {
......
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