codice:
document.write('<style type="text/css">\n');
document.write('.btn { width: 22px; height: 22px; border: 1px solid buttonface; margin: 0; padding: 0; }\n');
document.write('.btnOver { width: 22px; height: 22px; border: 1px outset; }\n');
document.write('.btnDown { width: 22px; height: 22px; border: 1px inset; background-color: buttonhighlight; }\n');
document.write('.btnNA { width: 22px; height: 22px; border: 1px solid buttonface; filter: alpha(opacity=25); }\n');
document.write('.cMenu { background-color: threedface; color: menutext; cursor: Default; font-family: MS Sans Serif; font-size: 8pt; padding: 2 12 2 16; }');
document.write('.cMenuOver { background-color: highlight; color: highlighttext; cursor: Default; font-family: MS Sans Serif; font-size: 8pt; padding: 2 12 2 16; }');
document.write('.cMenuDivOuter { background-color: threedface; height: 9 }');
document.write('.cMenuDivInner { margin: 0 4 0 4; border-width: 1; border-style: solid; border-color: threedshadow threedhighlight threedhighlight threedshadow; }');
document.write('</style>\n');
function editor_defaultConfig(objname) {
this.version = "2.03"
this.width = "auto";
this.height = "auto";
this.bodyStyle = 'background-color: #FFFFFF; font-family: "Verdana"; font-size: x-small;';
this.imgURL = _editor_url + 'images/';
this.debug = 0;
this.replaceNextlines = 0;
this.plaintextInput = 0;
this.toolbar = [
['bold','italic','underline','separator'],
['justifyleft','justifycenter','justifyright','separator'],
['OrderedList','UnOrderedList','Outdent','Indent','separator'],
['forecolor','backcolor','separator'],
['HorizontalRule','Createlink','InsertImage','InsertTable','htmlmode','separator'],
['popupeditor','about']];
this.fontstyles = [
];
this.btnList = {
"bold": ['Bold', 'Grassetto', 'editor_action(this.id)', 'ed_format_bold.gif'],
"italic": ['Italic', 'Corsivo', 'editor_action(this.id)', 'ed_format_italic.gif'],
"underline": ['Underline', 'Sottolineato', 'editor_action(this.id)', 'ed_format_underline.gif'],
"strikethrough": ['StrikeThrough', 'Strikethrough', 'editor_action(this.id)', 'ed_format_strike.gif'],
"subscript": ['SubScript', 'Subscript', 'editor_action(this.id)', 'ed_format_sub.gif'],
"superscript": ['SuperScript', 'Superscript', 'editor_action(this.id)', 'ed_format_sup.gif'],
"justifyleft": ['JustifyLeft', 'Allinea a sinistra', 'editor_action(this.id)', 'ed_align_left.gif'],
"justifycenter": ['JustifyCenter', 'Allinea al centro', 'editor_action(this.id)', 'ed_align_center.gif'],
"justifyright": ['JustifyRight', 'Allinea a destra', 'editor_action(this.id)', 'ed_align_right.gif'],
"justifyjustify": ['JustifyJustify', 'Giustifica', 'editor_action(this.id)', 'ed_align_justify.gif'],
"orderedlist": ['InsertOrderedList', 'Elenco numerico', 'editor_action(this.id)', 'ed_list_num.gif'],
"unorderedlist": ['InsertUnorderedList', 'Elenco puntato', 'editor_action(this.id)', 'ed_list_bullet.gif'],
"outdent": ['Outdent', 'Decrease Indent', 'editor_action(this.id)', 'ed_indent_less.gif'],
"indent": ['Indent', 'Increase Indent', 'editor_action(this.id)', 'ed_indent_more.gif'],
"forecolor": ['ForeColor', 'Colore testo', 'editor_action(this.id)', 'ed_color_fg.gif'],
"backcolor": ['BackColor', 'Background Color', 'editor_action(this.id)', 'ed_color_bg.gif'],
"horizontalrule": ['InsertHorizontalRule', 'Horizontal Rule', 'editor_action(this.id)', 'ed_hr.gif'],
"createlink": ['CreateLink', 'Collegamento ipertestuale', 'editor_action(this.id)', 'ed_link.gif'],
"insertimage": ['InsertImage', 'Insert Image', 'editor_action(this.id)', 'ed_image.gif'],
"inserttable": ['InsertTable', 'Inserisci una tabella', 'editor_action(this.id)', 'insert_table.gif'],
"htmlmode": ['HtmlMode', 'Mostra il codice HTML', 'editor_setmode(\''+objname+'\')', 'ed_html.gif'],
"popupeditor": ['popupeditor', 'Enlarge Editor', 'editor_action(this.id)', 'fullscreen_maximize.gif'],
"about": ['about', 'About this editor', 'editor_about(\''+objname+'\')', 'ed_about.gif'],
"custom1": ['custom1', 'Purpose of button 1', 'editor_action(this.id)', 'ed_custom.gif'],
"custom2": ['custom2', 'Purpose of button 2', 'editor_action(this.id)', 'ed_custom.gif'],
"custom3": ['custom3', 'Purpose of button 3', 'editor_action(this.id)', 'ed_custom.gif'],
"help": ['showhelp', 'Help using editor', 'editor_action(this.id)', 'ed_help.gif']};
}
function editor_generate(objname,userConfig) {
var config = new editor_defaultConfig(objname);
if (userConfig) {
for (var thisName in userConfig) {
if (userConfig[thisName]) { config[thisName] = userConfig[thisName]; }
}
}
document.all[objname].config = config;
var obj = document.all[objname];
if (!config.width || config.width == "auto") {
if (obj.style.width) { config.width = obj.style.width; }
else if (obj.cols) { config.width = (obj.cols * 8) + 22; }
else { config.width = '100%'; }
}
if (!config.height || config.height == "auto") {
if (obj.style.height) { config.height = obj.style.height; }
else if (obj.rows) { config.height = obj.rows * 17 }
else { config.height = '200'; }
}
var tblOpen = '<table border=0 cellspacing=0 cellpadding=0 style="float: left;" unselectable="on"><tr><td style="border: none; padding: 1 0 0 0"><nobr>';
var tblClose = '</nobr></td></tr></table>\n';
var toolbar = '';
var btnGroup, btnItem, aboutEditor;
for (var btnGroup in config.toolbar) {
if (config.toolbar[btnGroup].length == 1 &&
config.toolbar[btnGroup][0].toLowerCase() == "linebreak") {
toolbar += '<br clear="all">';
continue;
}
toolbar += tblOpen;
for (var btnItem in config.toolbar[btnGroup]) {
var btnName = config.toolbar[btnGroup][btnItem].toLowerCase();
if (btnName == "fontname") {
toolbar += '<select id="_' +objname+ '_FontName" onChange="editor_action(this.id)" unselectable="on" style="margin: 1 2 0 2; font-size: 12px;">';
for (var fontname in config.fontnames) {
toolbar += '<option value="' +config.fontnames[fontname]+ '">' +fontname+ '</option>'
}
toolbar += '</select>';
continue;
}
if (btnName == "fontsize") {
toolbar += '<select id="_' +objname+ '_FontSize" onChange="editor_action(this.id)" unselectable="on" style="margin: 1 2 0 0; font-size: 12px;">';
for (var fontsize in config.fontsizes) {
toolbar += '<option value="' +config.fontsizes[fontsize]+ '">' +fontsize+ '</option>'
}
toolbar += '</select>\n';
continue;
}
if (btnName == "fontstyle") {
toolbar += '<select id="_' +objname+ '_FontStyle" onChange="editor_action(this.id)" unselectable="on" style="margin: 1 2 0 0; font-size: 12px;">';
+ '<option value="">Font Style</option>';
for (var i in config.fontstyles) {
var fontstyle = config.fontstyles[i];
toolbar += '<option value="' +fontstyle.className+ '">' +fontstyle.name+ '</option>'
}
toolbar += '</select>';
continue;
}
if (btnName == "separator") {
toolbar += '<span style="border: 1px inset; width: 1px; font-size: 16px; height: 16px; margin: 0 3 0 3"></span>';
continue;
}
var btnObj = config.btnList[btnName];
if (btnName == 'linebreak') { alert("htmlArea error: 'linebreak' must be in a subgroup by itself, not with other buttons.\n\nhtmlArea wysiwyg editor not created."); return; }
if (!btnObj) { alert("htmlArea error: button '" +btnName+ "' not found in button list when creating the wysiwyg editor for '"+objname+"'.\nPlease make sure you entered the button name correctly.\n\nhtmlArea wysiwyg editor not created."); return; }
var btnCmdID = btnObj[0];
var btnTitle = btnObj[1];
var btnOnClick = btnObj[2];
var btnImage = btnObj[3];
toolbar += '<button title="' +btnTitle+ '" id="_' +objname+ '_' +btnCmdID+ '" class="btn" onClick="' +btnOnClick+ '" onmouseover="if(this.className==\'btn\'){this.className=\'btnOver\'}" onmouseout="if(this.className==\'btnOver\'){this.className=\'btn\'}" unselectable="on">[img]' +config.imgURL + btnImage+ '[/img]</button>';
}
toolbar += tblClose;
}
var editor = '<span id="_editor_toolbar"><table border=0 cellspacing=0 cellpadding=0 bgcolor="buttonface" style="padding: 1 0 0 2" width=' + config.width + ' unselectable="on"><tr><td>\n'
+ toolbar
+ '</td></tr></table>\n'
+ '</td></tr></table></span>\n'
+ '<textarea ID="_' +objname + '_editor" style="width:' +config.width+ '; height:' +config.height+ '; margin-top: -1px; margin-bottom: -1px;" wrap=soft></textarea>';
editor += '<div id="_' +objname + '_cMenu" style="position: absolute; visibility: hidden;"></div>';
if (!config.debug) { document.all[objname].style.display = "none"; }
if (config.plaintextInput) {
var contents = document.all[objname].value;
contents = contents.replace(/\r\n/g, '
');
contents = contents.replace(/\n/g, '
');
contents = contents.replace(/\r/g, '
');
document.all[objname].value = contents;
}
document.all[objname].insertAdjacentHTML('afterEnd', editor)
editor_setmode(objname, 'init');
for (var idx=0; idx < document.forms.length; idx++) {
var r = document.forms[idx].attachEvent('onsubmit', function() { editor_filterOutput(objname); });
if (!r) { alert("Error attaching event to form!"); }
}
return true;
}
function editor_action(button_id) {
var BtnParts = Array();
BtnParts = button_id.split("_");
var objname = button_id.replace(/^_(.*)_[^_]*$/, '$1');
var cmdID = BtnParts[ BtnParts.length-1 ];
var button_obj = document.all[button_id];
var editor_obj = document.all["_" +objname + "_editor"];
var config = document.all[objname].config;
if (cmdID == 'showhelp') {
window.open(_editor_url + "popups/editor_help.html", 'EditorHelp');
return;
}
if (cmdID == 'popupeditor') {
window.open(_editor_url + "popups/fullscreen.html?"+objname,
'FullScreen',
'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=640,height=480');
return;
}