Help with WText and the javascript library MathJax
Added by 太极美术工程狮 狮长 about 9 years ago
MathJax is a javascript library which renders MathML code into beautiful fomulas.
When the contents of the DOM in the browser changed , you can call javascript code MathJax.Hub.Typeset() to rerun MathJax and refresh the fomulas.
But , how do I know the exact time when the contents of a WText have been completely transfered from the server to the browser ? I have to call MathJax function at that moment.
When I call WText::setText in my c code , the contents are at the server at that time , but what is the time the contents reached the browser and got inserted into DOM ? I didn't find a way to get that information.
I uploaded an example , wish you can get the idea of my question.
Note that , you need to test the example with a browser that doesn't provide MathML support , as far as I know , the browsers with WebKit engine do not fully support MathML.
Please let me know if you need any further information.
MathJaxProblem.zip (2.35 MB) MathJaxProblem.zip | An example project which shows my problem |
Replies (3)
RE: Help with WText and the javascript library MathJax - Added by Wim Dumon about 9 years ago
Hello,
This is done by doJavaScript(). For example:
atclCnttWdgt->setText (WString::fromUTF8 (wholeContent));
atclCnttWdgt->doJavaScript("MathJax.Hub.Typeset()");
Best regards,
Wim.
RE: Help with WText and the javascript library MathJax - Added by 太极美术工程狮 狮长 about 9 years ago
I have already tried that before .
It seems that ,
atclCnttWdgt->setText (WString::fromUTF8 (wholeContent));
atclCnttWdgt->doJavaScript("MathJax.Hub.Typeset()"); //When the code is executed , the content of atclCnttWdgt has not been inserted into the DOM of the browser yet . And then , MathJax.Hub.Typeset() has not effect.
RE: Help with WText and the javascript library MathJax - Added by Wim Dumon about 9 years ago
The order of execution is indeed ill-defined here, I overlooked that. You can delay calling the javascript code by wrapping it in a setTimeout call:
atclCnttWdgt->setText (WString::fromUTF8 (wholeContent));
atclCnttWdgt->doJavaScript("setTimeout(function(){MathJax.Hub.Typeset();},0)");