editor-base-min.js revision 5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887
943N/AYUI.add("editor-base",function(B){var A=function(){A.superclass.constructor.apply(this,arguments);};B.extend(A,B.Base,{frame:null,initializer:function(){var C=new B.Frame({designMode:true,title:A.STRINGS.title,use:A.USE,dir:this.get("dir"),extracss:this.get("extracss")}).plug(B.Plugin.ExecCommand);C.after("ready",B.bind(this._afterFrameReady,this));C.addTarget(this);this.frame=C;this.publish("nodeChange",{emitFacade:true,bubbles:true,defaultFn:this._defNodeChangeFn});},_defNodeChangeFn:function(I){switch(I.changedType){case"enter":break;case"tab":if(!I.changedNode.test("li, li *")&&!I.changedEvent.shiftKey){this.execCommand("inserthtml"," ");I.changedEvent.halt();}break;}var J=this.getDomPath(I.changedNode),E={},G,D,F=[],H="",C="";if(I.commands){E=I.commands;}J.each(function(R){var L=R.get("tagName").toLowerCase(),Q=A.TAG2CMD[L],P=B.Node.getDOMNode(R);if(Q){E[Q]=1;}var O=P.style;if(O.fontWeight.toLowerCase()=="bold"){E.bold=1;}if(O.fontStyle.toLowerCase()=="italic"){E.italic=1;}if(O.textDecoration.toLowerCase()=="underline"){E.underline=1;}if(O.textDecoration.toLowerCase()=="line-through"){E.strikethrough=1;}var N=R.getStyle("fontFamily").split(",")[0].toLowerCase();if(N){G=N;}D=R.getStyle("fontSize");var M=R.get("className").split(" ");B.each(M,function(S){if(S!==""&&(S.substr(0,4)!=="yui_")){F.push(S);}});H=A.FILTER_RGB(R.getStyle("color"));var K=A.FILTER_RGB(R.getStyle("backgroundColor"));if(K!=="transparent"){C=K;}});I.dompath=J;I.classNames=F;I.commands=E;if(!I.fontFamily){I.fontFamily=G;}if(!I.fontSize){I.fontSize=D;}if(!I.fontColor){I.fontColor=H;}if(!I.backgroundColor){I.backgroundColor=C;}},getDomPath:function(C){var E=[],D=this.frame.getInstance();while(C!==null){if(!C.inDoc()){C=null;break;}if(C.get("nodeName")&&C.get("nodeType")&&(C.get("nodeType")==1)){E.push(D.Node.getDOMNode(C));}if(C.test("body")){C=null;break;}C=C.get("parentNode");}if(E.length===0){E[0]=D.config.doc.body;}return D.all(E.reverse());},_afterFrameReady:function(){var C=this.frame.getInstance();this.frame.on("mousedown",B.bind(this._onFrameMouseDown,this));this.frame.on("keyup",B.bind(this._onFrameKeyUp,this));this.frame.on("keydown",B.bind(this._onFrameKeyDown,this));C.Selection.filter();},_onFrameMouseDown:function(C){this.fire("nodeChange",{changedNode:C.frameTarget,changedType:"mousedown",changedEvent:C});},_onFrameKeyUp:function(E){if(A.NC_KEYS[E.keyCode]){var D=this.frame.getInstance(),C=new D.Selection();if(C.anchorNode){this.fire("nodeChange",{changedNode:C.anchorNode,changedType:"keyup",selection:C,changedEvent:E});}}},_onFrameKeyDown:function(E){if(A.NC_KEYS[E.keyCode]){var D=this.frame.getInstance(),C=new D.Selection();this.fire("nodeChange",{changedNode:C.anchorNode,changedType:A.NC_KEYS[E.keyCode],changedEvent:E});}},execCommand:function(G,I){var D=this.frame.execCommand(G,I),F=this.frame.getInstance(),E=new F.Selection(),C={},H={changedNode:E.anchorNode,changedType:"execcommand",nodes:D};switch(G){case"forecolor":H.fontColor=I;break;case"backcolor":H.backgroundColor=I;break;case"fontsize":H.fontSize=I;break;case"fontname":H.fontFamily=I;break;}C[G]=1;H.commands=C;this.fire("nodeChange",H);return D;},getInstance:function(){return this.frame.getInstance();},destructor:function(){},render:function(C){this.frame.set("content",this.get("content"));this.frame.render(C);return this;},focus:function(){this.frame.getInstance().one("win").focus();return this;},getContent:function(){var C=this.getInstance().Selection.unfilter();C=C.replace(/ _yuid="([^>]*)"/g,"");return C;}},{FILTER_RGB:function(E){if(E.toLowerCase().indexOf("rgb")!=-1){var H=new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)","gi");var D=E.replace(H,"$1,$2,$3,$4,$5").split(",");if(D.length==5){var G=parseInt(D[1],10).toString(16);var F=parseInt(D[2],10).toString(16);var C=parseInt(D[3],10).toString(16);G=G.length==1?"0"+G:G;F=F.length==1?"0"+F:F;C=C.length==1?"0"+C:C;E="#"+G+F+C;}}return E;},TAG2CMD:{"b":"bold","strong":"bold","i":"italic","em":"italic","u":"underline","sup":"superscript","sub":"subscript","img":"insertimage","a":"createlink","ul":"insertunorderedlist","ol":"insertorderedlist"},NC_KEYS:{8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",46:"delete"},USE:["substitute","node","selector-css3","selection","stylesheet"],NAME:"editorBase",STRINGS:{title:"Rich Text Editor"},ATTRS:{content:{value:"<br>",setter:function(C){if(C.substr(0,1)==="\n"){C=C.substr(1);}return this.frame.set("content",C);},getter:function(){return this.frame.get("content");}},dir:{writeOnce:true,value:"ltr"},extracss:{value:false,setter:function(C){if(this.frame){this.frame.set("extracss",C);}return C;}}}});B.EditorBase=A;},"@VERSION@",{requires:["base","frame","node","exec-command"],skinnable:false});