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) {
if(message === "End") {
var previewElement = inputData.$preview[0]; var previewElement = inputData.$preview[0];
if (!inputData.jax) { MathJax.Hub.Queue(function () {
inputData.jax = MathJax.Hub.getAllJax(previewElement)[0]; inputData.jax = MathJax.Hub.getAllJax(previewElement)[0];
} });
// MathJax might not be loaded yet (still). MathJax.Hub.Queue(function () {
// Check if MathJax is loaded
if (inputData.jax) { if (inputData.jax) {
// Set the text as the latex code, and then update the MathJax. // Set the text as the latex code, and then update the MathJax.
MathJax.Hub.Queue( MathJax.Hub.Queue(
['Text', inputData.jax, latex], ['Text', inputData.jax, latex],
['Reprocess', inputData.jax] ['Reprocess', inputData.jax]
); );
} } else if (latex) {
else if (latex) { console.log("[FormulaEquationInput] Oops no mathjax for ", latex);
console.warn("[FormulaEquationInput] Oops no mathjax for ", latex);
// Fall back to modifying the actual element. // Fall back to modifying the actual element.
var textNode = previewElement.childNodes[0]; var textNode = previewElement.childNodes[0];
textNode.data = "\\[" + latex + "\\]"; textNode.data = "\\[" + latex + "\\]";
MathJax.Hub.Queue(["Typeset", MathJax.Hub, previewElement]); 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