var whizzywig_version='Whizzywig 63';
var btn=[]; //object containing button strip information
btn._w=16; btn._h=16; btn._f=getDir()+"icons.png"; //set to path to toolbar image
var buttonPath, //path to custom toolbar button images; "textbuttons" means don't use images
buttonExt, //extension (e.g. .png) for toolbar button images; default '.gif'
cssFile, //url of CSS stylesheet to attach to edit area
imageBrowse, //path to page for image browser
linkBrowse, //path to page for link browser
idTa, //id of the textarea (param to makeWhizzyWig)
//OTHER GLOBALS //Whizzy contentWindow, current sel, range, parent, DOM path, popwindow, window, IE?;
oW, sel, rng, papa, trail, ppw, wn=window, msIE=("Microsoft Internet Explorer"==navigator.appName)
sels='',buts='',vals=[],opts=[],dobut=[],whizzies=[],taOrigSize=[];
function makeWhizzyWig(txtArea, controls){ // make a WhizzyWig from the textarea
idTa=txtArea;
whizzies[whizzies.length]=idTa;
if (!document.designMode) {
if (idTa.nodeName=="TEXTAREA"){tagButs();}
alert("Whizzywig "+t("editor not available for your browser"));
return;
}
var taContent=o(idTa).defaultValue ? o(idTa).defaultValue : o(idTa).innerHTML ? o(idTa).innerHTML: ''; //anything in the textarea?
if (!o(idTa).rows < 5){o(idTa).rows='15';}//IE won't use % from style
taWidth=o(idTa).style.width ? o(idTa).style.width : o(idTa).cols + "ex"; //grab the width and...
taHeight=o(idTa).style.height ? o(idTa).style.height : o(idTa).rows + "em"; //...height from the textarea
taOrigSize[idTa] = {w:taWidth,h:taHeight};
//Create whizzy container
var wContainer = document.createElement('div');
wContainer.id = 'CONTAINER'+idTa+'';
wContainer.style.width = taWidth;
var taObject = o(idTa);
o(idTa).parentNode.replaceChild(wContainer, o(idTa));
o("CONTAINER"+idTa).appendChild(taObject);
//End whizzy container
if (o(idTa).nodeName=="TEXTAREA"){
o(idTa).style.color='#060';
o(idTa).style.zIndex='2';
}else{w('<input type="hidden" id="wzhid_'+idTa+'" name="'+idTa+'" />')}
h(idTa);
var frm=o(idTa).parentNode;
while(frm.nodeName != 'FORM'){frm=frm.parentNode}//if not form, keep trying
addEvt(frm,"submit",syncTextarea);
w('<style type="text/css">button {vertical-align:middle;padding:0;margin:1px 0} button img{vertical-align:middle;margin:-1px} select{vertical-align:middle;margin:1px} .wzCtrl {background:ButtonFace; border:1px outset ButtonShadow; padding:5px;} #sourceTa{color:#060;font-family:mono;}</style>');
var dsels='formatblock fontname fontsize';
var dbuts=' bold italic underline | left center right justify | number bullet indent outdent | undo redo | color hilite rule | link image table | clean html spellcheck fullscreen ';
var tbuts=' tstart add_row_above add_row_below delete_row | add_column_before add_column_after delete_column | table_in_cell';
var t_end=''; //table controls end, if needed
btns=(dbuts+tbuts).split(' ');
for (var i=0,pos=0;i<btns.length;i++) {
if(btns[i] && btns[i]!='|' && btns[i]!='tstart'){btn[btns[i]]=btn._w*pos++}
}
controls=controls ? controls.toLowerCase() : "all";
if(controls == "all"){controls=dsels +' newline '+ buts + dbuts + tbuts}
else{controls += tbuts}
w('<div onmouseover="c(\''+idTa+'\')"><div id="CONTROLS'+idTa+'" class="wzCtrl" unselectable="on">');
gizmos=controls.split(' ');
for (i=0;i<gizmos.length;i++){
if (gizmos[i]){ //make buttons and selects for toolbar, in order requested
if (gizmos[i] == 'tstart') {
w('<div id="TABLE_CONTROLS'+idTa+'" style="display:none" unselectable="on">');
t_end='</div>';
}
else if(gizmos[i]=='|'){w(' <big style="padding-bottom:2em">|</big> ')}
else if(gizmos[i] == 'newline'){w('<br>')}
else if((dsels+sels).indexOf(gizmos[i]) != -1){makeSelect(gizmos[i])}
else if((dbuts+buts+tbuts).indexOf(gizmos[i]) != -1){makeButton(gizmos[i])}
}
}
w(t_end)//table controls end
w('<a href="http://www.unverse.net" style="color:buttonface" title="'+whizzywig_version+'">.</a> ');
w(fGo('LINK'));
if (linkBrowse){w('<input type="button" onclick=doWin("'+linkBrowse+'"); value="'+t("Browse")+'"> ')}
w(t('Link address (URL)')+': <input type="text" id="lf_url'+idTa+'" size="60"><br><input type="button" value="http://" onclick="o(\'lf_url'+idTa+'\').value=\'http://\'+o(\'lf_url'+idTa+'\').value"> <input type="button" value="mailto:" onclick="o(\'lf_url'+idTa+'\').value=\'mailto:\'+o(\'lf_url'+idTa+'\').value"><input type="checkbox" id="lf_new'+idTa+'">'+t("Open link in new window")+fNo(t("OK"),"insertLink()"));//LINK_FORM end
w(fGo('IMAGE'));
if(imageBrowse){w('<input type="button" onclick=doWin("'+imageBrowse+'"); value="'+t("Browse")+'"> ')}
w(t('Image address (URL)')+': <input type="text" id="if_url'+idTa+'" size="50"> <label title='+t("to display if image unavailable")+'><br>'+t("Alternate text")+':<input id="if_alt'+idTa+'" type="text" size="50"></label><br>'+t("Align")+':<select id="if_side'+idTa+'"><option value="none">_♥_ '+t("normal")+'</option><option value="left">♥= '+t("left")+'</option><option value="right">=♥ '+t("right")+'</option></select> '+t("Border")+':<input type="text" id="if_border'+idTa+'" size="20" value="0" title="'+t("number or CSS e.g. 3px maroon outset")+'"> '+t("Margin")+':<input type="text" id="if_margin'+idTa+'" size="20" value="0" title="'+t("number or CSS e.g. 5px 1em")+'">'+fNo(t("Insert Image"),"insertImage()"));//IMAGE_FORM end
w(fGo('TABLE')+t("Rows")+':<input type="text" id="tf_rows'+idTa+'" size="2" value="3"> <select id="tf_head'+idTa+'"><option value="0">'+t("No header row")+'</option><option value="1">'+t("Include header row")+'</option></select> '+t("Columns")+':<input type="text" id="tf_cols'+idTa+'" size="2" value="3"> '+t("Border width")+':<input type="text" id="tf_border'+idTa+'" size="2" value="1"> '+fNo(t("Insert Table"),"makeTable()"));//TABLE_FORM end
w(fGo('COLOR')+'<input type="hidden" id="cf_cmd'+idTa+'"><div style="background:#000;padding:1px;height:22px;width:125px;float:left"><div id="cPrvw'+idTa+'" style="background-color:red; height:100%; width:100%"></div></div> <input type=text id="cf_color'+idTa+'" value="red" size=17 onpaste=vC(value) onblur=vC(value)> <input type="button" onmouseover=vC() onclick=sC() value="'+t("OK")+'"> <input type="button" onclick="hideDialogs();" value="'+t("Cancel")+'"><br> '+t("click below or enter a")+' <a href="http://www.unverse.net/colortable.htm" target="_blank">'+t("color name")+'</a><br clear=all> <table border=0 cellspacing=1 cellpadding=0 width=480 bgcolor="#000000">'+"\n");
var wC=new Array("00","33","66","99","CC","FF") //color table
for (i=0; i<wC.length; i++){
w("<tr>");
for (j=0; j<wC.length; j++){
for (k=0; k<wC.length; k++){
var clr=wC[i]+wC[j]+wC[k];
w(' <td style="background:#'+clr+';height:12px;width:12px" onmouseover=vC("#'+clr+'") onclick=sC("#'+clr+'")></td>'+"\n");
}
}
w('</tr>');
}
w("</table></div>\n"); //end color table,COLOR_FORM
w("</div>\n"); //controls end
w('<div class="wzCtrl" id="showWYSIWYG'+idTa+'" style="display:none"><input type="button" onclick="showDesign();" value="'+t("Hide HTML")+'">');
tagButs();
w('</div>'+"\n");
w('<iframe style="border:1px inset ButtonShadow;width:100%;height:'+taHeight+'" src="javascript:;" id="whizzy'+idTa+'"></iframe></div>'+"\n", true); //finally write content to whizzy container
var startHTML="<html>\n<head>\n<style>td,th{border:1px dotted #888}</style>\n";
if(cssFile){startHTML += '<link media="all" type="text/css" href="'+cssFile+'" rel="stylesheet">\n'}
startHTML += '</head>\n<body id="'+idTa+'" style="background-image:none">\n'+tidyD(taContent)+'</body>\n</html>';
oW=o("whizzy"+idTa).contentWindow;
var d=oW.document;
try{d.designMode="on";} catch(e){ setTimeout('oW.designMode="on";', 100);}
d.open(); d.write(startHTML); d.close();
if(oW.addEventListener){oW.addEventListener("keypress", kb_handler, true)}//keyboard shortcuts for Moz
else{d.body.attachEvent("onpaste",function(){setTimeout('cleanUp()',10)})}
addEvt(d,"mouseup", whereAmI); addEvt(d,"keyup", whereAmI); addEvt(d,"dblclick", doDbl);
//move textarea so html menu appears on top
taObject = o(idTa);
o("CONTAINER"+idTa).removeChild(o(idTa));
o("CONTAINER"+idTa).appendChild(taObject);
//end move
idTa=null;
} //end makeWhizzyWig
function whizzywig(controls){
var i,ta=document.getElementsByTagName('TEXTAREA');
for (i=0;i<ta.length;i++){
if(!ta[i].id){ta[i].id=ta.name}
makeWhizzyWig(ta[i].id,controls);
}
}