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:
parent
046079b805
commit
7042c1d64f
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
|
@ -1348,7 +1348,8 @@ MathJax.Hub = {
|
|||
scripts: [], // filled in by prepareScripts
|
||||
start: new Date().getTime(), // timer for processing messages
|
||||
i: 0, // current script
|
||||
jax: {} // scripts grouped by output jax
|
||||
jax: {}, // scripts grouped by output jax
|
||||
jaxIDs: [] // id's of jax used
|
||||
};
|
||||
queue.Push(
|
||||
["Post",this.signal,["Begin "+action,ec.elements[i]]],
|
||||
|
@ -1466,8 +1467,18 @@ MathJax.Hub = {
|
|||
// and put this script in the queue for that jax
|
||||
//
|
||||
jax.outputJax = this.outputJax[jax.mimeType][0].id;
|
||||
if (!state.jax[jax.outputJax]) {state.jax[jax.outputJax] = []}
|
||||
state.jax[jax.outputJax].push(script);
|
||||
if (!state.jax[jax.outputJax]) {
|
||||
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
|
||||
|
@ -1475,7 +1486,7 @@ MathJax.Hub = {
|
|||
state.i++; var now = new Date().getTime();
|
||||
if (now - state.start > this.processUpdateTime && state.i < state.scripts.length) {
|
||||
state.start = now;
|
||||
tihs.processMessage(state,"Input");
|
||||
this.processMessage(state,"Input");
|
||||
this.RestartAfter(MathJax.Callback.Delay(1));
|
||||
}
|
||||
}
|
||||
|
@ -1494,10 +1505,10 @@ MathJax.Hub = {
|
|||
// (to get scaling factors, hide/show output, and so on)
|
||||
//
|
||||
prepareOutput: function (state,method) {
|
||||
for (var id in state.jax) {if (state.jax.hasOwnProperty(id)) {
|
||||
var JAX = MathJax.OutputJax[id];
|
||||
for (var i = 0, m = state.jaxIDs.length; i < m; i++) {
|
||||
var id = state.jaxIDs[i], JAX = MathJax.OutputJax[id];
|
||||
if (JAX[method]) {JAX[method](state.jax[id])}
|
||||
}}
|
||||
}
|
||||
},
|
||||
|
||||
processOutput: function (state) {
|
||||
|
@ -2049,7 +2060,7 @@ MathJax.Hub.Startup = {
|
|||
if (typeof(jax[id]) === 'undefined' && id !== 'newID') {delete this[id]}
|
||||
}
|
||||
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'))
|
||||
{this[id] = jax[id]}
|
||||
}
|
||||
|
|
|
@ -370,40 +370,57 @@
|
|||
if (!FONT.available) {HTMLCSS.Font.testFont(FONT)}
|
||||
}
|
||||
},
|
||||
|
||||
preTranslate: function (scripts) {
|
||||
for (var i = 0, m = scripts.length; i < m; i++) {
|
||||
var script = scripts[i]; if (!script.parentNode) return;
|
||||
var prev = script.previousSibling;
|
||||
if (prev && String(prev.className).match(/^MathJax(_Display)?$/))
|
||||
{prev.parentNode.removeChild(prev)}
|
||||
var math = script.MathJax.elementJax, span, div;
|
||||
math.HTMLCSS = {display: (math.root.Get("display") === "block")}
|
||||
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
|
||||
});
|
||||
if (math.HTMLCSS.display) {
|
||||
div = this.Element("div",{className:"MathJax_Display", style:{width:"100%"}});
|
||||
div.appendChild(span);
|
||||
}
|
||||
// (screen readers don't know about role="math" yet, so use "textbox" instead)
|
||||
div.setAttribute("role","textbox"); div.setAttribute("aria-readonly","true");
|
||||
div.className += " MathJax_Processing";
|
||||
script.parentNode.insertBefore(div,script);
|
||||
try {
|
||||
this.getScales(span);
|
||||
math.HTMLCSS.isHidden = (this.em === 0 || String(this.em) === "NaN");
|
||||
} catch (err) {
|
||||
math.HTMLCSS.isHidden = true;
|
||||
}
|
||||
if (math.HTMLCSS.isHidden) {this.hiddenDiv.appendChild(div); this.getScales(span)}
|
||||
math.HTMLCSS.em = this.em; math.HTMLCSS.outerEm = this.outerEm;
|
||||
math.HTMLCSS.scale = this.msieMarginScale; math.HTMLCSS.fontSize = span.style.fontSize;
|
||||
}
|
||||
},
|
||||
|
||||
Translate: function (script) {
|
||||
if (!script.parentNode) return;
|
||||
var prev = script.previousSibling;
|
||||
if (prev && String(prev.className).match(/^MathJax(_MathML|_Display)?$/))
|
||||
{prev.parentNode.removeChild(prev)}
|
||||
var math = script.MathJax.elementJax.root, span, div, frame;
|
||||
span = div = frame = this.Element("span",{
|
||||
className:"MathJax", oncontextmenu:this.ContextMenu, onmousedown: this.Mousedown,
|
||||
onmouseover:this.Mouseover, onclick:this.Click, ondblclick:this.DblClick
|
||||
});
|
||||
var blockMode = (math.Get("display") === "block");
|
||||
if (blockMode) {
|
||||
div = frame = this.Element("div",{className:"MathJax_Display", style:{width:"100%", position:"relative"}});
|
||||
div.appendChild(span);
|
||||
}
|
||||
// (screen readers don't know about role="math" yet, so use "textbox" instead)
|
||||
div.setAttribute("role","textbox"); div.setAttribute("aria-readonly","true");
|
||||
if (this.useProcessingFrame) {
|
||||
frame = this.Element((blockMode ? "div" : "span"),{className:"MathJax_Processing"});
|
||||
frame.appendChild(div);
|
||||
}
|
||||
script.parentNode.insertBefore(frame,script); var isHidden;
|
||||
try {this.getScales(span); isHidden = (this.em === 0 || String(this.em) === "NaN")} catch (err) {isHidden = true}
|
||||
if (isHidden) {this.hiddenDiv.appendChild(frame); this.getScales(span)}
|
||||
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.initHTML(math,span);
|
||||
math.setTeXclass();
|
||||
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;
|
||||
}
|
||||
if (isHidden) {script.parentNode.insertBefore(frame,script)}
|
||||
if (this.useProcessingFrame) frame.parentNode.replaceChild(div,frame);
|
||||
if (jax.HTMLCSS.isHidden) {script.parentNode.insertBefore(div,script)}
|
||||
div.className = div.className.split(/ /)[0];
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -474,9 +491,12 @@
|
|||
},
|
||||
|
||||
Remove: function (jax) {
|
||||
var span = jax.SourceElement(); if (!span) return;
|
||||
span = span.previousSibling; if (!span) return;
|
||||
if (span.className.match(/^MathJax/)) {span.parentNode.removeChild(span)}
|
||||
var span = document.getElementById(jax.inputID+"-Frame");
|
||||
if (span) {
|
||||
if (jax.HTMLCSS.display) {span = span.parentNode}
|
||||
span.parentNode.removeChild(span);
|
||||
}
|
||||
delete jax.HTMLCSS;
|
||||
},
|
||||
|
||||
getScales: function (span) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user