if(!Webadmin){
var Webadmin={};
}
Webadmin.RichTextEditorForm=Class.create();
Webadmin.RichTextEditorForm.prototype={initialize:function(_1,_2){
this.options=Object.extend({bold:true,italic:true,link:true,width:"400px",height:"100px"},_2||{});
this.element=$(_1);
this.editors=Array();
var _3=this.element.getElementsByTagName("textarea");
$A(_3).each(function(_4){
if((this.options.only&&Element.hasClassName($(_4),this.options.only))||!this.options.only){
this.editors[this.editors.length]=new Webadmin.RichTextEditor($(_4),this.options);
}
}.bind(this));
this.addListeners();
},addListeners:function(){
Event.observe(this.element,"submit",this.save.bindAsEventListener(this));
},save:function(){
$A(this.editors).each(function(_5){
_5.save();
});
},clear:function(){
$A(this.editors).each(function(_6){
_6.clear();
});
}};
Webadmin.RichTextEditor=Class.create();
Webadmin.RichTextEditor.prototype={initialize:function(_7,_8){
this.options=Object.extend({bold:true,italic:true,link:true,unlink:true,width:"400px",height:"100px"},_8||{});
this.element=$(_7);
this.parent=this.element.parentNode;
this.HTML=this.element.innerHTML;
this.iframe=document.createElement("iframe");
this.iframe.className="w-iframe";
this.iframe.id=this.element.id+"_rte";
this.iframe.style.width=this.options.width;
this.iframe.style.height=this.options.height;
this.rte=document.createElement("div");
this.rte.className="w-rte";
var _9=document.createElement("div");
this.controls();
this.rte.appendChild(this.controlstrip);
this.rte.appendChild(_9);
_9.appendChild(this.iframe);
this.parent.insertBefore(this.rte,this.element.nextSibling);
this.element.style.display="none";
this.setup();
},setup:function(){
this.HTML=this.HTML.replace(/&gt;/g,">");
this.HTML=this.HTML.replace(/&lt;/g,"<");
if(this.iframe.document){
var _a=document.frames.length-1;
document.frames[_a].document.designMode="On";
document.frames[_a].document.open();
document.frames[_a].document.write(this.HTML);
document.frames[_a].document.close();
this.doc=document.frames[_a].document;
this.doc.body.style.border="1px solid #A7A6AA";
}else{
this.doc=this.iframe.contentDocument;
this.doc.open();
this.doc.write(this.HTML);
this.doc.close();
this.doc.body.style.cursor="text";
this.doc.body.style.height="100%";
this.iframe.style.border="1px solid #ccc";
this.iframe.height-=2;
this.iframe.width-=2;
}
this.doc.body.style.margin="0px";
this.doc.designMode="On";
this.doc.body.style.padding="0px";
if(!document.all){
this.doc.execCommand("styleWithCSS",false,false);
}
this.addListeners();
},addListeners:function(){
if(this.options.bold==true){
Event.observe(this.boldButton,"click",this.bold.bindAsEventListener(this));
}
if(this.options.italic==true){
Event.observe(this.italicButton,"click",this.italic.bindAsEventListener(this));
}
if(this.options.link==true){
Event.observe(this.linkButton,"click",this.link.bindAsEventListener(this));
}
if(this.options.ul==true){
Event.observe(this.ulButton,"click",this.ul.bindAsEventListener(this));
}
if(this.options.ol==true){
Event.observe(this.olButton,"click",this.ol.bindAsEventListener(this));
}
if(this.options.strike==true){
Event.observe(this.strikeButton,"click",this.strike.bindAsEventListener(this));
}
if(this.options.superscript==true){
Event.observe(this.superscriptButton,"click",this.superscript.bindAsEventListener(this));
}
if(this.options.subscript==true){
Event.observe(this.subscriptButton,"click",this.subscript.bindAsEventListener(this));
}
if(this.options.underline==true){
Event.observe(this.underlineButton,"click",this.underline.bindAsEventListener(this));
}
if(this.options.unlink==true){
Event.observe(this.unlinkButton,"click",this.unlink.bindAsEventListener(this));
}
},removeListeners:function(){
},button:function(_b){
var _c=document.createElement("a");
_c.id=_b.id;
_c.className="w-controlbutton";
_c.href="#";
_c.title=_b.title;
var _d=document.createTextNode(_b.value);
_c.appendChild(_d);
return _c;
},controls:function(){
this.controlstrip=document.createElement("div");
this.controlstrip.className="w-controlstrip";
if(this.options.bold==true){
this.boldButton=this.button({id:"bold",title:"Bold",value:"B"});
this.controlstrip.appendChild(this.boldButton);
}
if(this.options.italic==true){
this.italicButton=this.button({id:"italic",title:"Italic",value:"I"});
this.controlstrip.appendChild(this.italicButton);
}
if(this.options.underline==true){
this.underlineButton=this.button({id:"underline",title:"Underlinke",value:"Underline"});
this.controlstrip.appendChild(this.underlineButton);
}
if(this.options.strike==true){
this.strikeButton=this.button({id:"strikethrough",title:"Strike",value:"Strike"});
this.controlstrip.appendChild(this.strikeButton);
}
if(this.options.link==true){
this.linkButton=this.button({id:"link",title:"Insert link",value:"A"});
this.controlstrip.appendChild(this.linkButton);
}
if(this.options.unlink==true){
this.unlinkButton=this.button({id:"unlink",title:"Unlink",value:"Unlink"});
this.controlstrip.appendChild(this.unlinkButton);
}
if(this.options.ul==true){
this.ulButton=this.button({id:"insertunorderedlist",title:"Insert Unordered List",value:"UL"});
this.controlstrip.appendChild(this.ulButton);
}
if(this.options.ol==true){
this.olButton=this.button({id:"insertorderedlist",title:"Insert Ordered List",value:"OL"});
this.controlstrip.appendChild(this.olButton);
}
if(this.options.subscript==true){
this.subscriptButton=this.button({id:"subscript",title:"Subscript",value:"Subscript"});
this.controlstrip.appendChild(this.subscriptButton);
}
if(this.options.superscript==true){
this.superscriptButton=this.button({id:"superscript",title:"Superscript",value:"Superscript"});
this.controlstrip.appendChild(this.superscriptButton);
}
},command:function(_e,_f){
this.doc.execCommand(_e,false,_f);
},bold:function(ev){
Event.stop(ev);
this.command("bold",null);
},italic:function(ev){
Event.stop(ev);
this.command("italic",null);
},ol:function(ev){
Event.stop(ev);
this.command("insertorderedlist",null);
},ul:function(ev){
Event.stop(ev);
this.command("insertunorderedlist",null);
},strike:function(ev){
Event.stop(ev);
this.command("strikethrough",null);
},subscript:function(ev){
Event.stop(ev);
this.command("subscript",null);
},superscript:function(ev){
Event.stop(ev);
this.command("superscript",null);
},underline:function(ev){
Event.stop(ev);
this.command("underline",null);
},unlink:function(ev){
Event.stop(ev);
this.command("unlink",null);
},link:function(ev){
Event.stop(ev);
var _1a=prompt("Please enter a URL:","");
if(_1a!=null&&_1a!=""){
this.command("createLink",_1a);
}else{
return false;
}
},save:function(){
var _1b=this.clean_html(this.doc.body.innerHTML);
_1b=_1b.replace("&nbsp;","");
this.element.value=_1b;
if(this.options.callback){
this.options.callback(_1b);
}
},clear:function(){
this.doc.body.innerHTML="&nbsp";
},clean_html:function(_1c){
var _1d=/(<[^>\s]*)(\w)/gi;
var _1e=_1c.match(_1d);
if(_1e){
for(i=0;i<_1e.length;i++){
_1c=_1c.replace(_1e[i],_1e[i].toLowerCase());
}
}
var _1d=/([^>\s]*)(\w=)/gi;
var _1e=_1c.match(_1d);
if(_1e){
for(i=0;i<_1e.length;i++){
_1c=_1c.replace(_1e[i],_1e[i].toLowerCase());
}
}
_1c=_1c.replace(/<o:p>\s*<\/o:p>/g,"");
_1c=_1c.replace(/<o:p>.*?<\/o:p>/g,"&nbsp;");
_1c=_1c.replace(/\s*MARGIN: 0cm 0cm 0pt\s*;/gi,"");
_1c=_1c.replace(/\s*MARGIN: 0cm 0cm 0pt\s*"/gi,"\"");
_1c=_1c.replace(/\s*TEXT-INDENT: 0cm\s*;/gi,"");
_1c=_1c.replace(/\s*TEXT-INDENT: 0cm\s*"/gi,"\"");
_1c=_1c.replace(/\s*TEXT-ALIGN: [^\s;]+;?"/gi,"\"");
_1c=_1c.replace(/\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi,"\"");
_1c=_1c.replace(/\s*FONT-VARIANT: [^\s;]+;?"/gi,"\"");
_1c=_1c.replace(/\s*tab-stops:[^;"]*;?/gi,"");
_1c=_1c.replace(/\s*tab-stops:[^"]*/gi,"");
_1c=_1c.replace(/\s*face="[^"]*"/gi,"");
_1c=_1c.replace(/\s*face=[^ >]*/gi,"");
_1c=_1c.replace(/\s*FONT-FAMILY:[^;"]*;?/gi,"");
_1c=_1c.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi,"<$1$3");
_1c=_1c.replace(/<(\w[^>]*) style="([^\"]*)"([^>]*)/gi,"<$1$3");
_1c=_1c.replace(/\s*style="\s*"/gi,"");
_1c=_1c.replace(/<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi,"&nbsp;");
_1c=_1c.replace(/<SPAN\s*[^>]*><\/SPAN>/gi,"");
_1c=_1c.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi,"<$1$3");
_1c=_1c.replace(/<SPAN\s*>(.*?)<\/SPAN>/gi,"$1");
_1c=_1c.replace(/<FONT\s*>(.*?)<\/FONT>/gi,"$1");
_1c=_1c.replace(/<\\?\?xml[^>]*>/gi,"");
_1c=_1c.replace(/<\/?\w+:[^>]*>/gi,"");
return _1c;
}};

