Commit 4834e51a by Waqas Khalid

Mathjax should be used after complete loading

Student couldn't able to submit his answer in ie9
becuase mathjax was used before its complete loading
thats cuase the problem. Mathjax operations should be
handled synchronously inorder to avoid error.

BLD-1199
parent 08a0c639
......@@ -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.
MathJax.Hub.Startup.signal.Interest(function (message) {
if(message === "End") {
var previewElement = inputData.$preview[0];
if (!inputData.jax) {
MathJax.Hub.Queue(function () {
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) {
// 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);
} 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