Handle preTranslate in HTML-CSS jax, and don't make a redundent scripts list if there is only one output jax in use

This commit is contained in:
Davide P. Cervone 2011-08-28 20:03:53 -04:00
parent 046079b805
commit 7042c1d64f
8 changed files with 73 additions and 42 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1348,7 +1348,8 @@ MathJax.Hub = {
scripts: [], // filled in by prepareScripts scripts: [], // filled in by prepareScripts
start: new Date().getTime(), // timer for processing messages start: new Date().getTime(), // timer for processing messages
i: 0, // current script i: 0, // current script
jax: {} // scripts grouped by output jax jax: {}, // scripts grouped by output jax
jaxIDs: [] // id's of jax used
}; };
queue.Push( queue.Push(
["Post",this.signal,["Begin "+action,ec.elements[i]]], ["Post",this.signal,["Begin "+action,ec.elements[i]]],
@ -1466,8 +1467,18 @@ MathJax.Hub = {
// and put this script in the queue for that jax // and put this script in the queue for that jax
// //
jax.outputJax = this.outputJax[jax.mimeType][0].id; jax.outputJax = this.outputJax[jax.mimeType][0].id;
if (!state.jax[jax.outputJax]) {state.jax[jax.outputJax] = []} if (!state.jax[jax.outputJax]) {
state.jax[jax.outputJax].push(script); if (state.jaxIDs.length === 0) {
// use original array until we know there are more (rather than two copies)
state.jax[jax.outputJax] = state.scripts;
} else {
if (state.jaxIDs.length === 1) // get the script so far for the existing jax
{state.jax[state.jaxIDs[0]] = state.scripts.slice(0,state.i)}
state.jax[jax.outputJax] = []; // start a new array for the new jax
}
state.jaxIDs.push(jax.outputJax); // save the ID of the jax
}
if (state.jaxIDs.length > 1) {state.jax[jax.outputJax].push(script)}
} }
// //
// Go on to the next script, and check if we need to update the processing message // Go on to the next script, and check if we need to update the processing message
@ -1475,7 +1486,7 @@ MathJax.Hub = {
state.i++; var now = new Date().getTime(); state.i++; var now = new Date().getTime();
if (now - state.start > this.processUpdateTime && state.i < state.scripts.length) { if (now - state.start > this.processUpdateTime && state.i < state.scripts.length) {
state.start = now; state.start = now;
tihs.processMessage(state,"Input"); this.processMessage(state,"Input");
this.RestartAfter(MathJax.Callback.Delay(1)); this.RestartAfter(MathJax.Callback.Delay(1));
} }
} }
@ -1494,10 +1505,10 @@ MathJax.Hub = {
// (to get scaling factors, hide/show output, and so on) // (to get scaling factors, hide/show output, and so on)
// //
prepareOutput: function (state,method) { prepareOutput: function (state,method) {
for (var id in state.jax) {if (state.jax.hasOwnProperty(id)) { for (var i = 0, m = state.jaxIDs.length; i < m; i++) {
var JAX = MathJax.OutputJax[id]; var id = state.jaxIDs[i], JAX = MathJax.OutputJax[id];
if (JAX[method]) {JAX[method](state.jax[id])} if (JAX[method]) {JAX[method](state.jax[id])}
}} }
}, },
processOutput: function (state) { processOutput: function (state) {
@ -2049,7 +2060,7 @@ MathJax.Hub.Startup = {
if (typeof(jax[id]) === 'undefined' && id !== 'newID') {delete this[id]} if (typeof(jax[id]) === 'undefined' && id !== 'newID') {delete this[id]}
} }
for (id in jax) { for (id in jax) {
if (!this.hasOwnProperty(id)) continue; if (!jax.hasOwnProperty(id)) continue;
if (typeof(this[id]) === 'undefined' || (this[id] !== jax[id] && id !== 'inputID')) if (typeof(this[id]) === 'undefined' || (this[id] !== jax[id] && id !== 'inputID'))
{this[id] = jax[id]} {this[id] = jax[id]}
} }

View File

@ -371,39 +371,56 @@
} }
}, },
Translate: function (script) { preTranslate: function (scripts) {
if (!script.parentNode) return; for (var i = 0, m = scripts.length; i < m; i++) {
var script = scripts[i]; if (!script.parentNode) return;
var prev = script.previousSibling; var prev = script.previousSibling;
if (prev && String(prev.className).match(/^MathJax(_MathML|_Display)?$/)) if (prev && String(prev.className).match(/^MathJax(_Display)?$/))
{prev.parentNode.removeChild(prev)} {prev.parentNode.removeChild(prev)}
var math = script.MathJax.elementJax.root, span, div, frame; var math = script.MathJax.elementJax, span, div;
span = div = frame = this.Element("span",{ math.HTMLCSS = {display: (math.root.Get("display") === "block")}
className:"MathJax", oncontextmenu:this.ContextMenu, onmousedown: this.Mousedown, span = div = this.Element("span",{
className:"MathJax", id:math.inputID+"-Frame",
oncontextmenu:this.ContextMenu, onmousedown: this.Mousedown,
onmouseover:this.Mouseover, onclick:this.Click, ondblclick:this.DblClick onmouseover:this.Mouseover, onclick:this.Click, ondblclick:this.DblClick
}); });
var blockMode = (math.Get("display") === "block"); if (math.HTMLCSS.display) {
if (blockMode) { div = this.Element("div",{className:"MathJax_Display", style:{width:"100%"}});
div = frame = this.Element("div",{className:"MathJax_Display", style:{width:"100%", position:"relative"}});
div.appendChild(span); div.appendChild(span);
} }
// (screen readers don't know about role="math" yet, so use "textbox" instead) // (screen readers don't know about role="math" yet, so use "textbox" instead)
div.setAttribute("role","textbox"); div.setAttribute("aria-readonly","true"); div.setAttribute("role","textbox"); div.setAttribute("aria-readonly","true");
if (this.useProcessingFrame) { div.className += " MathJax_Processing";
frame = this.Element((blockMode ? "div" : "span"),{className:"MathJax_Processing"}); script.parentNode.insertBefore(div,script);
frame.appendChild(div); try {
this.getScales(span);
math.HTMLCSS.isHidden = (this.em === 0 || String(this.em) === "NaN");
} catch (err) {
math.HTMLCSS.isHidden = true;
} }
script.parentNode.insertBefore(frame,script); var isHidden; if (math.HTMLCSS.isHidden) {this.hiddenDiv.appendChild(div); this.getScales(span)}
try {this.getScales(span); isHidden = (this.em === 0 || String(this.em) === "NaN")} catch (err) {isHidden = true} math.HTMLCSS.em = this.em; math.HTMLCSS.outerEm = this.outerEm;
if (isHidden) {this.hiddenDiv.appendChild(frame); this.getScales(span)} math.HTMLCSS.scale = this.msieMarginScale; math.HTMLCSS.fontSize = span.style.fontSize;
}
},
Translate: function (script) {
if (!script.parentNode) return;
var jax = script.MathJax.elementJax, math = jax.root,
span = document.getElementById(jax.inputID+"-Frame"),
div = (jax.HTMLCSS.display ? span.parentNode : span);
this.em = MML.mbase.prototype.em = jax.HTMLCSS.em;
this.outerEm = jax.HTMLCSS.outerEm; this.msieMarginScale = jax.HTMLCSS.scale;
span.style.fontSize = jax.HTMLCSS.fontSize;
this.initImg(span); this.initImg(span);
this.initHTML(math,span); this.initHTML(math,span);
math.setTeXclass(); math.setTeXclass();
try {math.toHTML(span,div)} catch (err) { try {math.toHTML(span,div)} catch (err) {
if (err.restart) {frame.parentNode.removeChild(frame)} if (err.restart) {while (span.firstChild) {span.removeChild(span.firstChild)}}
throw err; throw err;
} }
if (isHidden) {script.parentNode.insertBefore(frame,script)} if (jax.HTMLCSS.isHidden) {script.parentNode.insertBefore(div,script)}
if (this.useProcessingFrame) frame.parentNode.replaceChild(div,frame); div.className = div.className.split(/ /)[0];
}, },
/* /*
@ -474,9 +491,12 @@
}, },
Remove: function (jax) { Remove: function (jax) {
var span = jax.SourceElement(); if (!span) return; var span = document.getElementById(jax.inputID+"-Frame");
span = span.previousSibling; if (!span) return; if (span) {
if (span.className.match(/^MathJax/)) {span.parentNode.removeChild(span)} if (jax.HTMLCSS.display) {span = span.parentNode}
span.parentNode.removeChild(span);
}
delete jax.HTMLCSS;
}, },
getScales: function (span) { getScales: function (span) {