Merge pull request #824 from hgiesel/mathjax3plus
Improvements to MathJax and ts hooks
This commit is contained in:
commit
54eb554393
@ -3,20 +3,26 @@ window.MathJax = {
|
||||
displayMath: [["\\[", "\\]"]],
|
||||
processRefs: false,
|
||||
processEnvironments: false,
|
||||
packages: ['base', 'ams', 'noerrors', 'noundefined', 'mhchem']
|
||||
packages: {
|
||||
"[+]": ["noerrors", "mhchem"],
|
||||
},
|
||||
},
|
||||
startup: {
|
||||
typeset: false
|
||||
typeset: false,
|
||||
pageReady: () => {
|
||||
console.log("page is ready");
|
||||
return MathJax.startup.defaultPageReady();
|
||||
},
|
||||
},
|
||||
options: {
|
||||
renderActions: {
|
||||
addMenu: [],
|
||||
checkLoading: []
|
||||
checkLoading: [],
|
||||
},
|
||||
ignoreHtmlClass: 'tex2jax_ignore',
|
||||
processHtmlClass: 'tex2jax_process'
|
||||
ignoreHtmlClass: "tex2jax_ignore",
|
||||
processHtmlClass: "tex2jax_process",
|
||||
},
|
||||
loader: {
|
||||
load: ['[tex]/noerrors', '[tex]/mhchem']
|
||||
}
|
||||
load: ["[tex]/noerrors", "[tex]/mhchem"],
|
||||
},
|
||||
};
|
||||
|
@ -11,10 +11,14 @@ var aFade = 0;
|
||||
var onUpdateHook;
|
||||
var onShownHook;
|
||||
|
||||
function _runHook(arr) {
|
||||
function _runHook(arr: () => Promise<any>[]): Promise<any[]> {
|
||||
var promises = [];
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
arr[i]();
|
||||
promises.push(arr[i]());
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
function _updateQA(html, fadeTime, onupdate, onshown) {
|
||||
@ -32,10 +36,13 @@ function _updateQA(html, fadeTime, onupdate, onshown) {
|
||||
onUpdateHook = [onupdate];
|
||||
onShownHook = [onshown];
|
||||
|
||||
// fade out current text
|
||||
var qa = $("#qa");
|
||||
qa.fadeTo(fadeTime, 0, function () {
|
||||
|
||||
// fade out current text
|
||||
qa.fadeOut(fadeTime)
|
||||
.promise()
|
||||
// update text
|
||||
.then(() => {
|
||||
try {
|
||||
qa.html(html);
|
||||
} catch (err) {
|
||||
@ -46,21 +53,22 @@ function _updateQA(html, fadeTime, onupdate, onshown) {
|
||||
).replace(/\n/g, "<br />")
|
||||
);
|
||||
}
|
||||
_runHook(onUpdateHook);
|
||||
})
|
||||
.then(() => _runHook(onUpdateHook))
|
||||
.then(() =>
|
||||
// @ts-ignore wait for mathjax to ready
|
||||
MathJax.startup.promise.then(() => {
|
||||
// @ts-ignore clear MathJax buffer
|
||||
MathJax.typesetClear();
|
||||
|
||||
// @ts-ignore
|
||||
MathJax.startup.promise
|
||||
// render mathjax
|
||||
// @ts-ignore
|
||||
.then(MathJax.typesetPromise)
|
||||
// @ts-ignore typeset
|
||||
return MathJax.typesetPromise(qa.slice(0, 1));
|
||||
})
|
||||
)
|
||||
// and reveal when processing is done
|
||||
.then(function () {
|
||||
qa.fadeTo(fadeTime, 1, function () {
|
||||
_runHook(onShownHook);
|
||||
_updatingQA = false;
|
||||
});
|
||||
});
|
||||
});
|
||||
.then(() => qa.fadeIn(fadeTime).promise())
|
||||
.then(() => _runHook(onShownHook))
|
||||
.then(() => (_updatingQA = false));
|
||||
}
|
||||
|
||||
function _showQuestion(q, bodyclass) {
|
||||
|
Loading…
Reference in New Issue
Block a user