Changes to allow output jax to be included in a combined configuration file (more careful synchronization is needed in order to make sure the jax is loaded before typesetting begins)

This commit is contained in:
Davide P. Cervone 2011-01-01 16:44:48 -05:00
parent 244069816a
commit f5c0ac5bcd

View File

@ -29,7 +29,7 @@ if (document.getElementById && document.childNodes && document.createElement) {
if (!window.MathJax) {window.MathJax= {}} if (!window.MathJax) {window.MathJax= {}}
if (!MathJax.Hub) { // skip if already loaded if (!MathJax.Hub) { // skip if already loaded
MathJax.version = "1.0.8"; MathJax.version = "1.0.9";
/**********************************************************/ /**********************************************************/
@ -661,6 +661,16 @@ MathJax.version = "1.0.8";
return callback; return callback;
}, },
//
// Used when files are combined in a preloading configuration file
//
Preloading: function () {
for (var i = 0, m = arguments.length; i < m; i++) {
var file = this.fileURL(arguments[i]);
if (!this.loading[file]) {this.loading[file] = {preloaded: true}}
}
},
// //
// Code used to load the various types of files // Code used to load the various types of files
// (JS for JavaScript, CSS for style sheets) // (JS for JavaScript, CSS for style sheets)
@ -799,7 +809,7 @@ MathJax.version = "1.0.8";
loadComplete: function (file) { loadComplete: function (file) {
file = this.fileURL(file); file = this.fileURL(file);
var loading = this.loading[file]; var loading = this.loading[file];
if (loading) { if (loading && !loading.preloaded) {
BASE.Message.Clear(loading.message); BASE.Message.Clear(loading.message);
clearTimeout(loading.timeout); clearTimeout(loading.timeout);
if (loading.script) { if (loading.script) {
@ -1361,9 +1371,9 @@ MathJax.Hub = {
if (!script.MathJax || script.MathJax.state === STATE.PROCESSED) continue; if (!script.MathJax || script.MathJax.state === STATE.PROCESSED) continue;
if (!script.MathJax.elementJax || script.MathJax.state === STATE.UPDATE) { if (!script.MathJax.elementJax || script.MathJax.state === STATE.UPDATE) {
this.checkScriptSiblings(script); this.checkScriptSiblings(script);
result = inputJax[type].Translate(script); result = inputJax[type].Process(script);
if (typeof result === 'function') { if (typeof result === 'function') {
if (result.called) continue; // go back and call Translate() again if (result.called) continue; // go back and call Process() again
this.RestartAfter(result); this.RestartAfter(result);
} }
result.Attach(script,inputJax[type]); result.Attach(script,inputJax[type]);
@ -1374,10 +1384,10 @@ MathJax.Hub = {
throw Error("No output jax registered for "+jax.mimeType); throw Error("No output jax registered for "+jax.mimeType);
} }
jax.outputJax = outputJax[jax.mimeType][0]; jax.outputJax = outputJax[jax.mimeType][0];
result = jax.outputJax.Translate(script); result = jax.outputJax.Process(script);
if (typeof result === 'function') { if (typeof result === 'function') {
script.MathJax.state = STATE.UPDATE; script.MathJax.state = STATE.UPDATE;
if (result.called) continue; // go back and call Translate() again if (result.called) continue; // go back and call Process() again
this.RestartAfter(result); this.RestartAfter(result);
} }
script.MathJax.state = STATE.PROCESSED; script.MathJax.state = STATE.PROCESSED;
@ -1652,11 +1662,12 @@ MathJax.Hub.Startup = {
cObject.Augment(null,cdef); cObject.Augment(null,cdef);
return this; return this;
}, },
Translate: function (element) { Process: function (element) {
this.constructor.prototype.Translate = this.noTranslate; var load = AJAX.Require(this.directory+"/"+this.JAXFILE);
return AJAX.Require(this.directory+"/"+this.JAXFILE); if (!load.called) {this.constructor.prototype.Process = function (element) {return load}}
return load;
}, },
noTranslate: function (element) { Translate: function (element) {
throw Error(this.directory+"/"+this.JAXFILE+" failed to redefine the Translate() method"); throw Error(this.directory+"/"+this.JAXFILE+" failed to redefine the Translate() method");
}, },
Register: function (mimetype) {}, Register: function (mimetype) {},
@ -1681,6 +1692,7 @@ MathJax.Hub.Startup = {
queue.Push(["Post",HUB.Startup.signal,this.id+" Jax Startup"]); queue.Push(["Post",HUB.Startup.signal,this.id+" Jax Startup"]);
queue.Push(["Startup",this]); queue.Push(["Startup",this]);
queue.Push(["Post",HUB.Startup.signal,this.id+" Jax Ready"]); queue.Push(["Post",HUB.Startup.signal,this.id+" Jax Ready"]);
queue.Push([function (THIS) {THIS.Process = THIS.Translate},this.constructor.prototype]);
return queue.Push(["loadComplete",AJAX,this.directory+"/"+file]); return queue.Push(["loadComplete",AJAX,this.directory+"/"+file]);
} }
} }
@ -1695,9 +1707,7 @@ MathJax.Hub.Startup = {
BASE.InputJax = JAX.Subclass({ BASE.InputJax = JAX.Subclass({
elementJax: "mml", // the element jax to load for this input jax elementJax: "mml", // the element jax to load for this input jax
Translate: function (element) { Process: function (element) {
// Make Translate produce an error message until the true one is loaded
this.constructor.prototype.Translate = this.noTranslate;
var queue = CALLBACK.Queue(); var queue = CALLBACK.Queue();
// Load any needed element jax // Load any needed element jax
var jax = this.elementJax; if (!(jax instanceof Array)) {jax = [jax]} var jax = this.elementJax; if (!(jax instanceof Array)) {jax = [jax]}
@ -1709,7 +1719,8 @@ MathJax.Hub.Startup = {
queue.Push(AJAX.Require(file)); queue.Push(AJAX.Require(file));
} }
// Load the input jax // Load the input jax
queue.Push(AJAX.Require(this.directory+"/"+this.JAXFILE)); var load = queue.Push(AJAX.Require(this.directory+"/"+this.JAXFILE));
if (!load.called) {this.constructor.prototype.Process = function () {return load}}
// Load the associated output jax // Load the associated output jax
jax = HUB.config.outputJax["jax/"+jax[0]]; jax = HUB.config.outputJax["jax/"+jax[0]];
if (jax) {queue.Push(AJAX.Require(jax[0].directory+"/"+this.JAXFILE))} if (jax) {queue.Push(AJAX.Require(jax[0].directory+"/"+this.JAXFILE))}