/* This compressed file is part of Xinha. For uncompressed sources, forum, and bug reports, go to xinha.org */
/* This file is part of version 0.96beta2 released Fri, 20 Mar 2009 11:01:14 +0100 */
function Equation(c){this.editor=c;var a=c.config;var b=this;a.registerButton({id:"equation",tooltip:this._lc("Formula Editor"),image:c.imgURL("equation.gif","Equation"),textMode:false,action:function(d,f){b.buttonPress(d,f)}});a.addToolbarElement("equation","inserthorizontalrule",-1);mathcolor=a.Equation.mathcolor;mathfontfamily=a.Equation.mathfontfamily;this.enabled=!Xinha.is_ie;if(this.enabled){this.onBeforeSubmit=this.onBeforeUnload=function(){b.unParse()}}if(typeof AMprocessNode!="function"){Xinha._loadback(Xinha.getPluginDir("Equation")+"/ASCIIMathML.js",function(){translate()})}}Xinha.Config.prototype.Equation={mathcolor:"black",mathfontfamily:"serif"};Equation._pluginInfo={name:"ASCIIMathML Formula Editor",version:"2.3 (2008-01-26)",developer:"Raimund Meyer",developer_url:"http://x-webservice.net",c_owner:"",sponsor:"",sponsor_url:"",license:"GNU/LGPL"};Equation.prototype._lc=function(a){return Xinha._lc(a,"Equation")};Equation.prototype.onGenerate=function(){this.parse()};Equation.prototype.onKeyPress=function(b){if(this.enabled){e=this.editor;var a=e._getFirstAncestor(e.getSelection(),["span"]);if(a&&a.className=="AM"){if(b.keyCode==8||b.keyCode==46||b.charCode){Xinha._stopEvent(b);return true}}}return false};Equation.prototype.onBeforeMode=function(a){if(this.enabled&&a=="textmode"){this.unParse()}};Equation.prototype.onMode=function(a){if(this.enabled&&a=="wysiwyg"){this.parse()}};Equation.prototype.parse=function(){if(this.enabled){var f=this.editor._doc;var b=f.getElementsByTagName("span");for(var a=0;a<b.length;a++){var c=b[a];if(c.className!="AM"){continue}if(c.innerHTML.indexOf(this.editor.cc)!=-1){c.innerHTML=c.innerHTML.replace(this.editor.cc,"");c.parentNode.insertBefore(f.createTextNode(this.editor.cc),c)}c.title=c.innerHTML;var g=c.cloneNode(true);try{document.adoptNode(g)}catch(d){}AMprocessNode(g,false);try{f.adoptNode(g)}catch(d){}c.parentNode.replaceChild(g,c);g.parentNode.insertBefore(f.createTextNode(String.fromCharCode(32)),g);g.parentNode.insertBefore(f.createTextNode(String.fromCharCode(32)),g.nextSibling)}}};Equation.prototype.unParse=function(){var d=this.editor._doc;var b=d.getElementsByTagName("span");for(var a=0;a<b.length;a++){var c=b[a];if(c.className.indexOf("AM")==-1||c.getElementsByTagName("math").length==0){continue}var f=c.getAttribute("title");c.innerHTML=f;c.setAttribute("title",null)}};Equation.prototype.buttonPress=function(){var a=this;var d=this.editor;var b={};b.editor=d;var c=d._getFirstAncestor(d.getSelection(),["span"]);if(c){b.editedNode=c}Dialog(Xinha.getPluginDir("Equation")+"/popups/dialog.html",function(f){a.insert(f)},b)};Equation.prototype.insert=function(b){if(typeof b.formula!="undefined"){var c=(b.formula!="")?b.formula.replace(/^`?(.*)`?$/m,"`$1`"):"";if(b.editedNode&&(b.editedNode.tagName.toLowerCase()=="span")){var a=b.editedNode;if(c!=""){a.innerHTML=c;if(this.enabled){a.title=c}}else{a.parentNode.removeChild(a)}}else{if(!b.editedNode&&c!=""){if(this.enabled){var a=document.createElement("span");a.className="AM";this.editor.insertNodeAtSelection(a);a.innerHTML=c;a.title=c}else{this.editor.insertHTML('<span class="AM">'+c+"</span>")}}}if(this.enabled){this.parse()}}};