Add MathJax.HTML.setScript() to handle setting a script's value (taking IE9 bug into account), and use it where scripts are created (resolves issue#5)

This commit is contained in:
Davide P. Cervone 2011-02-07 19:48:47 -05:00
parent 1a073c1004
commit 31c32f8f20
16 changed files with 44 additions and 35 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

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

@ -1,5 +1,5 @@
/*
* /MathJax/extensions/jsMath2jax.js
* extensions/jsMath2jax.js
*
* Copyright (c) 2010 Design Science, Inc.
*
@ -12,5 +12,5 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
MathJax.Extension.jsMath2jax={version:"1.0.1",config:{element:null,preview:"TeX"},PreProcess:function(b){if(!this.configured){MathJax.Hub.Insert(this.config,(MathJax.Hub.config.jsMath2jax||{}));if(this.config.Augment){MathJax.Hub.Insert(this,this.config.Augment)}if(typeof(this.config.previewTeX)!=="undefined"&&!this.config.previewTeX){this.config.preview="none"}this.previewClass=MathJax.Hub.config.preRemoveClass;this.configured=true}if(typeof(b)==="string"){b=document.getElementById(b)}if(!b){b=this.config.element||document.body}var c=b.getElementsByTagName("span"),a;for(a=c.length-1;a>=0;a--){if(String(c[a].className).match(/(^| )math( |$)/)){this.ConvertMath(c[a],"")}}var d=b.getElementsByTagName("div");for(a=d.length-1;a>=0;a--){if(String(d[a].className).match(/(^| )math( |$)/)){this.ConvertMath(d[a],"; mode=display")}}},ConvertMath:function(c,d){if(c.getElementsByTagName("script").length===0){var b=c.parentNode,a=this.createMathTag(d,c.innerHTML);if(c.nextSibling){b.insertBefore(a,c.nextSibling)}else{b.appendChild(a)}if(this.config.preview!=="none"){this.createPreview(c)}b.removeChild(c)}},createPreview:function(a){var b;if(this.config.preview==="TeX"){b=[this.filterTeX(a.innerHTML)]}else{if(this.config.preview instanceof Array){b=this.config.preview}}if(b){b=MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},b);a.parentNode.insertBefore(b,a)}},createMathTag:function(c,b){b=b.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");var a=document.createElement("script");a.type="math/tex"+c;if(MathJax.Hub.Browser.isMSIE){a.text=b}else{a.appendChild(document.createTextNode(b))}return a},filterTeX:function(a){return a}};MathJax.Hub.Register.PreProcessor(["PreProcess",MathJax.Extension.jsMath2jax]);MathJax.Ajax.loadComplete("[MathJax]/extensions/jsMath2jax.js");
MathJax.Extension.jsMath2jax={version:"1.0.2",config:{element:null,preview:"TeX"},PreProcess:function(b){if(!this.configured){MathJax.Hub.Insert(this.config,(MathJax.Hub.config.jsMath2jax||{}));if(this.config.Augment){MathJax.Hub.Insert(this,this.config.Augment)}if(typeof(this.config.previewTeX)!=="undefined"&&!this.config.previewTeX){this.config.preview="none"}this.previewClass=MathJax.Hub.config.preRemoveClass;this.configured=true}if(typeof(b)==="string"){b=document.getElementById(b)}if(!b){b=this.config.element||document.body}var c=b.getElementsByTagName("span"),a;for(a=c.length-1;a>=0;a--){if(String(c[a].className).match(/(^| )math( |$)/)){this.ConvertMath(c[a],"")}}var d=b.getElementsByTagName("div");for(a=d.length-1;a>=0;a--){if(String(d[a].className).match(/(^| )math( |$)/)){this.ConvertMath(d[a],"; mode=display")}}},ConvertMath:function(c,d){if(c.getElementsByTagName("script").length===0){var b=c.parentNode,a=this.createMathTag(d,c.innerHTML);if(c.nextSibling){b.insertBefore(a,c.nextSibling)}else{b.appendChild(a)}if(this.config.preview!=="none"){this.createPreview(c)}b.removeChild(c)}},createPreview:function(a){var b;if(this.config.preview==="TeX"){b=[this.filterTeX(a.innerHTML)]}else{if(this.config.preview instanceof Array){b=this.config.preview}}if(b){b=MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},b);a.parentNode.insertBefore(b,a)}},createMathTag:function(c,b){b=b.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");var a=document.createElement("script");a.type="math/tex"+c;MathJax.HTML.setScript(a,b);return a},filterTeX:function(a){return a}};MathJax.Hub.Register.PreProcessor(["PreProcess",MathJax.Extension.jsMath2jax]);MathJax.Ajax.loadComplete("[MathJax]/extensions/jsMath2jax.js");

View File

@ -1,5 +1,5 @@
/*
* /MathJax/extensions/mml2jax.js
* extensions/mml2jax.js
*
* Copyright (c) 2010 Design Science, Inc.
*
@ -12,5 +12,5 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
MathJax.Extension.mml2jax={varsion:"1.0.4",config:{element:null,preview:"alttext"},MMLnamespace:"http://www.w3.org/1998/Math/MathML",PreProcess:function(e){if(!this.configured){MathJax.Hub.Insert(this.config,(MathJax.Hub.config.mml2jax||{}));if(this.config.Augment){MathJax.Hub.Insert(this,this.config.Augment)}this.InitBrowser();this.configured=true}if(typeof(e)==="string"){e=document.getElementById(e)}if(!e){e=this.config.element||document.body}this.ProcessMathArray(e.getElementsByTagName("math"));if(e.getElementsByTagNameNS){this.ProcessMathArray(e.getElementsByTagNameNS(this.MMLnamespace,"math"))}var d=document.getElementsByTagName("html")[0];if(d){for(var c=0,b=d.attributes.length;c<b;c++){var a=d.attributes[c];if(a.nodeName.substr(0,6)==="xmlns:"&&a.nodeValue===this.MMLnamespace){this.ProcessMathArray(e.getElementsByTagName(a.nodeName.substr(6)+":math"))}}}},ProcessMathArray:function(b){var a;if(b.length){if(this.msieMathTagBug){for(a=b.length-1;a>=0;a--){if(b[a].nodeName==="MATH"){this.msieProcessMath(b[a])}else{this.ProcessMath(b[a])}}}else{for(a=b.length-1;a>=0;a--){this.ProcessMath(b[a])}}}},ProcessMath:function(e){var d=e.parentNode;var a=document.createElement("script");a.type="math/mml";d.insertBefore(a,e);if(this.msieScriptBug){var b=this.msieOuterHTML(e);b=b.replace(/<\?import .*?>/i,"").replace(/<\?xml:namespace .*?\/>/i,"");a.text=b.replace(/&nbsp;/g,"&#xA0;");d.removeChild(e)}else{var c=MathJax.HTML.Element("span");c.appendChild(e);MathJax.HTML.addText(a,c.innerHTML)}if(this.config.preview!=="none"){this.createPreview(e,a)}},msieProcessMath:function(e){var c=e.parentNode;var a=document.createElement("script");a.type="math/mml";c.insertBefore(a,e);var b="",d;while(e&&e.nodeName!=="/MATH"){d=e;e=e.nextSibling;b+=this.msieNodeHTML(d);d.parentNode.removeChild(d)}if(e&&e.nodeName==="/MATH"){e.parentNode.removeChild(e)}a.text=b+"</math>";if(this.config.preview!=="none"){this.createPreview(e,a)}},msieNodeHTML:function(d){var c,b,a;if(d.nodeName==="#text"||d.nodeName==="#comment"){c=d.nodeValue.replace(/&/g,"&#x26;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}else{if(this.msieAttributeBug){c="<"+d.nodeName.toLowerCase();for(b=0,a=d.attributes.length;b<a;b++){if(d.attributes[b].specified){c+=" "+d.attributes[b].nodeName.toLowerCase()+"=";c+='"'+d.attributes[b].nodeValue.replace(/\"/g,'\\"')+'"'}}c+=">"}else{c=this.toLowerCase(d.outerHTML);var e=c.split(/\"/);for(b=0,a=e.length;b<a;b+=2){e[b]=e[b].toLowerCase()}c=e.join('"')}}return c},msieOuterHTML:function(d){if(d.nodeName.charAt(0)==="#"){return this.msieNodeHTML(d)}if(!this.msieAttributeBug){return d.outerHTML}var c=this.msieNodeHTML(d);for(var b=0,a=d.childNodes.length;b<a;b++){c+=this.msieOuterHTML(d.childNodes[b])}c+="</"+d.nodeName.toLowerCase()+">";return c},createPreview:function(b,a){var c;if(this.config.preview==="alttext"){var d=b.getAttribute("alttext");if(d!=null){c=[this.filterText(d)]}}else{if(this.config.preview instanceof Array){c=this.config.preview}}if(c){c=MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},c);a.parentNode.insertBefore(c,a)}},filterText:function(a){return a},InitBrowser:function(){MathJax.Hub.Browser.Select({MSIE:function(a){var b=MathJax.HTML.Element("span",{className:"mathjax"});MathJax.Hub.Insert(MathJax.Extension.mml2jax,{msieScriptBug:true,msieMathTagBug:(MathJax.HTML.Element("span",{innerHTML:"<math><mi>x</mi></math>"}).childNodes.length!==1),msieAttributeBug:(b.outerHTML.substr(12)!=='"')})}})}};MathJax.Hub.Register.PreProcessor(["PreProcess",MathJax.Extension.mml2jax]);MathJax.Ajax.loadComplete("[MathJax]/extensions/mml2jax.js");
MathJax.Extension.mml2jax={varsion:"1.0.5",config:{element:null,preview:"alttext"},MMLnamespace:"http://www.w3.org/1998/Math/MathML",PreProcess:function(e){if(!this.configured){MathJax.Hub.Insert(this.config,(MathJax.Hub.config.mml2jax||{}));if(this.config.Augment){MathJax.Hub.Insert(this,this.config.Augment)}this.InitBrowser();this.configured=true}if(typeof(e)==="string"){e=document.getElementById(e)}if(!e){e=this.config.element||document.body}this.ProcessMathArray(e.getElementsByTagName("math"));if(e.getElementsByTagNameNS){this.ProcessMathArray(e.getElementsByTagNameNS(this.MMLnamespace,"math"))}var d=document.getElementsByTagName("html")[0];if(d){for(var c=0,b=d.attributes.length;c<b;c++){var a=d.attributes[c];if(a.nodeName.substr(0,6)==="xmlns:"&&a.nodeValue===this.MMLnamespace){this.ProcessMathArray(e.getElementsByTagName(a.nodeName.substr(6)+":math"))}}}},ProcessMathArray:function(b){var a;if(b.length){if(this.msieMathTagBug){for(a=b.length-1;a>=0;a--){if(b[a].nodeName==="MATH"){this.msieProcessMath(b[a])}else{this.ProcessMath(b[a])}}}else{for(a=b.length-1;a>=0;a--){this.ProcessMath(b[a])}}}},ProcessMath:function(e){var d=e.parentNode;var a=document.createElement("script");a.type="math/mml";d.insertBefore(a,e);if(this.msieScriptBug){var b=this.msieOuterHTML(e);b=b.replace(/<\?import .*?>/i,"").replace(/<\?xml:namespace .*?\/>/i,"");MathJax.HTML.setScript(a,b.replace(/&nbsp;/g,"&#xA0;"));d.removeChild(e)}else{var c=MathJax.HTML.Element("span");c.appendChild(e);MathJax.HTML.setScript(a,c.innerHTML)}if(this.config.preview!=="none"){this.createPreview(e,a)}},msieProcessMath:function(e){var c=e.parentNode;var a=document.createElement("script");a.type="math/mml";c.insertBefore(a,e);var b="",d;while(e&&e.nodeName!=="/MATH"){d=e;e=e.nextSibling;b+=this.msieNodeHTML(d);d.parentNode.removeChild(d)}if(e&&e.nodeName==="/MATH"){e.parentNode.removeChild(e)}a.text=b+"</math>";if(this.config.preview!=="none"){this.createPreview(e,a)}},msieNodeHTML:function(d){var c,b,a;if(d.nodeName==="#text"||d.nodeName==="#comment"){c=d.nodeValue.replace(/&/g,"&#x26;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}else{if(this.msieAttributeBug){c="<"+d.nodeName.toLowerCase();for(b=0,a=d.attributes.length;b<a;b++){if(d.attributes[b].specified){c+=" "+d.attributes[b].nodeName.toLowerCase()+"=";c+='"'+d.attributes[b].nodeValue.replace(/\"/g,'\\"')+'"'}}c+=">"}else{c=this.toLowerCase(d.outerHTML);var e=c.split(/\"/);for(b=0,a=e.length;b<a;b+=2){e[b]=e[b].toLowerCase()}c=e.join('"')}}return c},msieOuterHTML:function(d){if(d.nodeName.charAt(0)==="#"){return this.msieNodeHTML(d)}if(!this.msieAttributeBug){return d.outerHTML}var c=this.msieNodeHTML(d);for(var b=0,a=d.childNodes.length;b<a;b++){c+=this.msieOuterHTML(d.childNodes[b])}c+="</"+d.nodeName.toLowerCase()+">";return c},createPreview:function(b,a){var c;if(this.config.preview==="alttext"){var d=b.getAttribute("alttext");if(d!=null){c=[this.filterText(d)]}}else{if(this.config.preview instanceof Array){c=this.config.preview}}if(c){c=MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},c);a.parentNode.insertBefore(c,a)}},filterText:function(a){return a},InitBrowser:function(){MathJax.Hub.Browser.Select({MSIE:function(a){var b=MathJax.HTML.Element("span",{className:"mathjax"});MathJax.Hub.Insert(MathJax.Extension.mml2jax,{msieScriptBug:true,msieMathTagBug:(MathJax.HTML.Element("span",{innerHTML:"<math><mi>x</mi></math>"}).childNodes.length!==1),msieAttributeBug:(b.outerHTML.substr(12)!=='"')})}})}};MathJax.Hub.Register.PreProcessor(["PreProcess",MathJax.Extension.mml2jax]);MathJax.Ajax.loadComplete("[MathJax]/extensions/mml2jax.js");

File diff suppressed because one or more lines are too long

View File

@ -29,7 +29,7 @@ if (document.getElementById && document.childNodes && document.createElement) {
if (!window.MathJax) {window.MathJax= {}}
if (!MathJax.Hub) { // skip if already loaded
MathJax.version = "1.0.10";
MathJax.version = "1.0.11";
/**********************************************************/
@ -939,6 +939,16 @@ MathJax.HTML = {
TextNode: function (text) {return document.createTextNode(text)},
addText: function (span,text) {return span.appendChild(this.TextNode(text))},
//
// Set the text of a script
//
setScript: function (script,text) {
if (this.setScriptBug) {script.text = text} else {
while (script.firstChild) {script.removeChild(script.firstChild)}
this.addText(script,text);
}
},
//
// Manage cookies
//
@ -1297,7 +1307,7 @@ MathJax.Hub = {
Update: function (script) {
var jax = script.MathJax.elementJax;
// FIXME: Have intputJax determine if things have changed?
if (jax && jax.originalText === (script.text == ""? script.innerHTML : script.text))
if (jax && jax.originalText === (script.text == "" ? script.innerHTML : script.text))
{script.MathJax.state = jax.STATE.PROCESSED} else
{jax.outputJax.Remove(jax); script.MathJax.state = jax.STATE.UPDATE}
},
@ -1803,10 +1813,7 @@ MathJax.Hub.Startup = {
Text: function (text,callback) {
var script = this.SourceElement();
if (script.firstChild) {
if (script.firstChild.nodeName !== "#text") {script.text = text}
else {script.firstChild.nodeValue = text}
} else {try {script.innerHTML = text} catch(err) {script.text = text}}
BASE.HTML.setScript(script,text);
script.MathJax.state = this.STATE.UPDATE;
return HUB.Update(script,callback);
},
@ -1966,7 +1973,11 @@ MathJax.Hub.Startup = {
else if (date >= "20061024") {browser.version = "2.0"}
}
},
Opera: function (browser) {browser.version = opera.version()}
Opera: function (browser) {browser.version = opera.version()},
MSIE: function (browser) {
browser.isIE9 = !!(document.documentMode && window.msPerformance);
MathJax.HTML.setScriptBug = !browser.isIE9 || document.documentMode < 9;
}
});
HUB.Browser.Select(MathJax.Message.browsers);

View File

@ -31,7 +31,7 @@
*/
MathJax.Extension.jsMath2jax = {
version: "1.0.1",
version: "1.0.2",
config: {
element: null, // The ID of the element to be processed
@ -86,8 +86,7 @@ MathJax.Extension.jsMath2jax = {
tex = tex.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");
var script = document.createElement("script");
script.type = "math/tex" + mode;
if (MathJax.Hub.Browser.isMSIE) {script.text = tex}
else {script.appendChild(document.createTextNode(tex))}
MathJax.HTML.setScript(script,tex);
return script;
},

View File

@ -24,7 +24,7 @@
*/
MathJax.Extension.mml2jax = {
varsion: "1.0.4",
varsion: "1.0.5",
config: {
element: null, // The ID of the element to be processed
// (defaults to full document)
@ -90,11 +90,11 @@ MathJax.Extension.mml2jax = {
if (this.msieScriptBug) {
var html = this.msieOuterHTML(math);
html = html.replace(/<\?import .*?>/i,"").replace(/<\?xml:namespace .*?\/>/i,"");
script.text = html.replace(/&nbsp;/g,"&#xA0;");
MathJax.HTML.setScript(script,html.replace(/&nbsp;/g,"&#xA0;"));
parent.removeChild(math);
} else {
var span = MathJax.HTML.Element("span"); span.appendChild(math);
MathJax.HTML.addText(script,span.innerHTML);
MathJax.HTML.setScript(script,span.innerHTML);
}
if (this.config.preview !== "none") {this.createPreview(math,script)}
},

View File

@ -24,7 +24,7 @@
*/
MathJax.Extension.tex2jax = {
version: "1.0.1",
version: "1.0.2",
config: {
element: null, // The ID of the element to be processed
// (defaults to full document)
@ -246,8 +246,7 @@ MathJax.Extension.tex2jax = {
createMathTag: function (mode,tex) {
var script = document.createElement("script");
script.type = "math/tex" + mode;
if (MathJax.Hub.Browser.isMSIE) {script.text = tex}
else {script.appendChild(document.createTextNode(tex))}
MathJax.HTML.setScript(script,tex);
this.insertNode(script);
return script;
},