// ==UserScript==
// @name BrEdiMa GM hatena
// @namespace http://bredima.sourceforge.jp/
// @description Includes GUI Math Editor into hatena::Diary edit page.
// @include http://d.hatena.ne.jp/*/edit*
// ==/UserScript==
Bredima=function(E,D){this.serial=Bredima.serial++;this.dom=E;this.config=new Array();for(var C in Bredima.config.def){this.config[C]=Bredima.config.def[C]}if(D=="float"){this.ignition=E;this.dom=document.createElement("div");this.dom.style.width="580px";this.dom.style.position="absolute";this.dom.style.display="none";var A=document.getElementsByTagName("body")[0];A.appendChild(this.dom);var B=this;Bredima.util.addListener(this.ignition,"click",function(){var F=Bredima.util.getOffset(B.ignition,A);B.dom.style.left=Math.min(F.left,A.clientWidth-590)+"px";B.dom.style.top=(F.top+24)+"px";if(B.isIgnited){B.frame.toggleVisibility()}else{B.isIgnited=true;B.dom.style.display="block";B.write()}})}};Bredima.version="0.71.20080112";Bredima.serial=0;Bredima.setConfig=function(A,B){Bredima.config.set(A,B)};Bredima.insertTo=function(D,C){D.focus();if(D.selectionStart!=null){var E=D.selectionStart;var A=D.selectionEnd;D.value=D.value.substring(0,E)+C+D.value.substring(A);D.setSelectionRange(E,A+C.length)}else{var B=document.selection.createRange();B.text=C;B.select()}};Bredima.prototype.setConfig=function(B,C){for(var A in this.config){if(A==B){this.config[B]=C}}};Bredima.prototype.onSubmit=function(){};Bredima.prototype.toMML=function(A){return this.exp.root.toMML(A)};Bredima.prototype.toLatex=function(){return this.exp.root.toLatex()};Bredima.prototype.toJSON=function(){return JSON.stringify(this.exp.root.toRundown())};Bredima.prototype.write=function(A){if(A){this.dom=A}this.init=new Bredima.Init();this.locale=new Bredima.Locale(this);this.history=new Bredima.History();this.frame=new Bredima.Frame(this,this.dom);this.exp=new Bredima.ExpCtrl(this);this.menu=new Bredima.Menu(this);this.init.observer.attach(this);this.init.exec()};Bredima.prototype.onInitialized=function(){var A=(this.config.json)?JSON.parse(this.config.json):null;this.frame.finalize();this.exp.init(A);this.frame.appear()};Bredima.prototype.getConfig=function(A){return this.config[A]};if(!this.JSON){JSON=function(){function f(n){return n<10?"0"+n:n}Date.prototype.toJSON=function(){return this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z"};var m={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};function stringify(value,whitelist){var a,i,k,l,r=/["\\\x00-\x1f\x7f-\x9f]/g,v;switch(typeof value){case"string":return r.test(value)?'"'+value.replace(r,function(a){var c=m[a];if(c){return c}c=a.charCodeAt();return"\\u00"+Math.floor(c/16).toString(16)+(c%16).toString(16)})+'"':'"'+value+'"';case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}if(typeof value.toJSON==="function"){return stringify(value.toJSON())}a=[];if(typeof value.length==="number"&&!(value.propertyIsEnumerable("length"))){l=value.length;for(i=0;i";C+=D;C+=""+B+">\n";return C};Bredima.util.getTexURI=function(B,A){if(A){A=(typeof (A)=="number")?Bredima.consts.texSize[A]:A;A="\\"+A+" "}return encodeURI(Bredima.config.get("uri_mimetex")+"?"+A+B)};Bredima.note=function(A){document.getElementById("debugFrame").innerHTML+="["+A+"] "};Bredima.util.animation=function(D){var C=D.start;var B=0;var A=(D.end-D.start)/D.step;var E=setInterval(function(){D.func(C);if(B++==D.step){clearInterval(E);if(D.finalize){D.finalize()}}if(B==D.step){C=D.end}else{C=D.start+A*B}},30)};Bredima.util.smoothAnimation=function(D){var C=D.start;var B=0;var A=(D.end-D.start)/(D.step-2);var E=setInterval(function(){D.func(C);if(B++==D.step){clearInterval(E);if(D.finalize){D.finalize()}}if(B==D.step){C=D.end}else{if(B<3){C=D.start+(A*2/14*((B-1)*5+3))}else{if(B>D.step-3){C=D.end-(A*2/14*((D.step-1-B)*5+3))}else{C=D.start+(A*(B-1))}}}},30)};Bredima.style={};Bredima.style.str="";Bredima.style.add=function(){for(var B=0;B0){this.records[this.ptr].chop(this.p2);this.ptr++}this.records[this.ptr++]=A;if(this.ptr>=Bredima.History.maxLength){this.records.shift();this.ptr--}this.length=this.ptr;this.p2=0;this.ackRecordArise()};Bredima.History.prototype.ackRecordArise=function(){this._turn("undo",true);this._turn("redo",false);this.observer.notify("HistoryChange")};Bredima.History.prototype.undo=function(){if(this.p2==0){if(this.ptr==0){return false}this.p2=this.records[--this.ptr].getLength()-1}this.records[this.ptr].revert(--this.p2);this._turn("redo",true);if((this.p2==0)&&(this.ptr==0)){this._turn("undo",false)}this.observer.notify("HistoryChange");return true};Bredima.History.prototype.redo=function(){if(this.ptr==this.length){return false}this.records[this.ptr].revert(++this.p2);this._turn("undo",true);if(this.p2==this.records[this.ptr].getLength()-1){this.ptr++;this.p2=0;if(this.ptr==this.length){this._turn("redo",false)}}this.observer.notify("HistoryChange");return true};Bredima.History.prototype._turn=function(B,A){if(this.isEnable[B]!=A){this.observer.notify("HistoryEnableChange",(A?"enable":"disable")+"_"+B);this.isEnable[B]=A}};Bredima.History.RowRecord=function(A){this.row=A;this.records=new Array};Bredima.History.RowRecord.prototype.isInput=function(){return false};Bredima.History.RowRecord.prototype.commit=function(A){var B=this.row.container.exp.getCurrent();this.records.push({rundown:this.row.toRundown(),position:new Bredima.History.TreePosition(B),selection:((A=="selected")?"":B.getSelection())});return true};Bredima.History.RowRecord.prototype.close=function(){this.position=new Bredima.History.TreePosition(this.row);this.row="";return true};Bredima.History.RowRecord.prototype.revert=function(A){var C=this.position.trace();var B=this.records[A];C.initFromRundown(B.rundown);C.repositionAll();B.position.trace().selectRange(B.selection)};Bredima.History.RowRecord.prototype.getLength=function(){return this.records.length};Bredima.History.InputRecord=function(A){this.input=A;this.records=new Array;this.cache();this.records.push({value:this.value,selection:this.selection});this.isTemporary=false;this.isCached=false};Bredima.History.InputRecord.prototype.isInput=function(){return true};Bredima.History.InputRecord.prototype.cache=function(){if(!this.isCached){this.isCached=true;this.value=this.input.toString();this.selection=this.input.getSelection()}};Bredima.History.InputRecord.prototype.commit=function(A){this.isCached=false;var B=(A=="noselection")?this.selection:this.input.getSelection();if(this.value!=this.input.toString()){if((A=="temporary")&&(this.isTemporary)){this.records.pop()}this.records.push({value:this.input.toString(),selection:B});this.isTemporary=(A=="temporary");return true}else{if(!this.selection.equals(B)){this.isTemporary=false}}return false};Bredima.History.InputRecord.prototype.close=function(){this.position=new Bredima.History.TreePosition(this.input);this.input="";return((this.records.length>1)&&!((this.records.length==2)&&(this.records[0].value==this.records[1].value)))};Bredima.History.InputRecord.prototype.revert=function(A){var B=this.position.trace();B.init(this.records[A])};Bredima.History.InputRecord.prototype.chop=function(A){this.records.splice(A+1,this.records.length)};Bredima.History.InputRecord.prototype.getLength=function(){return this.records.length};Bredima.History.TreePosition=function(A){this.tree=new Array;if(A.constructor.classID=="row"){this.tree.push(A.getOrder());A=A.container}while(A.constructor.classID!="exproot"){this.tree.push(A.getOrder());this.tree.push(A.row.getOrder());A=A.row.container}this.root=A};Bredima.History.TreePosition.prototype.trace=function(){var A=this.root;var B;for(B=this.tree.length-1;B>0;B-=2){A=A.getRow(this.tree[B]);A=A.getRowfactor(this.tree[B-1])}if(B==0){A=A.getRow(this.tree[B])}return A};Bredima.Menu=function(D){this.bredima=D;var F;var A;this.menus={};var B=this;for(var C=0;C=0){if(!this.isProcessing){this._endRec();this.startRowRec()}B.row.remove(B.row.getRowfactor(A));if(A>0){B.mergeWithPrevInput()}}}};Bredima.ExpCtrl._ctrlCharHandler[Bredima.consts.keys.left]={addCnd:function(A){return(!A.shiftKey)},position:"head",func:function(A){this.slideCursorFrom(A,"back")}};Bredima.ExpCtrl._ctrlCharHandler[Bredima.consts.keys.right]={addCnd:function(A){return((A.which==undefined)||(A.charCode!=undefined)||((A.type=="keypress")&&(A.which!=Bredima.consts.keys.right)))},position:"tail",func:function(A){this.slideCursorFrom(A,"fwd")}};Bredima.ExpCtrl._ctrlCharHandler[Bredima.consts.keys.up]={addCnd:function(A){return(!A.shiftKey)},position:"",func:function(A){this.liftCursorFrom(A,"up")}};Bredima.ExpCtrl._ctrlCharHandler[Bredima.consts.keys.down]={addCnd:function(A){return(!A.shiftKey)},position:"",func:function(A){this.liftCursorFrom(A,"down")}};Bredima.ExpCtrl.prototype.handleNormalCharacter=function(I){I=(I)?I:((window.event)?event:null);if(!I){return false}var C=(I.charCode)?I.charCode:I.keyCode;var F=Bredima.ExpCtrl._normalChar[C];if(F){Bredima.util.stopEvent(I);if(F!="noaction"){var D=Bredima.Exp.getClassById(F);if(!this.isProcessing){this._endRec();this.startRowRec()}this._insert(function(J){return new D(J)})}return true}else{var G=0;var A="";while((G=Bredima.ExpCtrl._strSuffix.indexOf(String.fromCharCode(C),G))>=0){var E=Bredima.ExpCtrl._replaceStrings[G];if(!A){A=this.current.getSelection()}var H=this.current.toString();var B=A.end-E.str.length+1;if(H.substring(B,A.end)==E.strShort){Bredima.util.stopEvent(I);this.current.init({value:H.substring(0,B)+H.substring(A.end,H.length),selection:new Bredima.Range(B,B)});this._endRec("temporary");this.startRowRec();if(E.op=="string"){this._insert(function(J){return new Bredima.Token.String(J,E.str)})}else{this._insert(function(J){return new (Bredima.Exp.getClassById(E.str))(J)})}return true}G++}}return false};Bredima.ExpCtrl._normalCharFeatures=[{code:13,make:"noaction"},{code:"(",make:"fenced"},{code:")",make:"fenced"},{code:"^",make:"sup"},{code:"_",make:"sub"}];Bredima.ExpCtrl._normalChar=new Array;(function(){for(var B=0;B=0)?this.undo:((A.indexOf("redo")>=0)?this.redo:""));if(B){B.setDisabled((A.indexOf("disable")>=0)?true:false)}};Bredima.style.add([".toolbar button","font-size: 12px; padding: 1px 2px;"]);Bredima.Frame.Toolbar.Sub=function(B){this.bredima=B;var E=new Bredima.Panel.MatrixMenu();for(var D=0;DBrEdiMa
Version "+Bredima.version+'
http://bredima.sourceforge.jp
'};Bredima.util.inherit(Bredima.Frame.About,Bredima.Panel.Dialog);Bredima.Exp=function(A){if(this.domName){this.obj=document.createElement(this.domName)}this.setClassName(["expelem"]);if(this.constructor.classID!=this.constructor.objType){this.addClassName(this.constructor.objType)}this.addClassName(this.constructor.classID)};Bredima.util.inherit(Bredima.Exp,Bredima.Parts);Bredima.util.setProperty(Bredima.Exp,{domName:"div"});Bredima.Exp.prototype.toString=function(){return JSON.stringify(this.toRundown)};Bredima.Exp.prototype.toRundown=function(){return new Array().concat(this.constructor.classID,this._toRundownContent())};Bredima.Exp.prototype._toRundownContent=function(){return this.toString()};Bredima.Exp.prototype.toMML=function(A,B){if(this.MML){return Bredima.util.addTag(this.MML,this._toMMLContent(A,B))}};Bredima.Exp.prototype._toMMLContent=function(){return this.toString()};Bredima.Exp.prototype.toLatex=function(){if(this.tex){return"\\"+this.tex+this._toLatexContent()}};Bredima.Exp.prototype._toLatexContent=function(){Bredima.util.error()};Bredima.Exp.prototype.repositionAll=function(){this._reposition()};Bredima.Exp.prototype.repositionToRoot=function(){Bredima.util.error()};Bredima.Exp.prototype._reposition=function(){};Bredima.Exp.prototype._resize=function(){if(this.top!=null){this.height=this.top+this.bottom}Bredima.util.setSize(this.obj,this.width,this.height)};Bredima.Exp.classes=new Array;Bredima.Exp.register=function(B,A,C){B.classID=(C)?C:A;B.objType=A;Bredima.Exp.classes.push(B)};Bredima.Exp.getClassById=function(B){for(var A=0;A\n";return A};Bredima.Exp.Root.prototype.toLatex=function(){return this.row.toLatex("noFence")};Bredima.Exp.Root.prototype.repositionAll=function(){this.row.repositionAll()};Bredima.Exp.Root.prototype.repositionToRoot=function(){};Bredima.Exp.Root.prototype.orderOf=function(){return 0};Bredima.Exp.Root.prototype.getRow=function(){return this.row};Bredima.Exp.Root.prototype.setCursorTo=function(A){this.row.setCursorToRow(A)};Bredima.style.add([".exproot","position: relative;"]);Bredima.Exp.Row=function(A){this.container=A.parent;this.level=A.level;this.__super__(A);this.rowfactors=new Array;if(A.rundown){this.initFromRundown(A.rundown)}else{this.add(new Bredima.Token.Input({parent:this,value:A.value}))}};Bredima.util.inherit(Bredima.Exp.Row,Bredima.Exp);Bredima.util.setProperty(Bredima.Exp.Row,{MML:"mrow",margin:2});Bredima.Exp.register(Bredima.Exp.Row,"row");Bredima.Exp.Row.prototype.initFromRundown=function(E){var C,A;for(var B=this.rowfactors.length-1;B>=0;B--){this.remove(this.rowfactors[B])}for(var B=0;B0)?this.row.getRowfactor(B-1):"";if(C&&(C.constructor.classID=="input")){var A=C.toString();this.obj.value=A+this;this.row.remove(C);this._setCursor(A.length);return C}};Bredima.Token.Input.prototype.selectRange=function(B){if(this.obj.setSelectionRange){this.obj.focus();this.obj.setSelectionRange(B.start,B.end)}else{var A=this.obj.createTextRange();A.moveStart("character",B.start);A.moveEnd("character",B.end-this.obj.value.length);A.select()}};Bredima.Token.Input.prototype.selectAll=function(){this.selectRange({start:0,end:this.obj.value.length})};Bredima.Token.Input.prototype._setCursor=function(A){this.selectRange({start:A,end:A})};Bredima.Token.Input.prototype.setCursorTo=function(A){this._setCursor((A=="head")?0:this.obj.value.length);return true};Bredima.Token.Input.prototype.getIncomingInput=function(){return this};Bredima.Token.Input.prototype.toString=function(){return this.obj.value};Bredima.Token.Input.prototype.toRundown=function(){return this.obj.value};Bredima.Token.Input.prototype.toMML=function(A){return(this.obj.value=="")?"":Bredima.util.addTag("mi",this.obj.value)};Bredima.Token.Input.prototype.toLatex=function(){return this.obj.value};Bredima.Token.Input.prototype._reposition=function(){var B=this.getOrder();var A=((this.row.container.exp.getCurrent()===this)||(this.obj.value.length>0)||(this.row.getLength()==1)||((B==1)&&(this.row.getLength()>B)&&(this.row.getRowfactor(B+1).isNeedPrev)));if(A){this.removeClassNameSuffix();this.width=Math.floor((this.obj.value.length+2)*Bredima.Token.width[this.row.level]);this._resizeWidth()}else{this.width=4;this.obj.style.width="";this.setClassNameSuffix("hidden")}};Bredima.style.add([".input","border: 1px solid gray; margin: 0; text-align: left; overflow: hidden; resize: none;"],["textarea.hidden","border-color: #ddd; background-color: #ddd; width: 4px !important;"],["textarea.hidden:hover","border-color: gray;"]);Bredima.Container=function(C){arguments.callee.superClass.apply(this,arguments);this.exp=this.row.container.exp;this.parts={};if(C.rundown&&(C.rundown.length>this.rowCount)){this.config=C.rundown.splice(0,(C.rundown.length-this.rowCount))}this.rows=new Array;var B={};for(var A=0;A0))?this.rowLevels[A]:this.row.getLevel()};this.rows.push(new Bredima.Exp.Row(B));this.obj.appendChild(this.rows[A].getDom())}this.content=this.rows[this.primaryRow]};Bredima.util.inherit(Bredima.Container,Bredima.Exp.Rowfactor);Bredima.util.setProperty(Bredima.Container,{rowCount:1,padding:{top:0,right:0,bottom:0,left:0},primaryRow:0});Bredima.Container.prototype.getLength=function(){return this.rows.length};Bredima.Container.prototype.getRow=function(A){return this.rows[A]};Bredima.Container.prototype.orderOf=function(B){for(var A=0;A"}return B+this.content.toMML(A)};Bredima.Container.Sup.prototype.toLatex=function(){return"^"+this.content.toLatex()};Bredima.Container.Sup.prototype._repositionContent=function(A){this.top=A.height;this.bottom=0;this.width=A.width;this._resize()};Bredima.Container.Sub=function(A){this.__super__(A);this.content.setPos(0,0)};Bredima.util.inherit(Bredima.Container.Sub,Bredima.Container);Bredima.util.setProperty(Bredima.Container.Sub,{MML:"msub",isMMLNeedPrev:true,rowLevels:[2]});Bredima.Exp.register(Bredima.Container.Sub,"container","sub");Bredima.Container.Sub.prototype._toMMLContent=function(A,B){if(B==""){B=""}return B+this.content.toMML(A)};Bredima.Container.Sub.prototype.toLatex=function(){return"_"+this.content.toLatex()};Bredima.Container.Sub.prototype._repositionContent=function(A){this.top=0;this.bottom=A.height;this.width=A.width;this._resize()};Bredima.Container.Over=function(A){this.__super__(A);this.add("line",new Bredima.Parts.Separator());this.parts.line.setPos(2,2)};Bredima.util.inherit(Bredima.Container.Over,Bredima.Container);Bredima.util.setProperty(Bredima.Container.Over,{MML:"mover",tex:"overline",padding:{top:4,right:0,bottom:0,left:0}});Bredima.Exp.register(Bredima.Container.Over,"container","over");Bredima.Container.Over.prototype._toMMLContent=function(A){return this.content.toMML(A)+Bredima.util.addTag("mo",(A)?Bredima.Parts.Symbol.all.OverBar.code:"‾")};Bredima.Container.Over.prototype._repositionContent=function(){Bredima.util.applySuper("_repositionContent",this,arguments);this.parts.line.setSize(this.width-4,1)};Bredima.Container.Vector=function(A){this.__super__(A);this.add("head",new Bredima.Parts.Image("arrowhead.png"));this.add("shaft",new Bredima.Parts.Image("arrowshaft.png"));this.parts.shaft.setPos(2,2)};Bredima.util.inherit(Bredima.Container.Vector,Bredima.Container);Bredima.util.setProperty(Bredima.Container.Vector,{MML:"mover",tex:"vec",padding:{top:10,right:0,bottom:0,left:0}});Bredima.Exp.register(Bredima.Container.Vector,"container","vector");Bredima.Container.Vector.prototype._toMMLContent=function(A){return this.content.toMML(A)+Bredima.util.addTag("mo",(A)?Bredima.Parts.Symbol.all.rarr.code:"→")};Bredima.Container.Vector.prototype._repositionContent=function(){Bredima.util.applySuper("_repositionContent",this,arguments);this.parts.shaft.setSize(this.width-14,9);this.parts.head.setPos(this.width-12,2)};Bredima.Container.Permutation=function(B,A){this.__super__(B);this.kind=(this.config)?this.config:A;this.add("symbol",new Bredima.Parts.String(this.values[this.kind],1));this.add("menu",new Bredima.Parts.Popup(this.exp.bredima,"permutation",this))};Bredima.util.inherit(Bredima.Container.Permutation,Bredima.Container);Bredima.util.setProperty(Bredima.Container.Permutation,{MML:"mmultiscripts",rowCount:2,rowLevels:[2,2]});Bredima.Exp.register(Bredima.Container.Permutation,"container","permutation");Bredima.Container.Permutation.prototype.values=["P","C","H"];Bredima.Container.Permutation.prototype._toRundownContentParam=function(){return this.kind};Bredima.Container.Permutation.prototype._toMMLContent=function(A){return Bredima.util.addTag("mi",this.values[this.kind])+this.rows[1].toMML(A)+"\n\n"+this.rows[0].toMML(A)+"\n"};Bredima.Container.Permutation.prototype.toLatex=function(){return"{{}_"+this.rows[0].toLatex()+this.values[this.kind]+"_"+this.rows[1].toLatex()+"}"};Bredima.Container.Permutation.prototype._repositionContent=function(B){var A=this.parts.symbol.getPreferredSize();this.width=A.width+B[0].width+B[1].width+8;this.top=A.top;this.bottom=Math.max(B[0].height,B[1].height,A.bottom);this._resize();this.parts.symbol.setPos(B[0].width,0);this.parts.menu.setPos(this.width-8,this.height-8);this.rows[0].setPos(0,A.top);this.rows[1].setPos(B[0].width+A.width,A.top)};Bredima.Container.Permutation.prototype.menuClickPerformed=function(A){if(this.kind!=A){this.exp.startRowRec(this.row);this.kind=A;this.parts.symbol.setString(this.values[this.kind]);this.exp.endRowRec()}};Bredima.Container.Sum=function(A){this.__super__(A);this.add("symbol",new Bredima.Parts.Symbol(this.exp.bredima,"sum",this.row.level))};Bredima.util.inherit(Bredima.Container.Sum,Bredima.Container);Bredima.util.setProperty(Bredima.Container.Sum,{MML:"munderover",rowCount:2,rowLevels:[2,2],verticalOrder:[1,0]});Bredima.Exp.register(Bredima.Container.Sum,"container","sum");Bredima.Container.Sum.prototype._toMMLContent=function(A){return Bredima.util.addTag("mo",this.parts.symbol.toMML(A))+Bredima.util.applySuper("_toMMLContent",this)};Bredima.Container.Sum.prototype.toLatex=function(){return this.parts.symbol.toLatex()+"_"+this.rows[0].toLatex()+"^"+this.rows[1].toLatex()};Bredima.Container.Sum.prototype._repositionContent=function(B){var A=this.parts.symbol.getPreferredSize();this.width=Math.max((A.width+4),B[0].width,B[1].width);this.top=A.top+B[1].height;this.bottom=A.bottom+B[0].height;this._resize();this.parts.symbol.setPos((this.width-A.width)/2,B[1].height);this.rows[1].setPos((this.width-B[1].width)/2,0);this.rows[0].setPos((this.width-B[0].width)/2,B[1].height+A.height)};Bredima.Container.Integral=function(A){this.__super__(A);this.add("symbol",new Bredima.Parts.Symbol(this.exp.bredima,"mathint",this.row.level))};Bredima.util.inherit(Bredima.Container.Integral,Bredima.Container);Bredima.util.setProperty(Bredima.Container.Integral,{MML:"msubsup",rowCount:2,rowLevels:[2,2],verticalOrder:[1,0]});Bredima.Exp.register(Bredima.Container.Integral,"container","integral");Bredima.Container.Integral.prototype._toMMLContent=function(A){return Bredima.util.addTag("mo",this.parts.symbol.toMML(A))+Bredima.util.applySuper("_toMMLContent",this)};Bredima.Container.Integral.prototype.toLatex=function(){return this.parts.symbol.toLatex()+"_"+this.rows[0].toLatex()+"^"+this.rows[1].toLatex()};Bredima.Container.Integral.prototype._repositionContent=function(C){var B=this.parts.symbol.getPreferredSize();var A=(C[1].bottom+C[0].top)/2;this.width=B.width+Math.max(C[0].width,C[1].width)+2;this.top=C[1].top+Math.ceil(A);this.bottom=C[0].bottom+Math.floor(A);this._resize();this.parts.symbol.setPos(2,this.top-B.top);this.rows[1].setPos(B.width+2,0);this.rows[0].setPos(B.width+2,this.height-C[0].height)};Bredima.Container.IntInterval=function(A){this.__super__(A);this.add("open",new Bredima.Parts.Image("bracket_open.png"));this.add("close",new Bredima.Parts.Image("bracket_close.png"))};Bredima.util.inherit(Bredima.Container.IntInterval,Bredima.Container);Bredima.util.setProperty(Bredima.Container.IntInterval,{MML:"msubsup",rowCount:3,rowLevels:[0,2,2],verticalOrder:[2,1]});Bredima.Exp.register(Bredima.Container.IntInterval,"container","intinterval");Bredima.Container.IntInterval.prototype.liftCursorFrom=function(B,C){var A=this.orderOf(B.row);if(((A==1)&&(C=="up"))||((A==2)&&(C=="down"))){return Bredima.util.applySuper("liftCursorFrom",this,arguments)}return false};Bredima.Container.IntInterval.prototype._toMMLContent=function(A){return Bredima.util.addTag("mfenced",this.content.toMML(A),'open="[" close="]"')+Bredima.util.applySuper("_toMMLContent",this)};Bredima.Container.IntInterval.prototype.toLatex=function(){return"\\left["+this.content.toLatex("nofence")+"\\right]_"+this.rows[1].toLatex()+"^"+this.rows[2].toLatex()};Bredima.Container.IntInterval.prototype._repositionContent=function(C){var A=(C[2].bottom+C[1].top)/2;var B=Math.max(C[2].top+Math.ceil(A)-C[0].top,0);this.width=C[0].width+Math.max(C[1].width,C[2].width)+22;this.top=B+C[0].top;this.bottom=Math.max(C[0].bottom,C[1].bottom+Math.floor(A));this._resize();this.parts.open.setSize(10,C[0].height);this.parts.open.setPos(2,B);this.parts.close.setSize(10,C[0].height);this.parts.close.setPos(C[0].width+12,B);this.content.setPos(12,B);this.rows[2].setPos(C[0].width+22,0);this.rows[1].setPos(C[0].width+22,this.height-C[1].height)};Bredima.Container.Limit=function(A){this.__super__(A);this.add("string",new Bredima.Parts.String("lim",this.row.getLevel()))};Bredima.util.inherit(Bredima.Container.Limit,Bredima.Container);Bredima.util.setProperty(Bredima.Container.Limit,{MML:"munder",tex:"lim_",rowLevels:[2]});Bredima.Exp.register(Bredima.Container.Limit,"container","lim");Bredima.Container.Limit.prototype._toMMLContent=function(A){return Bredima.util.addTag("mi","lim")+this.content.toMML(A)};Bredima.Container.Limit.prototype._repositionContent=function(B){var A=this.parts.string.getPreferredSize();this.width=Math.max(A.width,B.width);this.top=A.top;this.bottom=A.bottom+B.height;this._resize();this.parts.string.setPos((this.width-A.width)/2,0);this.content.setPos((this.width-B.width)/2,A.height)};Bredima.style.addStylesheet()
window.addEventListener(
'load',
function() {
if(!document.getElementById('edit-buttons')) return;
var button = document.createElement('img');
button.src = 'http://bredima.sourceforge.jp/pub/img/gm_hatena.png';
button.style.marginRight = '5px';
document.getElementById('edit-buttons').appendChild(button);
Bredima.setConfig('uri_mimetex', '/cgi-bin/mimetex.cgi');
Bredima.setConfig('uri_img', 'http://bredima.sourceforge.jp/pub/img/');
Bredima.setConfig('isGM', true);
var bd = new Bredima(button, 'float');
bd.setConfig('use_button', true);
bd.onSubmit = function() {
var form = document.forms.namedItem('edit');
var area = form.elements.namedItem('body');
Bredima.insertTo(area, '[tex:' + bd.toLatex() + ']');
}
},
false);