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