Handle loading of CommonHTML jax better (do it when we detect it is not present, rather than trying to hook into the input jax require array).

This commit is contained in:
Davide P. Cervone 2014-11-08 09:29:47 -05:00
parent d128cfbd5d
commit ff6d6935df

View File

@ -39,7 +39,7 @@
//
config: HUB.CombineConfig("CHTML-preview",{
Chunks: {EqnChunk: 10000, EqnChunkFactor: 1, EqnChunkDelay: 0},
color: "inherit",
color: "inherit!important",
updateTime: 10, updateDelay: 10,
messageStyle: "none",
disabled: false
@ -56,6 +56,7 @@
MathJax.Ajax.Styles({".MathJax_Preview":{color:this.config.color}});
var update, delay, style, done, saved;
var config = this.config;
HUB.Register.MessageHook("Begin Math Output",function () {
if (!done && !config.disabled && SETTINGS.CHTMLpreview &&
SETTINGS.renderer !== "CommonHTML") {
@ -97,25 +98,28 @@
try {
data.math.root.toCommonHTML(preview);
} catch (err) {
//
// Load the CommonHTML jax if it is not already loaded
//
if (!data.math.root.toCommonHTML) {
var queue = MathJax.Callback.Queue();
HUB.RestartAfter(queue.Push(
["Require",MathJax.Ajax,"[MathJax]/jax/output/CommonHTML/config.js"],
["Require",MathJax.Ajax,"[MathJax]/jax/output/CommonHTML/jax.js"]
));
}
if (!err.restart) {throw err} // an actual error
return MathJax.Callback.After(["postFilter",this,preview,data],err.restart);
}
},
//
// Hook into the inut jax postFilter to create the previews as
// Hook into the input jax postFilter to create the previews as
// the input jax are processed.
//
Register: function (name) {
HUB.Register.StartupHook(name+" Jax Require",function () {
var jax = MathJax.InputJax[name];
var delay = HUB.config.delayJaxRegistration;
HUB.config.delayJaxRegistration = true;
HUB.Register.StartupHook(name+" Jax Ready",function () {HUB.config.delayJaxRegistration = delay});
jax.require.push(
"[MathJax]/jax/output/CommonHTML/config.js",
"[MathJax]/jax/output/CommonHTML/jax.js"
);
jax.postfilterHooks.Add(["Preview",MathJax.Extension["CHTML-preview"]],50);
});
}