// $Id: htmlarea.js,v 1.2 2006/02/21 04:51:14 timax Exp $
//
// htmlArea v3.0 - Copyright (c) 2002-2004 interactivetools.com, inc.
// This copyright notice MUST stay intact for use (see license.txt).
//
// Portions (c) dynarch.com, 2003-2004
//
// A free WYSIWYG editor replacement for <textarea> fields.
// For full source code and docs, visit http://www.interactivetools.com/
//
// Version 3.0 (CVS 2004/09/08) developed by Mihai Bazon.
//   http://dynarch.com/mishoo
// -----------------------------------------------------------
// Note: This is not only the original HTMLArea file from CVS
//       It is an expanded version for RTEMulti and MD-Pro
//
// Many thanks to http://www.Xinha.org for ideas and code snippets
// Last changes: PeteBest, 29/10/05
//

if(typeof _editor_url=="string"){
_editor_url=_editor_url.replace(/\x2f*$/,'/');
}else{
_editor_url=QBPATH+"/";
if(_editor_url&&_editor_url.match(/^(https?:\/\/[^\/]+)(.*)$/)){
_full_url=_editor_url;
}else{
_full_url=ROOTPATH+"/"+_editor_url;
}
}
if(typeof _editor_lang=="string"){
_editor_lang=_editor_lang.toLowerCase();
}else{
_editor_lang=LANG;
}
HTMLArea.agt=navigator.userAgent.toLowerCase();
HTMLArea.is_ie=((HTMLArea.agt.indexOf("msie")!=-1)&&(HTMLArea.agt.indexOf("opera")==-1));
HTMLArea.is_opera=(HTMLArea.agt.indexOf("opera")!=-1);
HTMLArea.is_mac=(HTMLArea.agt.indexOf("mac")!=-1);
HTMLArea.is_mac_ie=(HTMLArea.is_ie&&HTMLArea.is_mac);
HTMLArea.is_win_ie=(HTMLArea.is_ie&&!HTMLArea.is_mac);
HTMLArea.is_gecko=(navigator.product=="Gecko");
function HTMLArea(textarea,config){
if(HTMLArea.checkSupportedBrowser()){
if(typeof config=="undefined"){
this.config=new HTMLArea.Config();
}else{
this.config=config;
}
this._htmlArea=null;
this._textArea=textarea;
this._editMode="wysiwyg";
this.plugins={};
this._timerToolbar=null;
this._timerUndo=null;
this._undoQueue=new Array();
this._undoPos=-1;
this._customUndo=true;
this._mdoc=document;
this.doctype='';
}
};
HTMLArea.loadScript=function(url,plugin){
if(plugin)
url=HTMLArea.getPluginDir(plugin)+'/'+url;
this._scripts.push(url);
};
(function(){
var scripts=HTMLArea._scripts=[_editor_url+"htmlarea.js",
_editor_url+"dialog.js",
_editor_url+"popupwin.js",
_editor_url+"lang/"+_editor_lang+".js"];
var head=document.getElementsByTagName("head")[0];
for(var i=1;i<scripts.length;++i){
var script=document.createElement("script");
script.src=scripts[i];
head.appendChild(script);
}
})();
HTMLArea.RE_tagName=/(<\/|<)\s*([^ \t\n>]+)/ig;
HTMLArea.RE_doctype=/(<!doctype((.|\n)*?)>)\n?/i;
HTMLArea.RE_head=/<head>((.|\n)*?)<\/head>/i;
HTMLArea.RE_body=/<body[^>]*>((.|\n)*?)<\/body>/i;
HTMLArea.RE_Specials=/([\/\^$*+?.()|{}[\]])/g;
HTMLArea.RE_email=/[a-z0-9_]{3,}@[a-z0-9_-]{2,}(\.[a-z0-9_-]{2,})+/i;
HTMLArea.RE_url=/(https?:\/\/)?(([a-z0-9_]+:[a-z0-9_]+@)?[a-z0-9_-]{2,}(\.[a-z0-9_-]{2,}){2,}(:[0-9]+)?(\/\S+)*)/i;
HTMLArea.Config=function(){
this.version="3.0";
if(ADDWIDTH=='auto'){
this.width="auto";
}else{
this.width=ADDWIDTH+"px";
}
if(ADDHEIGHT=='auto'){
this.height="auto";
}else{
this.height=ADDHEIGHT+"px";
}
this.statusBar=true;
this.htmlareaPaste=false;
this.undoSteps=20;
this.undoTimeout=500;
this.sizeIncludesToolbar=true;
this.fullPage=false;
this.pageStyle="";
this.killWordOnPaste=true;
this.makeLinkShowsTarget=true;
this.baseURL=document.baseURI||document.URL;
if(this.baseURL&&this.baseURL.match(/(.*)\/([^\/]+)/))
this.baseURL=RegExp.$1+"/";
this.imgURL="images/";
this.popupURL="popups/";
this.popupURLml="popups/lang/"+_editor_lang+"/";
this.htmlRemoveTags=null;
this.toolbar=[
["barstart","htmlmode","separator","cut","copy","paste","separator","selectall","removeformat",
"barstart","inserttable","toggleborders","insertimage","separator","insertfile","createlink","unlink",
"barstart","showhelp","showhelp"
],
["barstart","bold","italic","underline","strikethrough","subscript","superscript",
"barstart","justifyleft","justifycenter","justifyright","justifyfull",
"barstart","righttoleft","separator","template",
"barstart","insertorderedlist","insertunorderedlist","outdent","indent","separator","inserthorizontalrule",
"barstart","undo","redo"
],
["barstart","formatblock","separator","fontname","separator","fontsize",
"barstart","forecolor","hilitecolor","separator","textindicator","separator","bgcolor","bgimage"
]
];
this.fontname={
"&mdash; font &mdash;":'',
"Arial":'arial,helvetica,sans-serif',
"Courier New":'courier new,courier,monospace',
"Georgia":'georgia,times new roman,times,serif',
"Tahoma":'tahoma,arial,helvetica,sans-serif',
"Times New Roman":'times new roman,times,serif',
"Verdana":'verdana,arial,helvetica,sans-serif',
"impact":'impact',
"WingDings":'wingdings'
};
this.fontsize={
"&mdash; Size &mdash;":"",
"1 (8 pt)":"1",
"2 (10 pt)":"2",
"3 (12 pt)":"3",
"4 (14 pt)":"4",
"5 (18 pt)":"5",
"6 (24 pt)":"6",
"7 (36 pt)":"7"
};
this.formatblock={
"&mdash; Format &mdash;":"",
"Heading 1":"h1",
"Heading 2":"h2",
"Heading 3":"h3",
"Heading 4":"h4",
"Heading 5":"h5",
"Heading 6":"h6",
"Normal":"p",
"Address":"address",
"Formatted":"pre"
};
this.customSelects={};
function cut_copy_paste(e,cmd,obj){
e.execCommand(cmd);
};
this.debug=true;
this.btnList={
bold:["Bold",["ed_buttons_main.gif",3,2],false,function(e){e.execCommand("bold");}],
italic:["Italic",["ed_buttons_main.gif",2,2],false,function(e){e.execCommand("italic");}],
underline:["Underline",["ed_buttons_main.gif",2,0],false,function(e){e.execCommand("underline");}],
strikethrough:["Strikethrough",["ed_buttons_main.gif",3,0],false,function(e){e.execCommand("strikethrough");}],
subscript:["Subscript",["ed_buttons_main.gif",3,1],false,function(e){e.execCommand("subscript");}],
superscript:["Superscript",["ed_buttons_main.gif",2,1],false,function(e){e.execCommand("superscript");}],
justifyleft:["Justify Left",["ed_buttons_main.gif",0,0],false,function(e){e.execCommand("justifyleft");}],
justifycenter:["Justify Center",["ed_buttons_main.gif",1,1],false,function(e){e.execCommand("justifycenter");}],
justifyright:["Justify Right",["ed_buttons_main.gif",1,0],false,function(e){e.execCommand("justifyright");}],
justifyfull:["Justify Full",["ed_buttons_main.gif",0,1],false,function(e){e.execCommand("justifyfull");}],
orderedlist:["Ordered List",["ed_buttons_main.gif",0,3],false,function(e){e.execCommand("insertorderedlist");}],
unorderedlist:["Bulleted List",["ed_buttons_main.gif",1,3],false,function(e){e.execCommand("insertunorderedlist");}],
outdent:["Decrease Indent",["ed_buttons_main.gif",1,2],false,function(e){e.execCommand("outdent");}],
indent:["Increase Indent",["ed_buttons_main.gif",0,2],false,function(e){e.execCommand("indent");}],
forecolor:["Font Color",["ed_buttons_main.gif",3,3],false,function(e){e.execCommand("forecolor");}],
hilitecolor:["Text Background Color",["ed_buttons_main.gif",3,4],false,function(e){e.execCommand("hilitecolor");}],
horizontal:["Horizontal Rule",["ed_buttons_main.gif",6,0],false,function(e){e.execCommand("inserthorizontalrule");}],
createlink:["Insert Web Link",["ed_buttons_main.gif",6,1],false,function(e){e._createLink();}],
insertimage:["Insert/Modify Image",["ed_buttons_main.gif",6,3],false,function(e){e.execCommand("insertimage");}],
inserttable:["Insert Table",["ed_buttons_main.gif",6,2],false,function(e){e.execCommand("inserttable");}],
htmlmode:["Toggle HTML Source",["ed_buttons_main.gif",7,0],true,function(e){e.execCommand("htmlmode");}],
toggleborders:["Toggle Borders",["ed_buttons_main.gif",7,2],false,function(e){e._toggleBorders("toggleborders");}],
about:["About this editor",["ed_buttons_main.gif",8,2],true,function(e){e.execCommand("about");}],
showhelp:["Help using editor",["ed_buttons_main.gif",9,2],true,function(e){e.execCommand("showhelp");}],
unlink:["Remove Web Link",["ed_buttons_main.gif",7,1],false,function(e){e.execCommand("unlink");}],
insertfile:["Insert File",["ed_buttons_main.gif",9,1],true,function(e){e.execCommand("insertfile");}],
undo:["Undoes your last action",["ed_buttons_main.gif",4,2],false,function(e){e.execCommand("undo");}],
redo:["Redoes your last action",["ed_buttons_main.gif",5,2],false,function(e){e.execCommand("redo");}],
cut:["Cut selection",["ed_buttons_main.gif",5,0],false,cut_copy_paste],
copy:["Copy selection",["ed_buttons_main.gif",4,0],false,cut_copy_paste],
paste:["Paste from clipboard",["ed_buttons_main.gif",4,1],false,cut_copy_paste],
lefttoright:["Direction left to right",["ed_buttons_main.gif",0,4],false,function(e){e.execCommand("lefttoright");}],
righttoleft:["Direction right to left",["ed_buttons_main.gif",1,4],false,function(e){e.execCommand("righttoleft");}],
template:["Select template",["ed_buttons_main.gif",6,4],false,function(e){e.execCommand("template");}],
bgcolor:["Background Color",["ed_buttons_main.gif",2,3],false,function(e){e.execCommand("bgcolor");}],
bgimage:["Background Image",["ed_buttons_main.gif",2,4],false,function(e){e.execCommand("bgimage");}],
selectall:["Select all",["ed_buttons_main.gif",5,1],false,function(e){e.execCommand("selectall");}],
removeformat:["Remove formatting",["ed_buttons_main.gif",4,4],false,function(e){e.execCommand("removeformat");}],
print:["Print document",["ed_buttons_main.gif",8,1],false,function(e){e._iframe.contentWindow.print();}],
wordclean:["MS Word Cleaner",["ed_buttons_main.gif",4,3],false,function(e){e._wordClean();}]
};
for(var i in this.btnList){
var btn=this.btnList[i];
if(typeof btn[1]!='string')
{
btn[1][0]=_editor_url+this.imgURL+btn[1][0];
}
else
{
btn[1]=_editor_url+this.imgURL+btn[1];
}
try
{
if(typeof HTMLArea.I18N.tooltips[i]!="undefined")
{
btn[0]=HTMLArea.I18N.tooltips[i];
}
}
catch(e){}
}
};
HTMLArea.Config.prototype.registerButton=function(id,tooltip,image,textMode,action,context){
var the_id;
if(typeof id=="string"){
the_id=id;
}else if(typeof id=="object"){
the_id=id.id;
}else{
alert("ERROR [HTMLArea.Config::registerButton]:\ninvalid arguments");
return false;
}
if(typeof this.customSelects[the_id]!="undefined"){
}
if(typeof this.btnList[the_id]!="undefined"){
}
switch(typeof id){
case"string":this.btnList[id]=[tooltip,image,textMode,action,context];break;
case"object":this.btnList[id.id]=[id.tooltip,id.image,id.textMode,id.action,id.context];break;
}
};
HTMLArea.Config.prototype.registerDropdown=function(object){
if(typeof this.customSelects[object.id]!="undefined"){
}
if(typeof this.btnList[object.id]!="undefined"){
}
this.customSelects[object.id]=object;
};
HTMLArea.Config.prototype.hideSomeButtons=function(remove){
var toolbar=this.toolbar;
for(var i=toolbar.length;--i>=0;){
var line=toolbar[i];
for(var j=line.length;--j>=0;){
if(remove.indexOf(" "+line[j]+" ")>=0){
var len=1;
if(/[barstart|separator|space]/.test(line[j+1])){
len=1;
}
line.splice(j,len);
}
}
if(!line[1]){
line[0]="linebreak";
}
}
};
HTMLArea.replaceAll=function(config){
var tas=document.getElementsByTagName("textarea");
for(var i=tas.length;i>0;(new HTMLArea(tas[--i],config)).generate());
};
HTMLArea.replace=function(id,config){
var ta=HTMLArea.getElementById("textarea",id);
return ta?(new HTMLArea(ta,config)).generate():null;
};
HTMLArea.prototype._createToolbar=function(){
var editor=this;
var toolbar=document.createElement("div");
this._toolbar=toolbar;
toolbar.className="toolbar";
toolbar.unselectable="1";
var tb_row=null;
var tb_objects=new Object();
this._toolbarObjects=tb_objects;
function newLine(){
var table=document.createElement("table");
table.border="0px";
table.cellSpacing="0px";
table.cellPadding="0px";
toolbar.appendChild(table);
var tb_body=document.createElement("tbody");
table.appendChild(tb_body);
tb_row=document.createElement("tr");
tb_body.appendChild(tb_row);
};
newLine();
function setButtonStatus(id,newval){
var oldval=this[id];
var el=this.element;
if(oldval!=newval){
switch(id){
case"enabled":
if(newval){
HTMLArea._removeClass(el,"buttonDisabled");
el.disabled=false;
}else{
HTMLArea._addClass(el,"buttonDisabled");
el.disabled=true;
}
break;
case"active":
if(newval){
HTMLArea._addClass(el,"buttonPressed");
}else{
HTMLArea._removeClass(el,"buttonPressed");
}
break;
}
this[id]=newval;
}
};
function createSelect(txt){
var options=null;
var el=null;
var cmd=null;
var customSelects=editor.config.customSelects;
var context=null;
var tooltip="";
switch(txt){
case"fontsize":
case"fontname":
case"formatblock":
options=editor.config[txt];
cmd=txt;
break;
default:
cmd=txt;
var dropdown=customSelects[cmd];
if(typeof dropdown!="undefined"){
options=dropdown.options;
context=dropdown.context;
if(typeof dropdown.tooltip!="undefined"){
tooltip=dropdown.tooltip;
}
}else{
alert("ERROR [createSelect]:\nCan't find the requested dropdown definition");
}
break;
}
if(options){
el=document.createElement("select");
el.title=tooltip;
var obj={
name:txt,
element:el,
enabled:true,
text:false,
cmd:cmd,
state:setButtonStatus,
context:context
};
tb_objects[txt]=obj;
for(var i in options){
var op=document.createElement("option");
op.innerHTML=i;
op.value=options[i];
el.appendChild(op);
}
HTMLArea._addEvent(el,"change",function(){
editor._comboSelected(el,txt);
});
}
return el;
};
function createButton(txt){
var el=null;
var btn=null;
switch(txt){
case"barstart":
el=document.createElement("div");
el.className="barstart";
break;
case"separator":
el=document.createElement("div");
el.className="separator";
break;
case"space":
el=document.createElement("div");
el.className="space";
break;
case"linebreak":
newLine();
return false;
case"textindicator":
el=document.createElement("div");
el.appendChild(document.createTextNode("A"));
el.className="indicator";
el.title=HTMLArea.I18N.tooltips.textindicator;
var obj={
name:txt,
element:el,
enabled:true,
active:false,
text:false,
cmd:"textindicator",
state:setButtonStatus
};
tb_objects[txt]=obj;
break;
default:
btn=editor.config.btnList[txt];
}
if(!el&&btn){
el=document.createElement("div");
el.title=btn[0];
el.className="button";
var obj={
name:txt,
element:el,
enabled:true,
active:false,
text:btn[2],
cmd:btn[3],
state:setButtonStatus,
context:btn[4]||null
};
tb_objects[txt]=obj;
HTMLArea._addEvent(el,"mouseover",function(){
if(obj.enabled){
HTMLArea._addClass(el,"buttonHover");
}
});
HTMLArea._addEvent(el,"mouseout",function(){
if(obj.enabled)with(HTMLArea){
_removeClass(el,"buttonHover");
_removeClass(el,"buttonActive");
(obj.active)&&_addClass(el,"buttonPressed");
}
});
HTMLArea._addEvent(el,"mousedown",function(ev){
if(obj.enabled)with(HTMLArea){
_addClass(el,"buttonActive");
_removeClass(el,"buttonPressed");
_stopEvent(is_ie?window.event:ev);
}
});
HTMLArea._addEvent(el,"click",function(ev){
if(obj.enabled)with(HTMLArea){
_removeClass(el,"buttonActive");
_removeClass(el,"buttonHover");
obj.cmd(editor,obj.name,obj);
_stopEvent(is_ie?window.event:ev);
}
});
var i_contain=HTMLArea.makeBtnImg(btn[1]);
var img=i_contain.firstChild;
el.appendChild(i_contain);
obj.imgel=img;
obj.swapImage=function(newimg)
{
if(typeof newimg!='string')
{
img.src=newimg[0];
img.style.position='relative';
img.style.top=newimg[2]?('-'+(18*(newimg[2]+1))+'px'):'-18px';
img.style.left=newimg[1]?('-'+(18*(newimg[1]+1))+'px'):'-18px';
}
else
{
obj.imgel.src=newimg;
img.style.top='0px';
img.style.left='0px';
}
}
}else if(!el){
el=createSelect(txt);
}
if(el){
var tb_cell=document.createElement("td");
tb_row.appendChild(tb_cell);
tb_cell.appendChild(el);
}else{
alert("FIXME: Unknown toolbar item: "+txt);
}
return el;
};
var first=true;
for(var i=0;i<this.config.toolbar.length;++i){
if(!first){
createButton("linebreak");
}else{
first=false;
}
var group=this.config.toolbar[i];
for(var j=0;j<group.length;++j){
var code=group[j];
if(/^([IT])\[(.*?)\]/.test(code)){
var l7ed=RegExp.$1=="I";
var label=RegExp.$2;
if(l7ed){
label=HTMLArea.I18N.custom[label];
}
var tb_cell=document.createElement("td");
tb_row.appendChild(tb_cell);
tb_cell.className="label";
tb_cell.innerHTML=label;
}else{
createButton(code);
}
}
}
this._htmlArea.appendChild(toolbar);
};
use_clone_img=false;
HTMLArea.makeBtnImg=function(imgDef,doc)
{
if(!doc)doc=document;
if(!doc._htmlareaImgCache)
{
doc._htmlareaImgCache={};
}
var i_contain=null;
if(HTMLArea.is_ie&&((!doc.compatMode)||(doc.compatMode&&doc.compatMode=="BackCompat")))
{
i_contain=doc.createElement('span');
}
else
{
i_contain=doc.createElement('div');
i_contain.style.position='relative';
}
i_contain.style.overflow='hidden';
i_contain.style.width="18px";
i_contain.style.height="18px";
var img=null;
if(typeof imgDef=='string')
{
if(doc._htmlareaImgCache[imgDef])
{
img=doc._htmlareaImgCache[imgDef].cloneNode();
}
else
{
img=doc.createElement("img");
img.src=imgDef;
img.style.width="18px";
img.style.height="18px";
if(use_clone_img)
doc._htmlareaImgCache[imgDef]=img.cloneNode();
}
}
else
{
if(doc._htmlareaImgCache[imgDef[0]])
{
img=doc._htmlareaImgCache[imgDef[0]].cloneNode();
}
else
{
img=doc.createElement("img");
img.src=imgDef[0];
img.style.position='relative';
if(use_clone_img)
doc._htmlareaImgCache[imgDef[0]]=img.cloneNode();
}
img.style.top=imgDef[2]?('-'+(18*(imgDef[2]+1))+'px'):'-18px';
img.style.left=imgDef[1]?('-'+(18*(imgDef[1]+1))+'px'):'-18px';
}
i_contain.appendChild(img);
return i_contain;
}
HTMLArea.prototype._createStatusBar=function(){
var statusbar=document.createElement("div");
statusbar.className="statusBar";
this._htmlArea.appendChild(statusbar);
this._statusBar=statusbar;
div=document.createElement("span");
div.className="statusBarTree";
div.innerHTML=HTMLArea.I18N.msg["Path"]+": ";
this._statusBarTree=div;
this._statusBar.appendChild(div);
if(!this.config.statusBar){
statusbar.style.display="none";
}
};
HTMLArea.prototype.generate=function(){
var editor=this;
var textarea=this._textArea;
if(typeof textarea=="string"){
this._textArea=textarea=HTMLArea.getElementById("textarea",textarea);
}
this._ta_size={
w:textarea.offsetWidth,
h:textarea.offsetHeight
};
textarea.style.display="none";
var htmlarea=document.createElement("div");
htmlarea.className="htmlarea";
this._htmlArea=htmlarea;
textarea.parentNode.insertBefore(htmlarea,textarea);
if(textarea.form){
var f=textarea.form;
if(typeof f.onsubmit=="function"){
var funcref=f.onsubmit;
if(typeof f.__msh_prevOnSubmit=="undefined"){
f.__msh_prevOnSubmit=[];
}
f.__msh_prevOnSubmit.push(funcref);
}
f.onsubmit=function(){
editor._textArea.value=editor.getHTML();
var a=this.__msh_prevOnSubmit;
if(typeof a!="undefined"){
for(var i=a.length;--i>=0;){
a[i]();
}
}
};
if(typeof f.onreset=="function"){
var funcref=f.onreset;
if(typeof f.__msh_prevOnReset=="undefined"){
f.__msh_prevOnReset=[];
}
f.__msh_prevOnReset.push(funcref);
}
f.onreset=function(){
editor.setHTML(editor._textArea.value);
editor.updateToolbar();
var a=this.__msh_prevOnReset;
if(typeof a!="undefined"){
for(var i=a.length;--i>=0;){
a[i]();
}
}
};
}
try{
window.onunload=function(){
editor._textArea.value=editor.getHTML();
};
}catch(e){};
this._createToolbar();
var iframe=document.createElement("iframe");
iframe.src=_editor_url+"popups/blank.html";
htmlarea.appendChild(iframe);
this._iframe=iframe;
this._createStatusBar();
if(!HTMLArea.is_ie){
iframe.style.borderWidth="1px";
}
var height=(this.config.height=="auto"?(this._ta_size.h+"px"):this.config.height);
height=parseInt(height);
var width=(this.config.width=="auto"?(this._ta_size.w+"px"):this.config.width);
width=parseInt(width);
if(!HTMLArea.is_ie){
height-=2;
width-=2;
}
iframe.style.width=width+"px";
if(this.config.sizeIncludesToolbar){
height-=this._toolbar.offsetHeight;
height-=this._statusBar.offsetHeight;
}
if(height<0){
height=0;
}
iframe.style.height=height+"px";
textarea.style.width=iframe.style.width;
textarea.style.height=iframe.style.height;
function initIframe(){
var doc=editor._iframe.contentWindow.document;
if(!doc){
if(HTMLArea.is_gecko){
setTimeout(initIframe,100);
return false;
}else{
alert("ERROR: IFRAME can't be initialized.");
}
}
if(HTMLArea.is_gecko){
doc.designMode="on";
}
editor._doc=doc;
if(!editor.config.fullPage){
doc.open();
var html="<html>\n";
html+="<head>\n";
html+="<meta http-equiv=\"Content-Type\" content=\"text/html; charset="+editor.config.charSet+"\">\n";
if(typeof editor.config.baseHref!='undefined'&&editor.config.baseHref!=null)
{
html+="<base href=\""+editor.config.baseHref+"\"/>\n";
}
html+="<style title=\"table borders\">"
+".htmtableborders, .htmtableborders td, .htmtableborders th {border : 1px dashed lightgrey ! important;} \n"
+"</style>\n";
html+="<style>"
+editor.config.pageStyle+"\n"
+"html, body { border: 0px; } \n"
+"span.macro, span.macro ul, span.macro div, span.macro p {background : #CCCCCC;}\n"
+"</style>\n";
if(typeof editor.config.pageStyleSheets!=='undefined')
{
for(style_i=0;style_i<editor.config.pageStyleSheets.length;style_i++)
{
if(editor.config.pageStyleSheets[style_i].length>0)
html+="<link rel=\"stylesheet\" type=\"text/css\" href=\""+editor.config.pageStyleSheets[style_i]+"\">";
}
}
html+="</head>\n";
html+="<body>\n";
html+=editor._textArea.value;
html+="</body>\n";
html+="</html>";
doc.write(html);
doc.close();
}else{
var html=editor._textArea.value;
if(html.match(HTMLArea.RE_doctype)){
editor.setDoctype(RegExp.$1);
html=html.replace(HTMLArea.RE_doctype,"");
}
doc.open();
doc.write(html);
doc.close();
}
if(HTMLArea.is_ie){
doc.body.contentEditable=true;
}else{
}
editor.focusEditor();
HTMLArea._addEvents
(doc,["keydown","keypress","mousedown","mouseup","drag"],
function(event){
return editor._editorEvent(HTMLArea.is_ie?editor._iframe.contentWindow.event:event);
});
for(var i in editor.plugins){
var plugin=editor.plugins[i].instance;
if(typeof plugin.onGenerate=="function")
plugin.onGenerate();
if(typeof plugin.onGenerateOnce=="function"){
plugin.onGenerateOnce();
plugin.onGenerateOnce=null;
}
}
setTimeout(function(){
editor.updateToolbar();
},250);
if(typeof editor.onGenerate=="function")
editor.onGenerate();
};
setTimeout(initIframe,100);
};
HTMLArea.prototype.setMode=function(mode){
var editor=this;
var doc=editor._iframe.contentWindow.document;
if(typeof mode=="undefined"){
mode=((this._editMode=="textmode")?"wysiwyg":"textmode");
}
switch(mode){
case"textmode":
this._textArea.value=this.getHTML();
this._iframe.style.display="none";
this._textArea.style.display="block";
if(this.config.statusBar){
this._statusBar.appendChild(document.createTextNode(HTMLArea.I18N.msg["TEXT_MODE"]));
}
break;
case"wysiwyg":
if(HTMLArea.is_gecko){
try{
this._doc.designMode="off";
}catch(e){};
}
if(!this.config.fullPage){
this._doc.body.innerHTML=this.getHTML();
}else
this.setFullHTML(this.getHTML());
this._iframe.style.display="block";
this._textArea.style.display="none";
if(HTMLArea.is_gecko){
var html=this._textArea.value;
doc.open();
doc.write(html);
doc.close();
try{
this._doc.designMode="on";
}catch(e){};
if(doc.eventList)
{
for(var i=0;i<doc.eventList.length;i++)
doc.addEventListener(doc.eventList[i][0],doc.eventList[i][1],true);
}
}
if(this.config.statusBar){
this._statusBar.innerHTML='';
this._statusBar.appendChild(document.createTextNode(HTMLArea.I18N.msg["Path"]+": "));
this._statusBar.appendChild(this._statusBarTree);
}
break;
default:
alert("Mode <"+mode+"> not defined!");
return false;
}
this._editMode=mode;
this.focusEditor();
for(var i in this.plugins){
var plugin=this.plugins[i].instance;
if(typeof plugin.onMode=="function")plugin.onMode(mode);
}
};
HTMLArea.prototype.setFullHTML=function(html){
var save_multiline=RegExp.multiline;
RegExp.multiline=true;
if(html.match(HTMLArea.RE_doctype)){
this.setDoctype(RegExp.$1);
html=html.replace(HTMLArea.RE_doctype,"");
}
RegExp.multiline=save_multiline;
if(!HTMLArea.is_ie){
if(html.match(HTMLArea.RE_head))
this._doc.getElementsByTagName("head")[0].innerHTML=RegExp.$1;
if(html.match(HTMLArea.RE_body))
this._doc.getElementsByTagName("body")[0].innerHTML=RegExp.$1;
}else{
var html_re=/<html>((.|\n)*?)<\/html>/i;
html=html.replace(html_re,"$1");
this._doc.open();
this._doc.write(html);
this._doc.close();
this._doc.body.contentEditable=true;
return true;
}
};
HTMLArea.prototype.registerPlugin=function(){
var plugin=arguments[0];
var args=[];
for(var i=1;i<arguments.length;++i)
args.push(arguments[i]);
return this.registerPlugin2(plugin,args);
};
HTMLArea.prototype.registerPlugin2=function(plugin,args){
if(typeof plugin=="string")
plugin=eval(plugin);
if(typeof plugin=="undefined"){
return false;
}
var obj=new plugin(this,args);
if(obj){
var clone={};
var info=plugin._pluginInfo;
for(var i in info)
clone[i]=info[i];
clone.instance=obj;
clone.args=args;
this.plugins[plugin._pluginInfo.name]=clone;
return obj;
}else
alert("Can't register plugin "+plugin.toString()+".");
};
HTMLArea.getPluginDir=function(pluginName){
return _editor_url+"plugins/"+pluginName;
};
HTMLArea.loadPlugin=function(pluginName){
var dir=this.getPluginDir(pluginName);
var fullscreen_dir=_full_url+"plugins/"+pluginName;
var plugin=pluginName.replace(/([a-z])([A-Z])([a-z])/g,
function(str,l1,l2,l3){
return l1+"-"+l2.toLowerCase()+l3;
}).toLowerCase()+".js";
var plugin_file=dir+"/"+plugin;
var plugin_lang=dir+"/lang/"+_editor_lang+".js";
var fullscreen_plugin_file=fullscreen_dir+"/"+plugin;
var fullscreen_plugin_lang=fullscreen_dir+"/lang/"+_editor_lang+".js";
this.loadScript(plugin_file);
this.loadScript(plugin_lang);
document.write("<script type='text/javascript' src='"+fullscreen_plugin_file+"'></script>");
document.write("<script type='text/javascript' src='"+fullscreen_plugin_lang+"'></script>");
};
HTMLArea.loadStyle=function(style,plugin){
var url=_editor_url||'';
if(typeof plugin!="undefined"){
url+="plugins/"+plugin+"/";
}
url+=style;
if(/^\//.test(style))
url=style;
var head=document.getElementsByTagName("head")[0];
var link=document.createElement("link");
link.rel="stylesheet";
link.href=url;
head.appendChild(link);
};
HTMLArea.loadStyle(typeof _editor_css=="string"?_editor_css:"htmlarea.css");
HTMLArea.prototype.debugTree=function(){
var ta=document.createElement("textarea");
ta.style.width="100%";
ta.style.height="20em";
ta.value="";
function debug(indent,str){
for(;--indent>=0;)
ta.value+=" ";
ta.value+=str+"\n";
};
function _dt(root,level){
var tag=root.tagName.toLowerCase(),i;
var ns=HTMLArea.is_ie?root.scopeName:root.prefix;
debug(level,"- "+tag+" ["+ns+"]");
for(i=root.firstChild;i;i=i.nextSibling)
if(i.nodeType==1)
_dt(i,level+2);
};
_dt(this._doc.body,0);
document.body.appendChild(ta);
};
HTMLArea.getInnerText=function(el){
var txt='',i;
for(i=el.firstChild;i;i=i.nextSibling){
if(i.nodeType==3)
txt+=i.data;
else if(i.nodeType==1)
txt+=HTMLArea.getInnerText(i);
}
return txt;
};
HTMLArea.prototype._wordClean=function(){
var
editor=this,
stats={
empty_tags:0,
mso_class:0,
mso_style:0,
mso_xmlel:0,
orig_len:this._doc.body.innerHTML.length,
T:(new Date()).getTime()
},
stats_txt={
empty_tags:"Empty tags removed: ",
mso_class:"MSO class names removed: ",
mso_style:"MSO inline style removed: ",
mso_xmlel:"MSO XML elements stripped: "
};
function showStats(){
var txt="HTMLArea word cleaner stats: \n\n";
for(var i in stats)
if(stats_txt[i])
txt+=stats_txt[i]+stats[i]+"\n";
txt+="\nInitial document length: "+stats.orig_len+"\n";
txt+="Final document length: "+editor._doc.body.innerHTML.length+"\n";
txt+="Clean-up took "+(((new Date()).getTime()-stats.T)/1000)+" seconds";
alert(txt);
};
function clearClass(node){
var newc=node.className.replace(/(^|\s)mso.*?(\s|$)/ig,' ');
if(newc!=node.className){
node.className=newc;
if(!/\S/.test(node.className)){
node.removeAttribute("className");
++stats.mso_class;
}
}
};
function clearStyle(node){
var declarations=node.style.cssText.split(/\s*;\s*/);
for(var i=declarations.length;--i>=0;)
if(/^mso|^tab-stops/i.test(declarations[i])||
/^margin\s*:\s*0..\s+0..\s+0../i.test(declarations[i])){
++stats.mso_style;
declarations.splice(i,1);
}
node.style.cssText=declarations.join("; ");
};
function stripTag(el){
if(HTMLArea.is_ie)
el.outerHTML=HTMLArea.htmlEncode(el.innerText);
else{
var txt=document.createTextNode(HTMLArea.getInnerText(el));
el.parentNode.insertBefore(txt,el);
el.parentNode.removeChild(el);
}
++stats.mso_xmlel;
};
function checkEmpty(el){
if(/^(a|span|b|strong|i|em|font)$/i.test(el.tagName)&&
!el.firstChild){
el.parentNode.removeChild(el);
++stats.empty_tags;
}
};
function parseTree(root){
var tag=root.tagName.toLowerCase(),i,next;
if((HTMLArea.is_ie&&root.scopeName!='HTML')||(!HTMLArea.is_ie&&/:/.test(tag))){
stripTag(root);
return false;
}else{
clearClass(root);
clearStyle(root);
for(i=root.firstChild;i;i=next){
next=i.nextSibling;
if(i.nodeType==1&&parseTree(i))
checkEmpty(i);
}
}
return true;
};
parseTree(this._doc.body);
this.updateToolbar();
};
HTMLArea.prototype.forceRedraw=function(){
this._doc.body.style.visibility="hidden";
this._doc.body.style.visibility="visible";
};
HTMLArea.prototype.focusEditor=function(){
switch(this._editMode){
case"wysiwyg":try{this._iframe.contentWindow.focus()}catch(e){}break;
case"textmode":try{this._textArea.focus()}catch(e){}break;
default:alert("ERROR: mode "+this._editMode+" is not defined");
}
return this._doc;
};
HTMLArea.prototype._undoTakeSnapshot=function(){
var curTime=(new Date()).getTime();
var newOne=true;
if(this._undoPos>=this.config.undoSteps){
this._undoQueue.shift();
--this._undoPos;
}
if(this._undoPos<0||
this._undoQueue[this._undoPos].time<curTime-this.config.undoTimeout)
++this._undoPos;
else
newOne=false;
var txt=this.getInnerHTML();
if(newOne){
if(this._undoPos==0||this._undoQueue[this._undoPos-1].text!=txt){
this._undoQueue[this._undoPos]={text:txt,time:curTime};
this._undoQueue.length=this._undoPos+1;
}else
this._undoPos--;
}else{
if(this._undoQueue[this._undoPos].text!=txt){
this._undoQueue[this._undoPos].text=txt;
this._undoQueue.length=this._undoPos+1;
}
}
};
HTMLArea.prototype.undo=function(){
if(this._undoPos>0){
this._undoTakeSnapshot();
this.setHTML(this._undoQueue[--this._undoPos].text);
}
};
HTMLArea.prototype.redo=function(){
if(this._undoPos<this._undoQueue.length-1){
this._undoTakeSnapshot();
if(this._undoPos<this._undoQueue.length-1)
this.setHTML(this._undoQueue[++this._undoPos].text);
}
};
HTMLArea.prototype.updateToolbar=function(noStatus){
var doc=this._doc;
var text=(this._editMode=="textmode");
var ancestors=null;
if(!text){
ancestors=this.getAllAncestors();
if(this.config.statusBar&&!noStatus){
if(HTMLArea.is_ie){
this._statusBar.innerHTML='';
this._statusBar.appendChild(document.createTextNode(HTMLArea.I18N.msg["Path"]+": "));
this._statusBar.appendChild(this._statusBarTree);
}else{
this._statusBarTree.innerHTML=HTMLArea.I18N.msg["Path"]+": ";
}
for(var i=ancestors.length;--i>=0;){
var el=ancestors[i];
if(!el){
continue;
}
var a=document.createElement("a");
a.href="javascript:void(0)";
a.el=el;
a.editor=this;
a.onclick=function(){
this.blur();
this.editor.selectNodeContents(this.el);
this.editor.updateToolbar(true);
return false;
};
a.oncontextmenu=function(){
this.blur();
var info="Inline Style:\n\n";
info+=this.el.style.cssText.split(/;\s*/).join(";\n");
alert(info);
return false;
};
var txt=el.tagName.toLowerCase();
a.title=el.style.cssText;
if(el.id){
txt+="#"+el.id;
}
if(el.className){
txt+="."+el.className;
}
a.appendChild(document.createTextNode(txt));
this._statusBarTree.appendChild(a);
if(i!=0){
this._statusBarTree.appendChild(document.createTextNode(String.fromCharCode(0xbb)));
}
}
}
}
for(var i in this._toolbarObjects){
var btn=this._toolbarObjects[i];
var cmd=i;
var inContext=true;
if(btn.context&&!text){
inContext=false;
var context=btn.context;
var attrs=[];
if(/(.*)\[(.*?)\]/.test(context)){
context=RegExp.$1;
attrs=RegExp.$2.split(",");
}
context=context.toLowerCase();
var match=(context=="*");
for(var k=0;k<ancestors.length;++k){
if(!ancestors[k]){
continue;
}
if(match||(ancestors[k].tagName.toLowerCase()==context)){
inContext=true;
for(var ka=0;ka<attrs.length;++ka){
if(!eval("ancestors[k]."+attrs[ka])){
inContext=false;
break;
}
}
if(inContext){
break;
}
}
}
}
btn.state("enabled",(!text||btn.text)&&inContext);
if(typeof cmd=="function"){
continue;
}
var dropdown=this.config.customSelects[cmd];
if((!text||btn.text)&&(typeof dropdown!="undefined")){
dropdown.refresh(this);
continue;
}
switch(cmd){
case"fontname":
case"fontsize":
case"formatblock":
if(!text)try{
var value=(""+doc.queryCommandValue(cmd)).toLowerCase();
if(!value){
btn.element.selectedIndex=0;
break;
}
var options=this.config[cmd];
var k=0;
for(var j in options){
if((j.toLowerCase()==value)||
(options[j].substr(0,value.length).toLowerCase()==value)){
btn.element.selectedIndex=k;
throw"ok";
}
++k;
}
btn.element.selectedIndex=0;
}catch(e){};
break;
case"textindicator":
if(!text){
try{with(btn.element.style){
backgroundColor=HTMLArea._makeColor(
doc.queryCommandValue(HTMLArea.is_ie?"backcolor":"hilitecolor"));
if(/transparent/i.test(backgroundColor)){
backgroundColor=HTMLArea._makeColor(doc.queryCommandValue("backcolor"));
}
color=HTMLArea._makeColor(doc.queryCommandValue("forecolor"));
fontFamily=doc.queryCommandValue("fontname");
fontWeight=doc.queryCommandState("bold")?"bold":"normal";
fontStyle=doc.queryCommandState("italic")?"italic":"normal";
}}catch(e){
}
}
break;
case"htmlmode":btn.state("active",text);break;
case"lefttoright":
case"righttoleft":
var el=this.getParentElement();
while(el&&!HTMLArea.isBlockElement(el))
el=el.parentNode;
if(el)
btn.state("active",(el.style.direction==((cmd=="righttoleft")?"rtl":"ltr")));
break;
default:
cmd=cmd.replace(/(un)?orderedlist/i,"insert$1orderedlist");
try{
btn.state("active",(!text&&doc.queryCommandState(cmd)));
}catch(e){}
}
}
this._undoTakeSnapshot();
for(var i in this.plugins){
var plugin=this.plugins[i].instance;
if(typeof plugin.onUpdateToolbar=="function")
plugin.onUpdateToolbar();
}
};
HTMLArea.prototype.insertNodeAtSelection=function(toBeInserted){
if(!HTMLArea.is_ie){
var sel=this._getSelection();
var range=this._createRange(sel);
sel.removeAllRanges();
range.deleteContents();
var node=range.startContainer;
var pos=range.startOffset;
switch(node.nodeType){
case 3:
if(toBeInserted.nodeType==3){
node.insertData(pos,toBeInserted.data);
range=this._createRange();
range.setEnd(node,pos+toBeInserted.length);
range.setStart(node,pos+toBeInserted.length);
sel.addRange(range);
}else{
node=node.splitText(pos);
var selnode=toBeInserted;
if(toBeInserted.nodeType==11){
selnode=selnode.firstChild;
}
node.parentNode.insertBefore(toBeInserted,node);
this.selectNodeContents(selnode);
this.updateToolbar();
}
break;
case 1:
var selnode=toBeInserted;
if(toBeInserted.nodeType==11){
selnode=selnode.firstChild;
}
node.insertBefore(toBeInserted,node.childNodes[pos]);
this.selectNodeContents(selnode);
this.updateToolbar();
break;
}
}else{
return null;
}
};
HTMLArea.prototype.getParentElement=function(sel){
if(typeof sel=='undefined')
{
sel=this._getSelection();
}
var range=this._createRange(sel);
if(HTMLArea.is_ie){
switch(sel.type){
case"Text":
var parent=range.parentElement();
while(true)
{
var TestRange=range.duplicate();
TestRange.moveToElementText(parent);
if(TestRange.inRange(range))break;
if((parent.nodeType!=1)||(parent.tagName.toLowerCase()=='body'))break;
parent=parent.parentElement;
};
return parent;
case"None":
return range.parentElement();
case"Control":
return range.item(0);
default:
return this._doc.body;
}
}else try{
var p=range.commonAncestorContainer;
if(!range.collapsed&&range.startContainer==range.endContainer&&
range.startOffset-range.endOffset<=1&&range.startContainer.hasChildNodes())
p=range.startContainer.childNodes[range.startOffset];
while(p.nodeType==3){
p=p.parentNode;
}
return p;
}catch(e){
return null;
}
};
HTMLArea.prototype.getAllAncestors=function(){
var p=this.getParentElement();
var a=[];
while(p&&(p.nodeType==1)&&(p.tagName.toLowerCase()!='body')){
a.push(p);
p=p.parentNode;
}
a.push(this._doc.body);
return a;
};
HTMLArea.prototype.selectNodeContents=function(node,pos){
this.focusEditor();
this.forceRedraw();
var range;
var collapsed=(typeof pos!="undefined");
if(HTMLArea.is_ie){
if(!collapsed&&node.tagName&&node.tagName.toLowerCase().match(/table|img/))
{
range=this._doc.body.createControlRange();
range.add(node);
}
else
{
range=this._doc.body.createTextRange();
range.moveToElementText(node);
(collapsed)&&range.collapse(pos);
}
range.select();
}else{
var sel=this._getSelection();
range=this._doc.createRange();
if(!collapsed&&node.tagName&&node.tagName.toLowerCase().match(/table|img/))
{
range.selectNode(node);
(collapsed)&&range.collapse(pos);
}
else
{
range.selectNodeContents(node);
(collapsed)&&range.collapse(pos);
}
sel.removeAllRanges();
sel.addRange(range);
}
};
HTMLArea.prototype.insertHTML=function(html){
var sel=this._getSelection();
var range=this._createRange(sel);
this.focusEditor();
if(HTMLArea.is_ie){
range.pasteHTML(html);
}else{
var fragment=this._doc.createDocumentFragment();
var div=this._doc.createElement("div");
div.innerHTML=html;
while(div.firstChild){
fragment.appendChild(div.firstChild);
}
var node=this.insertNodeAtSelection(fragment);
}
};
HTMLArea.prototype.surroundHTML=function(startTag,endTag){
var html=this.getSelectedHTML();
this.insertHTML(startTag+html+endTag);
};
HTMLArea.prototype.getSelectedHTML=function(){
var sel=this._getSelection();
var range=this._createRange(sel);
var existing=null;
if(HTMLArea.is_ie){
existing=range.htmlText;
}else{
existing=HTMLArea.getHTML(range.cloneContents(),false,this);
}
return existing;
};
HTMLArea.prototype.hasSelectedText=function(){
return this.getSelectedHTML()!='';
};
HTMLArea.prototype._createLink=function(link){
var editor=this;
var outparam=null;
var t_event="";
var t_event_value="";
if(typeof link=="undefined"){
link=this.getParentElement();
if(link){
if(/^img$/i.test(link.tagName))
link=link.parentNode;
if(!/^a$/i.test(link.tagName))
link=null;
t_linktext=this.getSelectedHTML();
}
}
if(link){
if(HTMLArea.is_ie){
if(link.onclick!=null){t_event="onclick";t_event_value=link.onclick.toString();}
if(link.onmouseover!=null){t_event="onmouseover";t_event_value=link.onmouseover.toString();}
if(link.onmouseout!=null){t_event="onmouseout";t_event_value=link.onmouseout.toString();}
}else{
if(link.onclick){t_event="onclick";t_event_value=link.getAttribute("onclick").toString();}
if(link.onmouseover){t_event="onmouseover";t_event_value=link.getAttribute("onmouseover").toString();}
if(link.onmouseout){t_event="onmouseout";t_event_value=link.getAttribute("onmouseout").toString();}
}
outparam={
f_href:HTMLArea.is_ie?editor.stripBaseURL(link.href):link.getAttribute("href"),
f_title:HTMLArea.is_ie?link.title:link.getAttribute("title"),
f_linktext:HTMLArea.is_ie?link.getAdjacentText("afterBegin"):link.firstChild.nodeValue,
f_target:HTMLArea.is_ie?link.target:link.getAttribute("target"),
f_id:HTMLArea.is_ie?link.id:link.getAttribute("id"),
f_name:HTMLArea.is_ie?link.name:link.getAttribute("name"),
f_event:t_event,
f_event_value:t_event_value,
f_class:link.className,
f_style:link.style.cssText,
q:"",
feditor:editor
}
}else{
var sel=editor._getSelection();
var range=editor._createRange(sel);
var compare=0;
if(HTMLArea.is_ie){
if(sel.type=="Control")
compare=range.length;
else
compare=range.compareEndPoints("StartToEnd",range);
}else{
compare=range.compareBoundaryPoints(range.START_TO_END,range);
}
if(compare==0){
alert("You need to select some text before creating a link");
return;
}
outparam={
f_href:"http://",
f_title:t_linktext,
f_linktext:t_linktext,
f_target:"_blank",
f_id:"",
f_name:"",
f_event:"",
f_event_value:"",
f_class:"",
f_style:"",
q:"",
feditor:editor
}
};
this._popupDialog("insert_link.html",function(param){
if(!param)
return false;
var a=link;
if(!a)try{
editor._doc.execCommand("createlink",false,param.f_href);
a=editor.getParentElement();
var sel=editor._getSelection();
var range=editor._createRange(sel);
if(!HTMLArea.is_ie){
a=range.startContainer;
if(!/^a$/i.test(a.tagName)){
a=a.nextSibling;
if(a==null)
a=range.startContainer.parentNode;
}
}
}catch(e){}
else{
var href=param.f_href.trim();
editor.selectNodeContents(a);
if(href==""){
editor._doc.execCommand("unlink",false,null);
editor.updateToolbar();
return false;
}
else{
a.href=href;
}
}
if(!(a&&/^a$/i.test(a.tagName)))
return false;
a.target=param.f_target.trim();
a.title=param.f_title.trim();
a.id=param.f_id.trim();
a.setAttribute("name",param.f_name.trim());
a.className=param.f_class.trim();
a.style.cssText=param.f_style.trim();
if(HTMLArea.is_ie){
a.replaceAdjacentText("afterBegin",param.f_linktext.trim());
if(param.f_event.trim()=="onclick")a.onclick=param.f_event_value.trim();
if(param.f_event.trim()=="onmouseover")a.onmouseover=param.f_event_value.trim();
if(param.f_event.trim()=="onmouseout")a.onmouseout=param.f_event_value.trim();
}else{
a.firstChild.nodeValue=param.f_linktext.trim();
if(param.f_event.trim()=="onclick")a.setAttribute("onclick",param.f_event_value.trim());
if(param.f_event.trim()=="onmouseover")a.setAttribute("onmouseover",param.f_event_value.trim());
if(param.f_event.trim()=="onmouseout")a.setAttribute("onmouseout",param.f_event_value.trim());
}
editor.selectNodeContents(a);
editor.updateToolbar();
},outparam);
};
HTMLArea.prototype._insertImage=function(image){
var editor=this;
var outparam=null;
if(typeof image=="undefined"){
image=this.getParentElement();
if(image&&!/^img$/i.test(image.tagName))
image=null;
}
if(image){outparam={
f_base:editor.config.baseURL,
f_url:HTMLArea.is_ie?editor.stripBaseURL(image.src):image.getAttribute("src"),
f_alt:image.alt,
f_border:image.border,
f_align:image.align,
f_vert:image.vspace,
f_horiz:image.hspace,
f_baseurl:this.config.baseURL
}
};
this._popupDialog("insert_image.html",function(param){
if(!param){
return false;
}
var img=image;
if(!img){
var sel=editor._getSelection();
var range=editor._createRange(sel);
editor._doc.execCommand("insertimage",false,param.ImgUrl);
if(HTMLArea.is_ie){
img=range.parentElement();
if(img.tagName.toLowerCase()!="img"){
img=img.previousSibling;
}
}else{
img=range.startContainer.previousSibling;
}
}else{
img.src=param.ImgUrl;
}
for(var field in param){
var value=param[field];
switch(field){
case"f_alt":img.alt=value;break;
case"f_border":img.border=parseInt(value||"0");break;
case"f_align":img.align=value;break;
case"f_vert":img.vspace=parseInt(value||"0");break;
case"f_horiz":img.hspace=parseInt(value||"0");break;
}
}
},outparam);
};
HTMLArea.prototype._insertTable=function(){
var sel=this._getSelection();
var range=this._createRange(sel);
var editor=this;
this._popupDialog("insert_table.html",function(param){
if(!param){
return false;
}
var doc=editor._doc;
var table=doc.createElement("table");
for(var field in param){
var value=param[field];
if(!value){
continue;
}
switch(field){
case"f_width":table.style.width=value+param["f_unit"];break;
case"f_align":table.align=value;break;
case"f_border":table.border=parseInt(value);break;
case"f_spacing":table.cellSpacing=parseInt(value);break;
case"f_padding":table.cellPadding=parseInt(value);break;
}
}
var cellwidth=0;
if(param.f_fixed)
cellwidth=Math.floor(100/parseInt(param.f_cols));
var tbody=doc.createElement("tbody");
table.appendChild(tbody);
for(var i=0;i<param["f_rows"];++i){
var tr=doc.createElement("tr");
tbody.appendChild(tr);
for(var j=0;j<param["f_cols"];++j){
var td=doc.createElement("td");
if(cellwidth)
td.style.width=cellwidth+"%";
tr.appendChild(td);
td.appendChild(doc.createTextNode('\u00a0'));
}
}
if(HTMLArea.is_ie){
range.pasteHTML(table.outerHTML);
}else{
editor.insertNodeAtSelection(table);
}
return true;
},null);
};
HTMLArea.prototype._searchreplace=function(){
var editor=this;
var outparam=null;
var range=this.getSelectedHTML();
if(range)outparam={
fword:range,
feditor:editor
};
this._popupDialog("search_replace.html",function(param){
if(!param){
return false;
}
return true;
},outparam);
};
HTMLArea.prototype._insertTemplate=function(){
var editor=this;
this._popupDialogml("insert_template.shtml",function(text){
if(!text){
return false;
}
editor.setHTML(unescape(text));
},null);
};
HTMLArea.prototype._comboSelected=function(el,txt){
this.focusEditor();
var value=el.options[el.selectedIndex].value;
switch(txt){
case"fontname":
case"fontsize":this.execCommand(txt,false,value);break;
case"formatblock":
if(!HTMLArea.is_gecko||value!=='blockquote'){value="<"+value+">";}
this.execCommand(txt,false,value);
break;
default:
var dropdown=this.config.customSelects[txt];
if(typeof dropdown!="undefined"){
dropdown.action(this);
}else{
alert("FIXME: combo box "+txt+" not implemented");
}
}
};
HTMLArea.prototype.execCommand=function(cmdID,UI,param){
var editor=this;
this.focusEditor();
cmdID=cmdID.toLowerCase();
if(HTMLArea.is_gecko)try{this._doc.execCommand('useCSS',false,true);}catch(e){};
switch(cmdID){
case"htmlmode":this.setMode();break;
case"hilitecolor":
(HTMLArea.is_ie)&&(cmdID="backcolor");
if(HTMLArea.is_gecko)try{editor._doc.execCommand('useCSS',false,false);}catch(e){};
case"forecolor":
this._popupDialog("select_color.html",function(color){
if(color){
editor._doc.execCommand(cmdID,false,"#"+color);
}
},HTMLArea._colorToRgb(this._doc.queryCommandValue(cmdID)));
break;
case"createlink":
this._createLink();
break;
case"popupeditor":
HTMLArea._object=this;
if(HTMLArea.is_ie){
{
window.open(_editor_url+"fullscreen.html","ha_fullscreen",
"toolbar=no,location=no,directories=no,status=no,menubar=no,"+
"scrollbars=no,resizable=yes,width=640,height=480");
}
}else{
window.open(_editor_url+"fullscreen.html","ha_fullscreen",
"toolbar=yes,menubar=yes,personalbar=yes,width=640,height=480,"+
"scrollbars=yes,resizable=yes");
}
break;
case"undo":
case"redo":
if(this._customUndo)
this[cmdID]();
else
this._doc.execCommand(cmdID,UI,param);
break;
case"inserttable":this._insertTable();break;
case"toggleborders":this._toggleBorders();break;
case"insertfile":this._insertFile();break;
case"insertimage":this._insertImage();break;
case"about":this._popupDialog("about.html",null,this);break;
case"showhelp":
window.open(this.popupURLml("reference.html"),"ha_help",
"toolbar=no,menubar=no,personalbar=no,width=168,height=432,"+
"scrollbars=yes,resizable=yes");
break;
case"killword":this._wordClean();break;
case"cut":
case"copy":
case"paste":
try{
this._doc.execCommand(cmdID,UI,param);
if(this.config.killWordOnPaste)
this._wordClean();
}catch(e){
if(HTMLArea.is_gecko){
if(typeof HTMLArea.I18N.msg["Moz-Clipboard"]=="undefined"){
HTMLArea.I18N.msg["Moz-Clipboard"]=
"Unprivileged scripts cannot access Cut/Copy/Paste programatically "+
"for security reasons.  Click OK to see a technical note at mozilla.org "+
"which shows you how to allow a script to access the clipboard.\n\n"+
"[FIXME: please translate this message in your language definition file.]";
}
if(confirm(HTMLArea.I18N.msg["Moz-Clipboard"]))
window.open("http://mozilla.org/editor/midasdemo/securityprefs.html");
}
}
break;
case"lefttoright":
case"righttoleft":
var dir=(cmdID=="righttoleft")?"rtl":"ltr";
var el=this.getParentElement();
while(el&&!HTMLArea.isBlockElement(el))
el=el.parentNode;
if(el){
if(el.style.direction==dir)
el.style.direction="";
else
el.style.direction=dir;
}
break;
case"selectall":this._doc.execCommand(cmdID,UI,param);
break;
case"removeformat":this._doc.execCommand(cmdID,UI,param);
break;
case"searchreplace":this._searchreplace();break;
case"bgcolor":
oldcolor=this._doc.body.bgcolor;
this._popupDialog("select_color.html",function(color){
if((color)&&(color!='none')){
if(editor._doc.getElementById("myDivBg")){
editor.selectNodeContents(editor._doc.getElementById("myDivBg"));
var oldText=editor._doc.getElementById("myDivBg").innerHTML;
editor._doc.body.removeChild(editor._doc.getElementById("myDivBg"));
editor.insertHTML(oldText);
}
var newElem=editor._doc.createElement("DIV");
var oldText=editor.getHTML();
newText="<DIV id='myDivBg' style='background-color: "+color+";'>"+oldText+"</DIV>";
editor.setHTML(newText);
}else if(color=='none'){
editor.selectNodeContents(editor._doc.getElementById("myDivBg"));
var oldText=editor._doc.getElementById("myDivBg").innerHTML;
editor._doc.body.removeChild(editor._doc.getElementById("myDivBg"));
editor.insertHTML(oldText);
}
},
oldcolor);
break;
case"bgimage":
oldBgImage=this._doc.body.background;
this._popupDialogml("insert_bgimage.html",function(bgimage){
if((bgimage)&&(bgimage!='none')){
if(editor._doc.getElementById("myDivBg")){
editor.selectNodeContents(editor._doc.getElementById("myDivBg"));
var oldText=editor._doc.getElementById("myDivBg").innerHTML;
editor._doc.body.removeChild(editor._doc.getElementById("myDivBg"));
editor.insertHTML(oldText);
}
var newBgImage=_editor_url+"images/backgrounds/"+bgimage;
var newElem=editor._doc.createElement("DIV");
var oldText=editor.getHTML();
newText="<DIV id='myDivBg' style='background: url("+newBgImage+");'>"+oldText+"</DIV>";
editor.setHTML(newText);
}else if(bgimage=='none'){
editor.selectNodeContents(editor._doc.getElementById("myDivBg"));
var oldText=editor._doc.getElementById("myDivBg").innerHTML;
editor._doc.body.removeChild(editor._doc.getElementById("myDivBg"));
editor.insertHTML(oldText);
}
},
oldBgImage);
break;
case"template":this._insertTemplate();break;
case"wordclean":this._wordClean();break;
default:try{this._doc.execCommand(cmdID,UI,param);}
catch(e){if(this.config.debug){alert(e+"\n\nby execCommand("+cmdID+");");}}
}
this.updateToolbar();
return false;
};
HTMLArea.prototype._editorEvent=function(ev){
var editor=this;
var keyEvent=(HTMLArea.is_ie&&ev.type=="keydown")||(!HTMLArea.is_ie&&ev.type=="keypress");
if(typeof editor._textArea['on'+ev.type]=="function"){
editor._textArea['on'+ev.type]();
}
if(HTMLArea.is_gecko&&keyEvent&&ev.ctrlKey&&this._unLink&&this._unlinkOnUndo)
{
if(String.fromCharCode(ev.charCode).toLowerCase()=='z')
{
HTMLArea._stopEvent(ev);
this._unLink();
editor.updateToolbar();
return;
}
}
if(keyEvent)
{
for(var i in editor.plugins)
{
var plugin=editor.plugins[i].instance;
if(typeof plugin.onKeyPress=="function")
if(plugin.onKeyPress(ev))
return false;
}
}
if(keyEvent&&ev.ctrlKey&&!ev.altKey)
{
var sel=null;
var range=null;
var key=String.fromCharCode(HTMLArea.is_ie?ev.keyCode:ev.charCode).toLowerCase();
var cmd=null;
var value=null;
switch(key){
case'a':
if(!HTMLArea.is_ie){
sel=this._getSelection();
sel.removeAllRanges();
range=this._createRange();
range.selectNodeContents(this._doc.body);
sel.addRange(range);
HTMLArea._stopEvent(ev);
}
break;
case'b':cmd="bold";break;
case'i':cmd="italic";break;
case'u':cmd="underline";break;
case's':cmd="strikethrough";break;
case'l':cmd="justifyleft";break;
case'e':cmd="justifycenter";break;
case'r':cmd="justifyright";break;
case'j':cmd="justifyfull";break;
case'z':cmd="undo";break;
case'y':cmd="redo";break;
case'v':if(HTMLArea.is_ie||editor.config.htmlareaPaste){cmd="paste";}break;
case'n':cmd="formatblock";value=HTMLArea.is_ie?"<p>":"p";break;
case'0':cmd="killword";break;
case'1':
case'2':
case'3':
case'4':
case'5':
case'6':
cmd="formatblock";
value="h"+key;
if(HTMLArea.is_ie)
value="<"+value+">";
break;
}
if(cmd){
this.execCommand(cmd,false,value);
HTMLArea._stopEvent(ev);
}
}
else if(keyEvent)
{
if(HTMLArea.is_gecko)
{
var s=editor._getSelection()
var autoWrap=function(textNode,tag)
{
var rightText=textNode.nextSibling;
if(typeof tag=='string')tag=editor._doc.createElement(tag);
var a=textNode.parentNode.insertBefore(tag,rightText);
HTMLArea.removeFromParent(textNode);
a.appendChild(textNode);
rightText.data=' '+rightText.data;
if(HTMLArea.is_ie)
{
var r=editor._createRange(s);
s.moveToElementText(rightText);
s.move('character',1);
}
else
{
s.collapse(rightText,1);
}
HTMLArea._stopEvent(ev);
editor._unLink=function()
{
var t=a.firstChild;
a.removeChild(t);
a.parentNode.insertBefore(t,a);
HTMLArea.removeFromParent(a);
editor._unLink=null;
editor._unlinkOnUndo=false;
}
editor._unlinkOnUndo=true;
return a;
}
switch(ev.which)
{
case 32:
{
if(s&&s.isCollapsed&&s.anchorNode.nodeType==3&&s.anchorNode.data.length>3&&s.anchorNode.data.indexOf('.')>=0)
{
var midStart=s.anchorNode.data.substring(0,s.anchorOffset).search(/\S{4,}$/);
if(midStart==-1)break;
if(this._getFirstAncestor(s,'a'))
{
break;
}
var matchData=s.anchorNode.data.substring(0,s.anchorOffset).replace(/^.*?(\S*)$/,'$1');
var m=matchData.match(HTMLArea.RE_email);
if(m)
{
var leftText=s.anchorNode;
var rightText=leftText.splitText(s.anchorOffset);
var midText=leftText.splitText(midStart);
autoWrap(midText,'a').href='mailto:'+m[0];
break;
}
var m=matchData.match(HTMLArea.RE_url);
if(m)
{
var leftText=s.anchorNode;
var rightText=leftText.splitText(s.anchorOffset);
var midText=leftText.splitText(midStart);
autoWrap(midText,'a').href=(m[1]?m[1]:'http://')+m[2];
break;
}
}
}
break;
default:
{
if(ev.keyCode==27||(this._unlinkOnUndo&&ev.ctrlKey&&ev.which==122))
{
if(this._unLink)
{
this._unLink();
HTMLArea._stopEvent(ev);
}
break;
}
else if(ev.which||ev.keyCode==8||ev.keyCode==46)
{
this._unlinkOnUndo=false;
if(s.anchorNode&&s.anchorNode.nodeType==3)
{
var a=this._getFirstAncestor(s,'a');
if(!a)break;
if(!a._updateAnchTimeout)
{
if(s.anchorNode.data.match(HTMLArea.RE_email)
&&(a.href.match('mailto:'+s.anchorNode.data.trim()))
)
{
var textNode=s.anchorNode;
var fn=function()
{
a.href='mailto:'+textNode.data.trim();
a._updateAnchTimeout=setTimeout(fn,250);
}
a._updateAnchTimeout=setTimeout(fn,250);
break;
}
var m=s.anchorNode.data.match(HTMLArea.RE_url);
if(m&&a.href.match(s.anchorNode.data.trim()))
{
var textNode=s.anchorNode;
var fn=function()
{
var m=textNode.data.match(HTMLArea.RE_url);
a.href=(m[1]?m[1]:'http://')+m[2];
a._updateAnchTimeout=setTimeout(fn,250);
}
a._updateAnchTimeout=setTimeout(fn,250);
}
}
}
}
}
break;
}
}
switch(ev.keyCode)
{
case 13:
if(HTMLArea.is_gecko&&!ev.shiftKey&&this.config.mozParaHandler=='dirty')
{
this.dom_checkInsertP();
HTMLArea._stopEvent(ev);
}
break;
case 8:
case 46:
if(HTMLArea.is_gecko&&!ev.shiftKey){
if(this.dom_checkBackspace())
HTMLArea._stopEvent(ev);
}else if(HTMLArea.is_ie){
if(this.ie_checkBackspace())
HTMLArea._stopEvent(ev);
}
break;
}
}
if(editor._timerToolbar){
clearTimeout(editor._timerToolbar);
}
editor._timerToolbar=setTimeout(function(){
editor.updateToolbar();
editor._timerToolbar=null;
},250);
};
HTMLArea.prototype._selectionEmpty=function(sel)
{
if(!sel)return true;
if(HTMLArea.is_ie)
{
return this._createRange(sel).htmlText=='';
}
else if(typeof sel.isCollapsed!='undefined')
{
return sel.isCollapsed;
}
return true;
}
HTMLArea.prototype._activeElement=function(sel)
{
if(sel==null)return null;
if(this._selectionEmpty(sel))return null;
if(HTMLArea.is_ie)
{
if(sel.type.toLowerCase()=="control")
{
return sel.createRange().item(0);
}
else
{
var range=sel.createRange();
var p_elm=this.getParentElement(sel);
if(p_elm.innerHTML==range.htmlText)
{
return p_elm;
}
return null;
}
}
else
{
if(!sel.isCollapsed)
{
if(sel.anchorNode.childNodes.length>sel.anchorOffset&&sel.anchorNode.childNodes[sel.anchorOffset].nodeType==1)
{
return sel.anchorNode.childNodes[sel.anchorOffset];
}
else if(sel.anchorNode.nodeType==1)
{
return sel.anchorNode;
}
else
{
return sel.anchorNode.parentNode;
}
}
return null;
}
}
HTMLArea.removeFromParent=function(el)
{
if(!el.parentNode)return;
var pN=el.parentNode;
pN.removeChild(el);
return el;
}
HTMLArea.prototype.ie_checkBackspace=function(){
var sel=this._getSelection();
if(HTMLArea.is_ie&&sel.type=='Control')
{
var elm=this._activeElement(sel);
HTMLArea.removeFromParent(elm);
return true;
}
var range=this._createRange(sel);
var r2=range.duplicate();
r2.moveStart("character",-1);
var a=r2.parentElement();
if(a!=range.parentElement()&&
/^a$/i.test(a.tagName)){
r2.collapse(true);
r2.moveEnd("character",1);
r2.pasteHTML('');
r2.select();
return true;
}
};
HTMLArea.prototype.dom_checkBackspace=function(){
var self=this;
setTimeout(function(){
var sel=self._getSelection();
var range=self._createRange(sel);
var SC=range.startContainer;
var SO=range.startOffset;
var EC=range.endContainer;
var EO=range.endOffset;
var newr=SC.nextSibling;
if(SC.nodeType==3)
SC=SC.parentNode;
if(!/\S/.test(SC.tagName)){
var p=document.createElement("p");
while(SC.firstChild)
p.appendChild(SC.firstChild);
SC.parentNode.insertBefore(p,SC);
SC.parentNode.removeChild(SC);
var r=range.cloneRange();
r.setStartBefore(newr);
r.setEndAfter(newr);
r.extractContents();
sel.removeAllRanges();
sel.addRange(r);
}
},10);
};
HTMLArea.prototype.dom_checkInsertP=function(){
var p=this.getAllAncestors();
var block=null;
var body=this._doc.body;
for(var i=0;i<p.length;++i)
if(HTMLArea.isBlockElement(p[i])&&!/body|html/i.test(p[i].tagName)){
block=p[i];
break;
}
var sel=this._getSelection();
var range=this._createRange(sel);
if(!range.collapsed)
range.deleteContents();
sel.removeAllRanges();
var SC=range.startContainer;
var SO=range.startOffset;
var EC=range.endContainer;
var EO=range.endOffset;
if(SC==EC&&SC==body&&!SO&&!EO){
p=this._doc.createTextNode(" ");
body.insertBefore(p,body.firstChild);
range.selectNodeContents(p);
SC=range.startContainer;
SO=range.startOffset;
EC=range.endContainer;
EO=range.endOffset;
}
if(!block){
var r2=range.cloneRange();
r2.setStartBefore(SC);
r2.setEndAfter(EC);
r2.surroundContents(block=this._doc.createElement("p"));
range.setEndAfter(block);
range.setStart(block.firstChild,SO);
}else range.setEndAfter(block);
var df=range.extractContents();
if(!/\S/.test(block.innerHTML))
block.innerHTML="<br />";
p=df.firstChild;
if(!/\S/.test(p.innerHTML))
p.innerHTML="<br />";
if(/^\s*<br\s*\/?>\s*$/.test(p.innerHTML)&&/^h[1-6]$/i.test(p.tagName)){
df.appendChild(this.convertNode(p,"p"));
df.removeChild(p);
}
block.parentNode.insertBefore(df,block.nextSibling);
range.selectNodeContents(block.nextSibling);
range.collapse(true);
sel.addRange(range);
this.forceRedraw();
};
HTMLArea.prototype.getHTML=function(){
var html='';
switch(this._editMode){
case"wysiwyg":
{
if(!this.config.fullPage)
html=HTMLArea.getHTML(this._doc.body,false,this);
else
html=this.doctype+"\n"+HTMLArea.getHTML(this._doc.documentElement,true,this);
break;
}
case"textmode":
{
html=this._textArea.value;
break;
}
default:
{
alert("Mode <"+mode+"> not defined!");
return false;
}
}
return html;
};
HTMLArea.prototype.getInnerHTML=function(){
if(!this._doc.body)return'';
switch(this._editMode){
case"wysiwyg":
if(!this.config.fullPage)
html=this._doc.body.innerHTML;
else
html=this.doctype+"\n"+this._doc.documentElement.innerHTML;
break;
case"textmode":
html=this._textArea.value;
break;
default:
alert("Mode <"+mode+"> not defined!");
return false;
}
return html;
};
HTMLArea.prototype.setHTML=function(html){
switch(this._editMode)
{
case"wysiwyg":
{
if(!this.config.fullPage)
{
this._doc.body.innerHTML=html;
}
else
{
this._doc.setFullHTML(html);
}
}
break;
case"textmode":
{
this._textArea.value=html;
}
break;
default:
{
alert("Mode <"+mode+"> not defined!");
}
break;
}
return false;
};
HTMLArea.prototype.setDoctype=function(doctype){
this.doctype=doctype;
};
HTMLArea._object=null;
HTMLArea.cloneObject=function(obj){
if(!obj)return null;
var newObj=new Object;
if(obj.constructor.toString().indexOf("function Array(")==1){
newObj=obj.constructor();
}
if(obj.constructor.toString().indexOf("function Function(")==1){
newObj=obj;
}else for(var n in obj){
var node=obj[n];
if(typeof node=='object'){newObj[n]=HTMLArea.cloneObject(node);}
else{newObj[n]=node;}
}
return newObj;
};
HTMLArea.checkSupportedBrowser=function(){
if(HTMLArea.is_gecko){
if(navigator.productSub<20021201){
alert("You need at least Mozilla-1.3 Alpha.\n"+
"Sorry, your Gecko is not supported.");
return false;
}
if(navigator.productSub<20030210){
alert("Mozilla < 1.3 Beta is not supported!\n"+
"I'll try, though, but it might not work.");
}
}
return HTMLArea.is_gecko||HTMLArea.is_ie;
};
HTMLArea.prototype._getSelection=function(){
if(HTMLArea.is_ie){
return this._doc.selection;
}else{
return this._iframe.contentWindow.getSelection();
}
};
HTMLArea.prototype._createRange=function(sel){
if(HTMLArea.is_ie){
return sel.createRange();
}else{
this.focusEditor();
if(typeof sel!="undefined"){
try{
return sel.getRangeAt(0);
}catch(e){
return this._doc.createRange();
}
}else{
return this._doc.createRange();
}
}
};
HTMLArea._addEvent=function(el,evname,func){
if(HTMLArea.is_ie){
el.attachEvent("on"+evname,func);
}else{
el.addEventListener(evname,func,true);
if(!el.eventList)
el.eventList=[];
el.eventList[el.eventList.length]=[evname,func];
}
};
HTMLArea._addEvents=function(el,evs,func){
for(var i=evs.length;--i>=0;){
HTMLArea._addEvent(el,evs[i],func);
}
};
HTMLArea._removeEvent=function(el,evname,func){
if(HTMLArea.is_ie){
el.detachEvent("on"+evname,func);
}else{
el.removeEventListener(evname,func,true);
if(el.eventList)
{
var newList=[];
for(var i=0;i<el.eventList.length;i++)
{
if(el.eventList[i][0]==evname&&el.eventList[i][1]==func){}
else newList[newList.length]=el.eventList[i];
}
el.eventList=newList;
}
}
};
HTMLArea._removeEvents=function(el,evs,func){
for(var i=evs.length;--i>=0;){
HTMLArea._removeEvent(el,evs[i],func);
}
};
HTMLArea._stopEvent=function(ev){
if(HTMLArea.is_ie){
ev.cancelBubble=true;
ev.returnValue=false;
}else{
ev.preventDefault();
ev.stopPropagation();
}
};
HTMLArea._removeClass=function(el,className){
if(!(el&&el.className)){
return;
}
var cls=el.className.split(" ");
var ar=new Array();
for(var i=cls.length;i>0;){
if(cls[--i]!=className){
ar[ar.length]=cls[i];
}
}
el.className=ar.join(" ");
};
HTMLArea._addClass=function(el,className){
HTMLArea._removeClass(el,className);
el.className+=" "+className;
};
HTMLArea._hasClass=function(el,className){
if(!(el&&el.className)){
return false;
}
var cls=el.className.split(" ");
for(var i=cls.length;i>0;){
if(cls[--i]==className){
return true;
}
}
return false;
};
HTMLArea._blockTags=" body form textarea fieldset ul ol dl li div "+
"p h1 h2 h3 h4 h5 h6 quote pre table thead "+
"tbody tfoot tr td th iframe address blockquote";
HTMLArea.isBlockElement=function(el){
return(HTMLArea._blockTags.indexOf(" "+el.tagName.toLowerCase()+" ")!=-1);
};
HTMLArea._closingTags=" a abbr acronym address applet b bdo big blockquote button caption center cite code del dfn dir div dl em fieldset font form frameset h1 h2 h3 h4 h5 h6 i iframe ins kbd label legend map menu noframes noscript object ol optgroup pre q s samp script select small span strike strong style sub sup table textarea title tt u ul var ";
HTMLArea.needsClosingTag=function(el){
return(HTMLArea._closingTags.indexOf(" "+el.tagName.toLowerCase()+" ")!=-1);
};
HTMLArea.htmlEncode=function(str){
str=str.replace(/&/ig,"&amp;");
str=str.replace(/</ig,"&lt;");
str=str.replace(/>/ig,"&gt;");
str=str.replace(/\xA0/g,"&nbsp;");
str=str.replace(/\x22/g,"&quot;");
return str;
};
HTMLArea.getHTML=function(root,outputRoot,editor){
var html="";
if(root.nodeType==11){
var div=document.createElement("div");
var temp=root.insertBefore(div,root.firstChild);
for(j=temp.nextSibling;j;j=j.nextSibling){
temp.appendChild(j.cloneNode(true));
}
html+=temp.innerHTML.replace(/<[^\?!][^>]*>/gi,function(tag){return editor.cleanHTML(tag)});
}else{
var root_tag=(root.nodeType==1)?root.tagName.toLowerCase():'';
if(outputRoot){
html+="<"+root_tag+">";
}
html+=editor.getInnerHTML().replace(/<[^\?!][^>]*>/gi,function(tag){
if(!(editor.config.htmlRemoveTags&&editor.config.htmlRemoveTags.test(tag.replace(/<([^\s>\/]+)/,'$1'))))
return editor.cleanHTML(tag);
else return''});
if(HTMLArea.is_ie){
html=html.replace(/<li( [^>]*)?>/g,'</li><li$1>').
replace(/(<(ul|ol)[^>]*>)[\s\n]*<\/li>/g,'$1').
replace(/<\/li>([\s\n]*<\/li>)+/g,'<\/li>');
}
if(outputRoot){
html+="</"+root_tag+">";
}
html=HTMLArea.indent(html);
};
return html;
};
HTMLArea.getHTMLWrapper=function(root,outputRoot,editor,indent){
var html="";
switch(root.nodeType){
case 10:
case 6:
case 12:
break;
case 2:
break;
case 4:
html+=(HTMLArea.is_ie?('\n'+indent):'')+'<![CDATA['+root.data+']]>';
break;
case 5:
html+='&'+root.nodeValue+';';
break;
case 7:
html+=(HTMLArea.is_ie?('\n'+indent):'')+'<?'+root.target+' '+root.data+' ?>';
break;
case 1:
case 11:
case 9:
{
var closed;
var i;
var root_tag=(root.nodeType==1)?root.tagName.toLowerCase():'';
if(outputRoot)
outputRoot=!(editor.config.htmlRemoveTags&&editor.config.htmlRemoveTags.test(root_tag));
if(outputRoot){
closed=(!(root.hasChildNodes()||HTMLArea.needsClosingTag(root)));
html+="<"+root.tagName.toLowerCase();
var attrs=root.attributes;
for(i=0;i<attrs.length;++i){
var a=attrs.item(i);
if(!a.specified&&!(root.tagName.toLowerCase().match(/input|option/)&&a.nodeName=='value')){
continue;
}
var name=a.nodeName.toLowerCase();
var value;
if(name!="style"){
if(typeof root[a.nodeName]!="undefined"&&name!="href"&&name!="src"&&!/^on/.test(name)){
value=root[a.nodeName];
}else{
value=a.nodeValue;
if(HTMLArea.is_ie&&(name=="href"||name=="src")){
value=editor.stripBaseURL(value);
}
}
}else{
value=root.style.cssText;
}
html+=" "+name+'="'+HTMLArea.htmlEncode(value)+'"';
}
if(html!=""){
html+=closed?" />":">";
}
}
html+=editor.getInnerHTML().replace(/<[^>]*>/gi,function($1){return HTMLArea.prototype.cleanHTML($1,false)});
if(outputRoot&&!closed){
html+="</"+root.tagName.toLowerCase()+">";
}
html=HTMLArea.indent(html);
}
break;
case 3:
html=/^script|style$/i.test(root.parentNode.tagName)?root.data:HTMLArea.htmlEncode(root.data);
break;
case 8:
html="<!--"+root.data+"-->";
break;
}
return html;
};
HTMLArea.RegExpCache=[
new RegExp().compile(/<\s*\/?([^\s\/>]+)[\s*\/>]/gi),
new RegExp().compile(/(\S*\s*=\s*)?_moz[^=>]*(=\s*[^>]*)?/gi),
new RegExp().compile(/\s*=\s*(([^'"][^>\s]*)([>\s])|"([^"]+)"|'([^']+)')/g),
new RegExp().compile(/\/>/g),
new RegExp().compile(/<(br|hr|img|input|link|meta|param|embed)([^>]*)>/g),
new RegExp().compile(/(checked|compact|declare|defer|disabled|ismap|multiple|no(href|resize|shade|wrap)|readonly|selected)([\s>])/gi),
new RegExp().compile(/(="[^']*)'([^'"]*")/),
new RegExp().compile(/&(?=[^<]*>)/g),
new RegExp().compile(/<\s+/g),
new RegExp().compile(/\s+(\/)?>/g),
new RegExp().compile(/\s{2,}/g),
new RegExp().compile(/\s+([^=\s]+)(="[^"]+")/g),
new RegExp().compile(/(\S*\s*=\s*)?contenteditable[^=>]*(=\s*[^>\s\/]*)?/gi),
new RegExp().compile(/((href|src)=")([^\s]*)"/g),
new RegExp().compile(/<\/?(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|br|hr|img|embed|param|pre|script|html|head|body)[^>]*>/g),
new RegExp().compile(/<\/(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|html|head|body|script)( [^>]*)?>/g),
new RegExp().compile(/<(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|html|head|body|script)( [^>]*)?>/g),
new RegExp().compile(/<(br|hr|img|embed|param|pre)[^>]*>/g),
new RegExp().compile(/(^|<\/(pre|script)>)(\s|[^\s])*?(<(pre|script)[^>]*>|$)/g),
new RegExp().compile(/(<pre[^>]*>)(\s|[^\s])*?(<\/pre>)/g),
new RegExp().compile(/(^|<!--(\s|\S)*?-->)((\s|\S)*?)(?=<!--(\s|\S)*?-->|$)/g)
];
HTMLArea.prototype.cleanHTML=function(sHtml){
var c=HTMLArea.RegExpCache;
sHtml=sHtml.
replace(c[0],function(str){return str.toLowerCase();}).
replace(c[1],' ').
replace(c[12],' ').
replace(c[2],'="$2$4$5"$3').
replace(c[11],function(str,p1,p2){return' '+p1.toLowerCase()+p2;}).
replace(c[3],'>').
replace(c[9],'$1>').
replace(c[4],'<$1$2 />').
replace(c[5],'$1="$1"$3').
replace(c[6],'$1$2').
replace(c[8],'<').
replace(c[10],' ');
if(HTMLArea.is_ie&&c[13].test(sHtml)){
sHtml=sHtml.replace(c[13],'$1'+this.stripBaseURL(RegExp.$3)+'"');
};
if(this.config.only7BitPrintablesInURLs&&c[13].test(sHtml)){
sHtml=sHtml.replace(c[13],'$1'+RegExp.$3.replace(/([^!-~]+)/g,function(chr){return escape(chr);})+'"');
}
return sHtml;
};
HTMLArea.prototype.fixLists=function(sHtml){
sHtml=sHtml.replace(/<li([^>]*)>/g,'</li><li$1>').
replace(/(<(ul|ol)[^>]*>)[\s\n]*<\/li>/g,'$1').
replace(/<\/li>([\s\n]*<\/li>)+/g,'<\/li>')
return sHtml;
}
HTMLArea.indent=function(s,sindentChar){
HTMLArea.__nindent=0;
HTMLArea.__sindent="";
HTMLArea.__sindentChar=(typeof sindentChar=="undefined")?"  ":sindentChar;
var c=HTMLArea.RegExpCache;
if(HTMLArea.is_gecko){
s=s.replace(c[19],function(str){return str.replace(/<br \/>/g,"\n")});
}
s=s.replace(c[20],function(st,$1,$2,$3){
strn=$3.replace(c[18],function(string){
string=string.replace(/[\n\r]/gi," ").replace(/\s+/gi," ").replace(c[14],function(str){
if(str.match(c[16])){
var s="\n"+HTMLArea.__sindent+str;
HTMLArea.__sindent+=HTMLArea.__sindentChar;
++HTMLArea.__nindent;
return s;
}else if(str.match(c[15])){
--HTMLArea.__nindent;
HTMLArea.__sindent="";
for(var i=HTMLArea.__nindent;i>0;--i){
HTMLArea.__sindent+=HTMLArea.__sindentChar;
}
return"\n"+HTMLArea.__sindent+str;
}else if(str.match(c[17])){
return"\n"+HTMLArea.__sindent+str;
}
return str;
});
return string;
});return $1+strn;
});
if(s.charAt(0)=="\n"){
return s.substring(1,s.length);
}
s=s.replace(/ *\n/g,'\n');
return s;
};
HTMLArea.prototype.stripBaseURL=function(string){
var baseurl=this.config.baseURL;
baseurl=baseurl.replace(/[^\/]+$/,'');
var basere=new RegExp(baseurl);
string=string.replace(basere,"");
baseurl=baseurl.replace(/^(https?:\/\/[^\/]+)(.*)$/,'$1');
basere=new RegExp(baseurl);
return string.replace(basere,"");
};
String.prototype.trim=function(){
return this.replace(/^\s+/,'').replace(/\s+$/,'');
};
HTMLArea._makeColor=function(v){
if(typeof v!="number"){
return v;
}
var r=v&0xFF;
var g=(v>>8)&0xFF;
var b=(v>>16)&0xFF;
return"rgb("+r+","+g+","+b+")";
};
HTMLArea._colorToRgb=function(v){
if(!v)
return'';
function hex(d){
return(d<16)?("0"+d.toString(16)):d.toString(16);
};
if(typeof v=="number"){
var r=v&0xFF;
var g=(v>>8)&0xFF;
var b=(v>>16)&0xFF;
return"#"+hex(r)+hex(g)+hex(b);
}
if(v.substr(0,3)=="rgb"){
var re=/rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/;
if(v.match(re)){
var r=parseInt(RegExp.$1);
var g=parseInt(RegExp.$2);
var b=parseInt(RegExp.$3);
return"#"+hex(r)+hex(g)+hex(b);
}
return null;
}
if(v.substr(0,1)=="#"){
return v;
}
return null;
};
HTMLArea.prototype._popupDialogml=function(url,action,init){
Dialog(this.popupURLml(url),action,init);
};
HTMLArea.prototype._popupDialog=function(url,action,init){
Dialog(this.popupURL(url),action,init);
};
HTMLArea.prototype.imgURL=function(file,plugin){
if(typeof plugin=="undefined")
return _editor_url+file;
else
return _editor_url+"plugins/"+plugin+"/img/"+file;
};
HTMLArea.prototype.popupURL=function(file){
var url="";
if(file.match(/^plugin:\/\/(.*?)\/(.*)/)){
var plugin=RegExp.$1;
var popup=RegExp.$2;
if(!/\.html$/.test(popup))
popup+=".html";
url=_editor_url+"plugins/"+plugin+"/popups/"+popup;
}else
url=_editor_url+this.config.popupURL+file;
return url;
};
HTMLArea.prototype.popupURLml=function(file){
var url="";
if(file.match(/^plugin:\/\/(.*?)\/(.*)/)){
var plugin=RegExp.$1;
var popup=RegExp.$2;
if(!/\.html$/.test(popup))
popup+=".html";
url=_editor_url+"plugins/"+plugin+"/popups/lang/"+_editor_lang+"/"+popup;
}else
url=_editor_url+this.config.popupURLml+file;
return url;
};
HTMLArea.prototype._toggleBorders=function()
{
tables=this._doc.getElementsByTagName('TABLE');
if(tables.length!=0)
{
if(!this.borders)
{
name="bordered";
this.borders=true;
}
else
{
name="";
this.borders=false;
}
for(var ix=0;ix<tables.length;ix++)
{
if(this.borders)
{
if(HTMLArea.is_gecko)
{
tables[ix].style.display="none";
tables[ix].style.display="table";
}
HTMLArea._addClass(tables[ix],'htmtableborders');
}
else
{
HTMLArea._removeClass(tables[ix],'htmtableborders');
}
}
}
return true;
}
HTMLArea.addClasses=function(el,classes)
{
if(el!=null)
{
var thiers=el.className.trim().split(' ');
var ours=classes.split(' ');
for(var x=0;x<ours.length;x++)
{
var exists=false;
for(var i=0;exists==false&&i<thiers.length;i++)
{
if(thiers[i]==ours[x])
{
exists=true;
}
}
if(exists==false)
{
thiers[thiers.length]=ours[x];
}
}
el.className=thiers.join(' ').trim();
}
}
HTMLArea.removeClasses=function(el,classes)
{
var existing=el.className.trim().split();
var new_classes=[];
var remove=classes.trim().split();
for(var i=0;i<existing.length;i++)
{
var found=false;
for(var x=0;x<remove.length&&!found;x++)
{
if(existing[i]==remove[x])
{
found=true;
}
}
if(!found)
{
new_classes[new_classes.length]=existing[i];
}
}
return new_classes.join(' ');
}
HTMLArea.addClass=HTMLArea._addClass;
HTMLArea.removeClass=HTMLArea._removeClass;
HTMLArea._addClasses=HTMLArea.addClasses;
HTMLArea._removeClasses=HTMLArea.removeClasses;
HTMLArea.getElementById=function(tag,id){
var el,i,objs=document.getElementsByTagName(tag);
for(i=objs.length;--i>=0&&(el=objs[i]);)
if(el.id==id)
return el;
return null;
};
function GetValues(obj)
{
var i=0;var j=0;
var res='Objekt: '+obj+'\n\n';
for(temp in obj)
{
res+=temp+': '+obj[temp]+'\n';
i=i+1;
if(i==5){
alert(res);
res='';
i=0;
}
}
}
