// control registration array
var spaw_editors = new Array();
// returns true if editor is already registered
function SPAW_editor_registered(editor)
{
var found = false;
for(i=0;i'+this[editor+'_rEdit'].document.body.innerHTML+'
';
else
this[editor+'_rEdit'].document.body.innerHTML = ''+this[editor+'_rEdit'].document.body.innerHTML+'
';
}
sender.selectedIndex = 0;
SPAW_update_toolbar(editor, true);
}
function SPAW_font_change(editor, sender)
{
fontname = sender.options[sender.selectedIndex].value;
window.frames[editor+'_rEdit'].focus();
this[editor+'_rEdit'].document.execCommand('fontname', false, fontname);
sender.selectedIndex = 0;
SPAW_update_toolbar(editor, true);
}
function SPAW_fontsize_change(editor, sender)
{
fontsize = sender.options[sender.selectedIndex].value;
window.frames[editor+'_rEdit'].focus();
this[editor+'_rEdit'].document.execCommand('fontsize', false, fontsize);
sender.selectedIndex = 0;
SPAW_update_toolbar(editor, true);
}
function SPAW_paragraph_change(editor, sender)
{
format = sender.options[sender.selectedIndex].value;
window.frames[editor+'_rEdit'].focus();
this[editor+'_rEdit'].document.execCommand('formatBlock', false, format);
sender.selectedIndex = 0;
SPAW_update_toolbar(editor, true);
}
function SPAW_table_create_click(editor, sender)
{
if (window.frames[editor+'_rEdit'].document.selection.type != "Control")
{
// selection is not a control => insert table
var nt = showModalDialog('dialogs/table.php?lang=' + document.all['SPAW_'+editor+'_lang'].value + '&theme=' + document.all['SPAW_'+editor+'_theme'].value, null,
'dialogHeight:250px; dialogWidth:366px; resizable:no; status:no');
if (nt)
{
window.frames[editor+'_rEdit'].focus();
var newtable = document.createElement('TABLE');
try {
newtable.width = (nt.width)?nt.width:'';
newtable.height = (nt.height)?nt.height:'';
newtable.border = (nt.border)?nt.border:'';
if (nt.cellPadding) newtable.cellPadding = nt.cellPadding;
if (nt.cellSpacing) newtable.cellSpacing = nt.cellSpacing;
newtable.bgColor = (nt.bgColor)?nt.bgColor:'';
// create rows
for (i=0;i 1)
{
// increase rowspan
cr.cells(i).rowSpan++;
}
else
{
var newc = cr.cells(i).cloneNode();
newr.appendChild(newc);
}
}
// increase rowspan for cells that were spanning through current row
for (i=0; i (cr.rowIndex - i))
tempr.cells(j).rowSpan++;
}
}
}
SPAW_update_toolbar(editor, true);
} // insertRow
function SPAW_formCellMatrix(ct)
{
var tm = new Array();
for (i=0; i 1)
{
ct.rows(i).cells(tm[i][realIndex]).colSpan++;
}
else
{
var newc = ct.rows(i).insertCell(tm[i][realIndex]+1)
var nc = ct.rows(i).cells(tm[i][realIndex]).cloneNode();
newc.replaceNode(nc);
}
}
}
}
SPAW_update_toolbar(editor, true);
} // insertColumn
function SPAW_table_cell_merge_right_click(editor, sender)
{
var ct = SPAW_getTable(editor); // current table
var cr = SPAW_getTR(editor); // current row
var cd = SPAW_getTD(editor); // current row
if (cd && cr && ct)
{
// get "real" cell position and form cell matrix
var tm = SPAW_formCellMatrix(ct);
for (j=0; j0 && (tm[cr.rowIndex+ccrs][crealIndex-1]!=tm[cr.rowIndex+ccrs][crealIndex]))))
{
ncrs = ct.rows(cr.rowIndex+ccrs).cells(ncellIndex).rowSpan?ct.rows(cr.rowIndex+ccrs).cells(ncellIndex).rowSpan:1;
nccs = ct.rows(cr.rowIndex+ccrs).cells(ncellIndex).colSpan?ct.rows(cr.rowIndex+ccrs).cells(ncellIndex).colSpan:1;
// proceed only if current and next cell colspans are equal
if (cccs == nccs)
{
// increase rowspan of current cell and append content of the next cell to current
cd.innerHTML += ct.rows(cr.rowIndex+ccrs).cells(ncellIndex).innerHTML;
ct.rows(cr.rowIndex+ccrs).deleteCell(ncellIndex);
cd.rowSpan = ccrs+ncrs;
}
}
}
}
SPAW_update_toolbar(editor, true);
} // mergeDown
function SPAW_table_row_delete_click(editor, sender)
{
var ct = SPAW_getTable(editor); // current table
var cr = SPAW_getTR(editor); // current row
var cd = SPAW_getTD(editor); // current cell
if (cd && cr && ct)
{
// if there's only one row just remove the table
if (ct.rows.length<=1)
{
ct.removeNode(true);
}
else
{
// get "real" cell position and form cell matrix
var tm = SPAW_formCellMatrix(ct);
// decrease rowspan for cells that were spanning through current row
for (i=0; i (cr.rowIndex - i))
tempr.cells(j).rowSpan--;
}
}
curCI = -1;
// check for current row cells spanning more than 1 row
for (i=0; i1 && (cr.rowIndex+1)1)?cr.cells(curCI).colSpan:1;
for (j=i; j<(i+cs);j++)
{
tm[cr.rowIndex+1][j] = nrCI;
nj = j;
}
for (j=nj; j1)
ct.rows(i).cells(tm[i][realIndex]).colSpan--;
else
ct.rows(i).deleteCell(tm[i][realIndex]);
}
}
}
}
SPAW_update_toolbar(editor, true);
} // deleteColumn
// split cell horizontally
function SPAW_table_cell_split_horizontal_click(editor, sender)
{
var ct = SPAW_getTable(editor); // current table
var cr = SPAW_getTR(editor); // current row
var cd = SPAW_getTD(editor); // current cell
if (cd && cr && ct)
{
// get "real" cell position and form cell matrix
var tm = SPAW_formCellMatrix(ct);
for (j=0; j1)
{
// split only current cell
// find where to insert a cell in the next row
i = realIndex;
while (tm[cr.rowIndex+1][i] == -1) i++;
if (i == tm[cr.rowIndex+1].length)
ni = ct.rows(cr.rowIndex+1).cells.length;
else
ni = tm[cr.rowIndex+1][i];
var newc = ct.rows(cr.rowIndex+1).insertCell(ni);
cd.rowSpan--;
var nc = cd.cloneNode();
newc.replaceNode(nc);
cd.rowSpan = 1;
}
else
{
// add new row and make all other cells to span one row more
ct.insertRow(cr.rowIndex+1);
for (i=0; i1?cr.cells(i).rowSpan:1;
cr.cells(i).rowSpan = rs+1;
}
}
for (i=0; i (cr.rowIndex - i))
tempr.cells(j).rowSpan++;
}
}
// clone current cell to new row
var newc = ct.rows(cr.rowIndex+1).insertCell(0);
var nc = cd.cloneNode();
newc.replaceNode(nc);
}
}
SPAW_update_toolbar(editor, true);
} // splitH
function SPAW_table_cell_split_vertical_click(editor, sender)
{
var ct = SPAW_getTable(editor); // current table
var cr = SPAW_getTR(editor); // current row
var cd = SPAW_getTD(editor); // current cell
if (cd && cr && ct)
{
// get "real" cell position and form cell matrix
var tm = SPAW_formCellMatrix(ct);
for (j=0; j1)
{
// split only current cell
var newc = ct.rows(cr.rowIndex).insertCell(cd.cellIndex+1);
cd.colSpan--;
var nc = cd.cloneNode();
newc.replaceNode(nc);
cd.colSpan = 1;
}
else
{
// clone current cell
var newc = ct.rows(cr.rowIndex).insertCell(cd.cellIndex+1);
var nc = cd.cloneNode();
newc.replaceNode(nc);
for (i=0; i1?ct.rows(i).cells(tm[i][realIndex]).colSpan:1;
ct.rows(i).cells(tm[i][realIndex]).colSpan = cs+1;
}
}
}
}
SPAW_update_toolbar(editor, true);
} // splitV
// switch to wysiwyg mode
function SPAW_design_tab_click(editor, sender)
{
//iText = this[editor+'_rEdit'].document.body.innerText;
iText = document.all[editor].value;
this[editor+'_rEdit'].document.body.innerHTML = iText;
document.all['SPAW_'+editor+'_editor_mode'].value = 'design';
// turn off html mode toolbars
document.all['SPAW_'+editor+'_toolbar_top_html'].style.display = 'none';
document.all['SPAW_'+editor+'_toolbar_left_html'].style.display = 'none';
document.all['SPAW_'+editor+'_toolbar_right_html'].style.display = 'none';
document.all['SPAW_'+editor+'_toolbar_bottom_html'].style.display = 'none';
// turn on design mode toolbars
document.all['SPAW_'+editor+'_toolbar_top_design'].style.display = 'inline';
document.all['SPAW_'+editor+'_toolbar_left_design'].style.display = 'inline';
document.all['SPAW_'+editor+'_toolbar_right_design'].style.display = 'inline';
document.all['SPAW_'+editor+'_toolbar_bottom_design'].style.display = 'inline';
// switch editors
document.all[editor].style.display = "none";
document.all[editor+"_rEdit"].style.display = "inline";
document.all[editor+"_rEdit"].document.body.focus();
// turn on invisible borders if needed
SPAW_toggle_borders(editor,this[editor+'_rEdit'].document.body, null);
this[editor+'_rEdit'].focus();
SPAW_update_toolbar(editor, true);
}
// switch to html mode
function SPAW_html_tab_click(editor, sender)
{
iHTML = this[editor+'_rEdit'].document.body.innerHTML;
//this[editor+'_rEdit'].document.body.innerText = iHTML;
document.all[editor].value = iHTML;
document.all['SPAW_'+editor+'_editor_mode'].value = 'html';
// turn off design mode toolbars
document.all['SPAW_'+editor+'_toolbar_top_design'].style.display = 'none';
document.all['SPAW_'+editor+'_toolbar_left_design'].style.display = 'none';
document.all['SPAW_'+editor+'_toolbar_right_design'].style.display = 'none';
document.all['SPAW_'+editor+'_toolbar_bottom_design'].style.display = 'none';
// turn on html mode toolbars
document.all['SPAW_'+editor+'_toolbar_top_html'].style.display = 'inline';
document.all['SPAW_'+editor+'_toolbar_left_html'].style.display = 'inline';
document.all['SPAW_'+editor+'_toolbar_right_html'].style.display = 'inline';
document.all['SPAW_'+editor+'_toolbar_bottom_html'].style.display = 'inline';
// switch editors
document.all[editor+"_rEdit"].style.display = "none";
document.all[editor].style.display = "inline";
document.all[editor].focus();
this[editor+'_rEdit'].focus();
SPAW_update_toolbar(editor, true);
}
function SPAW_getFieldByEditor(editor, field)
{
var thefield;
// get field by editor name if no field passed
if (field == null || field == "")
{
var flds = document.getElementsByName(editor);
thefield = flds[0].id;
}
else
{
thefield=field;
}
return thefield;
}
function SPAW_getHtmlValue(editor, thefield)
{
var htmlvalue;
if(document.all['SPAW_'+editor+'_editor_mode'].value == 'design')
{
// wysiwyg
htmlvalue = this[editor+'_rEdit'].document.body.innerHTML;
}
else
{
// code
htmlvalue = document.all[thefield].value;
}
return htmlvalue;
}
function SPAW_updateField(editor, field)
{
var thefield = SPAW_getFieldByEditor(editor, field);
var htmlvalue = SPAW_getHtmlValue(editor, thefield);
if (document.all[thefield].value != htmlvalue)
{
// something changed
document.all[thefield].value = htmlvalue;
}
}
function SPAW_confirm(editor,block,message) {
return showModalDialog('dialogs/confirm.php?lang=' + document.all['SPAW_'+editor+'_lang'].value + '&theme=' + document.all['SPAW_'+editor+'_theme'].value + '&block=' + block + '&message=' + message, null, 'dialogHeight:100px; dialogWidth:300px; resizable:no; status:no');
}
// cleanup html
function SPAW_cleanup_click(editor, sender)
{
if (SPAW_confirm(editor,'cleanup','confirm'))
{
window.frames[editor+'_rEdit'].focus();
var found = true;
while (found)
{
found = false;
var els = window.frames[editor+'_rEdit'].document.body.all;
for (i=0; i= 33 && eobj.event.keyCode<=40))
{
SPAW_update_toolbar(editor, false);
}
}
var spaw_context_html = "";
// update active toolbar state
function SPAW_update_toolbar(editor, force)
{
//window.frames[editor+'_rEdit'].focus();
var pt = SPAW_getParentTag(editor);
if (pt)
{
if (pt.outerHTML == spaw_context_html && !force)
{
return;
}
else
{
spaw_context_html = pt.outerHTML;
}
}
// button sets
table_row_items = [
"table_row_insert",
"table_row_delete"
];
table_cell_items = [
"table_cell_prop",
"table_column_insert",
"table_column_delete",
"table_cell_merge_right",
"table_cell_merge_down",
"table_cell_split_horizontal",
"table_cell_split_vertical"
];
table_obj_items = [
"table_prop"
];
img_obj_items = [
"image_prop"
];
standard_cmd_items = [ // command, control id
["cut", "cut"],
["copy", "copy"],
["paste", "paste"],
["undo", "undo"],
["redo", "redo"],
["bold", "bold"],
["italic", "italic"],
["underline", "underline"],
["justifyleft", "left"],
["justifycenter", "center"],
["justifyright", "right"],
["indent", "indent"],
["outdent", "unindent"],
["forecolor", "fore_color"],
["backcolor", "bg_color"],
["insertorderedlist", "ordered_list"],
["insertunorderedlist", "bulleted_list"],
["createlink", "hyperlink"],
["inserthorizontalrule","hr"]
];
togglable_items = [ // command, control id
["bold", "bold"],
["italic", "italic"],
["underline", "underline"],
["justifyleft", "left"],
["justifycenter", "center"],
["justifyright", "right"],
["insertorderedlist", "ordered_list"],
["insertunorderedlist", "bulleted_list"],
["createlink", "hyperlink"],
["inserthorizontalrule","hr"]
];
standard_dropdowns = [ // command, control id
["fontname", "font"],
["fontsize", "fontsize"],
["formatblock", "paragraph"]
];
// proceed only if active toolbar is enabled
if (!spaw_active_toolbar) return;
//window.frames[editor+'_rEdit'].focus();
// get object references
var eobj = window.frames[editor+'_rEdit']; // editor iframe
var edoc = eobj.document; // editor docutment
// enable image insert
SPAW_toggle_tbi(editor,"image_insert", true);
// enable table insert
SPAW_toggle_tbi(editor,"table_create", true);
// toggle table buttons
// get table
var ct = SPAW_getTable(editor);
if (ct)
{
// table found
// enable table properties
SPAW_toggle_tb_items(editor,table_obj_items, true);
// get table row
var cr = SPAW_getTR(editor);
if (cr)
{
// enable table row features
SPAW_toggle_tb_items(editor,table_row_items, true);
// get table cell
var cd = SPAW_getTD(editor);
if (cd)
{
// enable cell features
SPAW_toggle_tb_items(editor,table_cell_items, true);
}
else
{
// disable cell features
SPAW_toggle_tb_items(editor,table_cell_items, false);
// disable image insert
SPAW_toggle_tbi(editor,"image_insert", false);
}
}
else
{
// disable table row and cell features
SPAW_toggle_tb_items(editor,table_cell_items, false);
SPAW_toggle_tb_items(editor,table_row_items, false);
// disable image insert
SPAW_toggle_tbi(editor,"image_insert", false);
}
}
else
{
// disable all available table related buttons
SPAW_toggle_tb_items(editor,table_obj_items, false);
SPAW_toggle_tb_items(editor,table_row_items, false);
SPAW_toggle_tb_items(editor,table_cell_items, false);
}
// end table buttons
// image buttons
// get image
var im = SPAW_getImg(editor);
if (im)
{
// enable image buttons
SPAW_toggle_tb_items(editor,img_obj_items, true);
// disable table insert
SPAW_toggle_tbi(editor,"table_create", false);
}
else
{
// disable image buttons
SPAW_toggle_tb_items(editor,img_obj_items, false);
}
// end image buttons
// set state and enable/disable standard command buttons
for (i=0; i http://www.interactivetools.com/iforum/Open_Source_C3/htmlArea_v3.0_-_Beta_Release_F14/v3_Word_Cleaner_%26_questions_P16103/ )
// Word Clean Function v1.0.4;
function wordClean(wordData)
{
// Format data for cleanup
wordData = wordData.replace(/[\n]+|\ \;| [ ]*/g, ' ');
if ((wordData.indexOf('class=Mso')>=0) | (wordData.indexOf('class="Mso')>=0))
{
// kill unwanted tags
wordData = wordData.replace(/<\?xml:[^>]*>/g,''); // Word xml
wordData = wordData.replace(/<\/?st1:[^>]*>/g,''); // Word SmartTags
wordData = wordData.replace(/<\/?[a-z]\:[^>]*>/g,''); // All other funny Word non-HTML stuff
wordData = wordData.replace(/<\/?(span|div)[^>]*>/gi,'');
wordData = wordData.replace(/<\/?font[^>]*>/gi,''); // Disable if you want to keep font formatting
wordData = wordData.replace(/