/* ---------------------------------------------------------------------- *\
Function : editor_generate
Description : replace textarea with wysiwyg editor
Usage : editor_generate("textarea_id",[height],[width]);
Arguments : objname - ID of textarea to replace
w - width of wysiwyg editor
h - height of wysiwyg editor
\* ---------------------------------------------------------------------- */
function editor_generate(objname,w,h) {
// Default Settings
var imgURL = _editor_url + 'images/'; // images url
// set size to specified size or size of original object
var obj = document.all[objname];
if (!w) {
if (obj.style.width) { width = obj.style.width; } // use css style
else if (obj.cols) { width = (obj.cols * 8) + 22; } // col width + toolbar
else { width = '100%'; } // default
}
if (!h) {
if (obj.style.height) { height = obj.style.height; } // use css style
else if (obj.rows) { height = obj.rows * 17 } // row height
else { height = '200'; } // default
}
// Check for IE 5.5+ on Windows
var Agent, VInfo, MSIE, Ver, Win32, Opera;
Agent = navigator.userAgent;
VInfo = Array(); // version info
VInfo = Agent.split(";")
MSIE = Agent.indexOf('MSIE') > 0;
Ver = VInfo[1].substr(6,3);
Win32 = Agent.indexOf('Windows') > 0 && Agent.indexOf('Mac') < 0 && Agent.indexOf('Windows CE') < 0;
Opera = Agent.indexOf('Opera') > -1;
if (!MSIE || Opera || Ver < 5.5 || !Win32) { return; }
var editor = ''
+ '
\n'
+ '\n'
+ ' \n'
+ ' | \n'
+ ' '
+ ' | \n'
+ ' \n'
+ ' \n'
+ '\n'
+ ' \n'
+ ' | \n'
+ '\n\n'
+ ' | \n'
+ ' \n'
+ ' \n'
+ '\n'
// uncomment to add these buttons
+ '\n'
+ '\n'
+ '| \n'
+ ''
+ ' | \n'
+ '\n'
+ ' '
+ ' \n'
+ ' | \n'
+ '\n'
+ '\n'
+ ' '
+ ' | \n'
+ ' |
\n'
+ ''
+ ''
// + ''
;
// create editor
var contents = document.all[objname].value; // get original contents
document.all[objname].outerHTML = editor; // create editor frame
document.all['_'+objname+'_editor'].value = contents; // set contents
editor_setmode('_' +objname+ '_HtmlMode', 'init'); // switch to wysiwyg mode
}
/* ---------------------------------------------------------------------- *\
Function : editor_action
Description : perform an editor command on selected editor content
Usage :
Arguments : button_id - button id string with editor and action name
\* ---------------------------------------------------------------------- */
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"];
// check editor mode (don't perform actions in textedit mode)
if (editor_obj.tagName.toLowerCase() == 'textarea') { return; }
var editdoc = editor_obj.contentWindow.document;
_editor_focus(editor_obj);
// execute command for font pulldowns
var idx = button_obj.selectedIndex;
if (idx != null) {
var val = button_obj[ idx ].value;
editdoc.execCommand(cmdID,0,val);
}
// execute command for fgcolor & bgcolor buttons
else if (cmdID == 'ForeColor' || cmdID == 'BackColor') {
// figure our optimal window placement for popup dialog
var posX = event.screenX;
var posY = event.screenY + 20;
var screenW = screen.width; // screen size
var screenH = screen.height - 20; // take taskbar into account
if (posX + 232 > screenW) { posX = posX - 232 - 40; } // if mouse too far right
if (posY + 164 > screenH) { posY = posY - 164 - 80; } // if mouse too far down
var wPosition = "dialogLeft:" +posX+ "; dialogTop:" +posY;
var oldcolor = _dec_to_rgb(editdoc.queryCommandValue(cmdID));
var newcolor = showModalDialog(_editor_url + "select_color.html", oldcolor,
"dialogWidth:238px; dialogHeight: 187px; "
+ "resizable: no; help: no; status: no; scroll: no; "
+ wPosition);
if (newcolor != null) { editdoc.execCommand(cmdID, false, "#"+newcolor); }
}
// execute command for buttons
else {
// subscript & superscript, disable one before enabling the other
if (cmdID.toLowerCase() == 'subscript' && editdoc.queryCommandState('superscript')) { editdoc.execCommand('superscript'); }
if (cmdID.toLowerCase() == 'superscript' && editdoc.queryCommandState('subscript')) { editdoc.execCommand('subscript'); }
// insert link
if (cmdID.toLowerCase() == 'createlink'){
editdoc.execCommand(cmdID,1);
}
// insert image
else if (cmdID.toLowerCase() == 'insertimage'){
showModalDialog(_editor_url + "insert_image.html", editdoc, "resizable: no; help: no; status: no; scroll: no; ");
}
// insert image
else if (cmdID.toLowerCase() == 'about'){
var html = 'About\n'
+ '\n'
+ '\n\n'
+ 'Editor
\n\n'
+ '\n\n';
var popup = window.open('', 'ColorPicker',
"location=no,menubar=no,toolbar=no,directories=no,status=no," +
"height=275,width=450,resizable=no,scrollbars=no");
popup.document.write(html);
}
// all other commands
else {
editdoc.execCommand(cmdID);
}
}
editor_updateUI(objname);
}
/* ---------------------------------------------------------------------- *\
Function : editor_updateUI
Description : update button status, selected fonts, and hidden output field.
Usage :
Arguments : objname - ID of textarea to replace
runDelay: -1 = run now, no matter what
0 = run now, if allowed
1000 = run in 1 sec, if allowed at that point
\* ---------------------------------------------------------------------- */
function editor_updateUI(objname,runDelay) {
var editor_obj = document.all["_" +objname+ "_editor"]; // html editor object
if (runDelay == null) { runDelay = 0; }
var editdoc, editEvent;
// setup timer for delayed updates (some events take time to complete)
if (runDelay > 0) { return setTimeout(function(){ editor_updateUI(objname); }, runDelay); }
// don't execute more than 3 times a second (eg: too soon after last execution)
if (this.tooSoon == 1 && runDelay >= 0) { this.queue = 1; return; } // queue all but urgent events
this.tooSoon = 1;
setTimeout(function(){
this.tooSoon = 0;
if (this.queue) { editor_updateUI(objname,-1); };
this.queue = 0;
}, 333); // 1/3 second
// check editor mode and update hidden output field
if (editor_obj.tagName.toLowerCase() == 'textarea') { // textedit mode
document.all[objname].value = editor_obj.value; // update hidden output field
return;
} else { // WYSIWYG mode
editdoc = editor_obj.contentWindow.document; // get iframe editor document object
editEvent = editor_obj.contentWindow.event;
_fix_placeholder_urls(editdoc);
document.all[objname].value = editdoc.body.innerHTML; // update hidden output field
}
// update button states
var IDList = Array('Bold','Italic','Underline','JustifyLeft','JustifyCenter','JustifyRight','InsertOrderedList','InsertUnorderedList');
for (i=0; i';
var RichEdit = '';
//
// Switch to TEXTEDIT mode
//
if (mode == "textedit" || editor_obj.tagName.toLowerCase() == 'iframe') {
editdoc = editor_obj.contentWindow.document;
var contents = editdoc.body.createTextRange().htmlText;
editor_obj.outerHTML = TextEdit;
editor_obj = document.all["_" +objname + "_editor"];
editor_obj.value = contents;
editor_updateUI(objname);
// disable buttons
var IDList = Array('Bold','Italic','Underline','StrikeThrough','SubScript','SuperScript','JustifyLeft','JustifyCenter','JustifyRight','InsertOrderedList','InsertUnorderedList','Outdent','Indent','ForeColor','BackColor','InsertHorizontalRule','CreateLink','InsertImage');
for (i=0; i\n'
+ '\n'
+ '\n'
+ ''
+ contents
+ '\n'
+ '