scribble-mathjax/jax/output/NativeMML/jax.js

17 lines
11 KiB
JavaScript

/*
* /MathJax/jax/output/NativeMML/jax.js
*
* Copyright (c) 2010 Design Science, Inc.
*
* Part of the MathJax library.
* See http://www.mathjax.org for details.
*
* Licensed under the Apache License, Version 2.0;
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
(function(b,e,d,g,f){var a,c=e.Browser.isMSIE;b.Augment({LEFTBUTTON:(c?1:0),MENUKEY:"altKey",noContextMenuBug:e.Browser.isKonequeror,msieQuirks:(c&&!(document.compatMode==="BackCompat")),msieEventBug:e.Browser.isIE9,config:{styles:{}},settings:e.config.menuSettings,Startup:function(){return d.Styles(this.config.styles)},Config:function(){this.SUPER(arguments).Config.call(this);if(this.settings.scale){this.config.scale=this.settings.scale}if(e.config.displayAlign!=="center"){var j=e.config.displayAlign,h=e.config.displayIndent;var i={"text-align":j+"!important"};i["margin-"+j]=h+"!important";MathJax.Hub.Insert(this.config.styles,{"div.MathJax_MathML":i,"div.MathJax_MathML math":{"text-align":j},"div.MathJax_MathContainer > span":{"text-align":j+"!important"}})}},InitializeMML:function(){this.initialized=true;if(e.Browser.isMSIE){try{var h=document.createElement("object");h.id="mathplayer";h.classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987";document.getElementsByTagName("head")[0].appendChild(h);document.namespaces.add("mjx","http://www.w3.org/1998/Math/MathML");document.namespaces.mjx.doImport("#mathplayer")}catch(i){alert("MathJax was not able to set up MathPlayer.\n\nIf MathPlayer is not installed, you need to install it first.\nOtherwise, your security settings may be preventing ActiveX \ncontrols from running. Use the Internet Options item under\nthe Tools menu and select the Security tab, then press the\nCustom Level button. Check that the settings for\n'Run ActiveX Controls', and 'Binary and script behaviors'\nare enabled.\n\nCurrently you will see error messages rather than\ntypeset mathematics.")}}},Translate:function(i){if(!i.parentNode){return}if(!this.initialized){this.InitializeMML()}var m=i.previousSibling;if(m&&String(m.className).match(/^MathJax(_MathML|_Display)?$/)){m.parentNode.removeChild(m)}var l=i.MathJax.elementJax.root;var k=(l.Get("display")==="block"?"div":"span");var j=document.createElement(k),h=j;j.className="MathJax_MathML";j.style.fontSize=this.config.scale+"%";if(c&&this.config.showMathMenuMSIE){h=g.addElement(j,"span",{className:"MathJax_MathContainer",style:{display:"inline-block",position:"relative"}})}l.toNativeMML(h);i.parentNode.insertBefore(j,i);if(c){if(this.config.showMathMenuMSIE){this.MSIEoverlay(j)}}else{l=j.firstChild;l.jaxID="NativeMML";l.oncontextmenu=f.Menu;l.onmouseover=f.Mouseover;l.onmousout=f.Mouseout;l.onmousedown=f.Mousedown;l.onclick=f.Click;l.ondblclick=f.DblClick}},Remove:function(h){var i=h.SourceElement();if(!i){return}i=i.previousSibling;if(!i){return}if(i.className.match(/MathJax_MathML/)){i.parentNode.removeChild(i)}},MMLnamespace:"http://www.w3.org/1998/Math/MathML",MSIEoverlay:function(o){var n=o.firstChild;o.style.position="absolute";var p=o.scrollHeight,j=o.offsetWidth;var l=g.addElement(o,"img",{src:"about:blank",style:{width:0,height:p+"px"}});var h=o.scrollHeight-p;o.removeChild(l);o.style.position="";var m,k,i=(o.parentNode.nodeName.toLowerCase()==="div");if(i&&this.quirks){m=-p;k=Math.floor(-j/2)}else{m=h-p,k=-j}g.addElement(o,"span",{style:{display:"inline-block",width:0,height:0,position:"relative"}},[["span",{style:{display:"inline-block",position:"absolute",left:k+"px",top:m+"px",width:n.offsetWidth+"px",height:p+"px",cursor:"pointer","background-color":"white",filter:"alpha(opacity=0)"},onmousedown:this.MSIEevent,oncontextmenu:this.MSIEevent,onclick:this.MSIEevent,onmouseup:this.MSIEevent,onmousemove:this.MSIEevent,ondblclick:this.MSIEevent,onmouseover:this.MSIEevent,onmouseout:this.MSIEevent}]])},MSIEmath:function(h){var i=h.parentNode.previousSibling.firstChild;return(i.nodeName.toLowerCase()==="span"?i.firstChild:i)},MSIEevent:function(){var i=b.MSIEmath(this);var h=window.event;var j=b["MSIE"+h.type];if(j&&j.call(b,h,i,this)){return false}if(i.fireEvent){i.fireEvent("on"+h.type,h)}return false},MSIEmousedown:function(j,i,h){if(j[this.MENUKEY]&&j.button===this.LEFTBUTTON&&this.settings.context!=="MathJax"){this.trapUp=this.trapClick=true;this.ContextMenu(j,h,true);return true}if(this.MSIEzoomKeys&&this.MSIEzoomKeys(j)){this.trapUp=true;return true}return false},MSIEcontextmenu:function(j,i,h){if(this.settings.context==="MathJax"){this.trapUp=this.trapClick=true;this.ContextMenu(j,h);return true}return false},HandleEvent:f.HandleEvent,ContextMenu:function(i,h,j){if(this.config.showMathMenu&&(this.settings.context==="MathJax"||j)){if(document.selection){setTimeout("document.selection.empty()",0)}if(this.msieEventBug){i=window.event}h=h.parentNode;if(c){h=h.parentNode}delete this.trapClick;delete this.trapUp;return f.ContextMenu(i,h)}},Mousedown:function(i,h){if(this.config.showMathMenu){if(this.settings.context==="MathJax"){if(!this.noContextMenuBug||i.button!==2){return}}else{if(!i[b.MENUKEY]||i.button!==b.LEFTBUTTON){return}}return this.ContextMenu(i,h,true)}},NAMEDSPACE:{negativeveryverythinmathspace:"-.0556em",negativeverythinmathspace:"-.1111em",negativethinmathspace:"-.1667em",negativemediummathspace:"-.2222em",negativethickmathspace:"-.2778em",negativeverythickmathspace:"-.3333em",negativeveryverythickmathspace:"-.3889em"}});e.Register.StartupHook("mml Jax Ready",function(){a=MathJax.ElementJax.mml;a.mbase.Augment({toNativeMML:function(n){var k=this.NativeMMLelement(this.type);this.NativeMMLattributes(k);for(var l=0,j=this.data.length;l<j;l++){if(this.data[l]){this.data[l].toNativeMML(k)}else{k.appendChild(this.NativeMMLelement("mrow"))}}n.appendChild(k)},NativeMMLattributes:function(k){var o=this.defaults;var q=this.NativeMMLcopyAttributes,n=this.NativeMMLskipAttributes;if(this.type==="mstyle"){o=a.math.prototype.defaults}for(var p in o){if(!n[p]&&o.hasOwnProperty(p)){if(this[p]!=null){k.setAttribute(p,this.NativeMMLattribute(p,this[p]))}}}for(var l=0,j=q.length;l<j;l++){if(this[q[l]]!=null){k.setAttribute(q[l],this.NativeMMLattribute(q[l],this[q[l]]))}}},NativeMMLcopyAttributes:["fontfamily","fontsize","fontweight","fontstyle","color","background","id","class","href","style"],NativeMMLskipAttributes:{texClass:1,useHeight:1,texprimestyle:1},NativeMMLattribute:function(j,i){i=String(i);if(b.NAMEDSPACE[i]){i=b.NAMEDSPACE[i]}else{if(i.match(/^\s*([-+]?(\d+(\.\d*)?|\.\d+))\s*mu\s*$/)){i=((1/18)*RegExp.$1)+"em"}else{if(i==="-tex-caligraphic"){i="script"}else{if(i==="-tex-oldstyle"){i="normal"}}}}return i},NativeMMLelement:(c?function(i){return document.createElement("mjx:"+i)}:function(i){return document.createElementNS(b.MMLnamespace,i)})});a.mrow.Augment({toNativeMML:function(l){if(this.inferred&&this.parent.inferRow){for(var k=0,j=this.data.length;k<j;k++){if(this.data[k]){this.data[k].toNativeMML(l)}else{l.appendChild(this.NativeMMLelement("mrow"))}}}else{this.SUPER(arguments).toNativeMML.call(this,l)}}});a.msubsup.Augment({toNativeMML:function(o){var n=this.type;if(this.data[this.sup]==null){n="msub"}if(this.data[this.sub]==null){n="msup"}var k=this.NativeMMLelement(n);this.NativeMMLattributes(k);delete this.data[0].inferred;for(var l=0,j=this.data.length;l<j;l++){if(this.data[l]){this.data[l].toNativeMML(k)}}o.appendChild(k)}});a.munderover.Augment({toNativeMML:function(o){var n=this.type;if(this.data[this.under]==null){n="mover"}if(this.data[this.over]==null){n="munder"}var k=this.NativeMMLelement(n);this.NativeMMLattributes(k);delete this.data[0].inferred;for(var l=0,j=this.data.length;l<j;l++){if(this.data[l]){this.data[l].toNativeMML(k)}}o.appendChild(k)}});if(e.Browser.isFirefox){a.mtable.Augment({toNativeMML:function(i){if(this.width){var j=(this.style||"").replace(/;\s*$/,"").split(";");j.push("width:"+this.width);this.style=j.join(";")}this.SUPER(arguments).toNativeMML.call(this,i)}});a.mlabeledtr.Augment({toNativeMML:function(n){var k=this.NativeMMLelement("mtr");this.NativeMMLattributes(k);for(var l=1,j=this.data.length;l<j;l++){if(this.data[l]){this.data[l].toNativeMML(k)}else{k.appendChild(this.NativeMMLelement("mrow"))}}n.appendChild(k)}});var h=MathJax.Hub.config.root+"/fonts/HTML-CSS/TeX/otf";b.Augment({config:{styles:{'[mathvariant="double-struck"]':{"font-family":"MathJax_AMS"},'[mathvariant="script"]':{"font-family":"MathJax_Script"},'[mathvariant="fraktur"]':{"font-family":"MathJax_Fraktur"},'[mathvariant="-tex-oldstyle"]':{"font-family":"MathJax_Caligraphic"},'[mathvariant="-tex-oldstyle-bold"]':{"font-family":"MathJax_Caligraphic","font-weight":"bold"},'[mathvariant="-tex-caligraphic"]':{"font-family":"MathJax_Caligraphic"},'[mathvariant="-tex-caligraphic-bold"]':{"font-family":"MathJax_Caligraphic","font-weight":"bold"},'[mathvariant="bold-script"]':{"font-family":"MathJax_Script","font-weight":"bold"},'[mathvariant="bold-fraktur"]':{"font-family":"MathJax_Fraktur","font-weight":"bold"},'[mathvariant="monospace"]':{"font-family":"monospace"},'[mathvariant="sans-serif"]':{"font-family":"sansserif"},'[mathvariant="bold-sans-serif"]':{"font-family":"sansserif","font-weight":"bold"},'[mathvariant="sans-serif-italic"]':{"font-family":"sansserif","font-style":"italic"},'[mathvariant="sans-serif-bold-italic"]':{"font-family":"sansserif","font-style":"italic","font-weight":"bold"},"@font-face /*1*/":{"font-family":"MathJax_AMS",src:"local('MathJax_AMS'), url('"+h+"/MathJax_AMS-Regular.otf')"},"@font-face /*2*/":{"font-family":"MathJax_Script",src:"local('MathJax_Script'), url('"+h+"/MathJax_Script-Regular.otf')"},"@font-face /*3*/":{"font-family":"MathJax_Fraktur",src:"local('MathJax_Fraktur'), url('"+h+"/MathJax_Fraktur-Regular.otf')"},"@font-face /*4*/":{"font-family":"MathJax_Caligraphic",src:"local('MathJax_Caligraphic'), url('"+h+"/MathJax_Caligraphic-Regular.otf')"},"@font-face /*5*/":{"font-family":"MathJax_Fraktur","font-weight":"bold",src:"local('MathJax_Fraktur-Bold'), url('"+h+"/MathJax_Fraktur-Bold.otf')"},"@font-face /*6*/":{"font-family":"MathJax_Caligraphic","font-weight":"bold",src:"local('MathJax_Caligraphic-Bold'), url('"+h+"/MathJax_Caligraphic-Bold.otf')"}}}})}a.TeXAtom.Augment({toNativeMML:function(j){var i=this.NativeMMLelement("mrow");this.data[0].toNativeMML(i);j.appendChild(i)}});a.chars.Augment({toNativeMML:function(i){i.appendChild(document.createTextNode(this.toString()))}});a.entity.Augment({toNativeMML:function(i){i.appendChild(document.createTextNode(this.toString()))}});a.xml.Augment({toNativeMML:function(l){for(var k=0,j=this.data.length;k<j;k++){l.appendChild(this.data[k].cloneNode(true))}}});e.Register.StartupHook("TeX mathchoice Ready",function(){a.TeXmathchoice.Augment({toNativeMML:function(i){this.Core().toNativeMML(i)}})});setTimeout(MathJax.Callback(["loadComplete",b,"jax.js"]),0)});e.Register.StartupHook("End Cookie",function(){if(e.config.menuSettings.zoom!=="None"){d.Require("[MathJax]/extensions/MathZoom.js")}})})(MathJax.OutputJax.NativeMML,MathJax.Hub,MathJax.Ajax,MathJax.HTML,MathJax.HTML.Event);