I 've a htmlarea which is obtained from interactivetools.com
my problem i've a reset button in a form ....it was able to reset everything except the htmlarea i used from interactive tools...
Here is the java script i'm using .....
//
// htmlArea v3.0 - Copyright (c) 2002 interactivetools.com, inc.
// This copyright notice MUST stay intact for use (see license.txt).
//
// A free WYSIWYG editor replacement for <textarea> fields.
// For full source code and docs, visit
http://www.interactivetools.com///
// Version 3.0 developed by Mihai Bazon for InteractiveTools.
//
http://students.infoiasi.ro/~mishoo//
// $Id: htmlarea.js,v 1.19 2003/08/10 15:56:34 mishoo Exp $
// Creates a new HTMLArea object. Tries to replace the textarea with the given
// ID with it.
function HTMLArea(textarea, config) {
if (HTMLArea.checkSupportedBr
owser()) {
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._mdoc = document; // cache the document, we need it in plugins
}
};
HTMLArea.Config = function () {
this.version = "3.0";
this.width = "auto";
this.height = "auto";
// enable creation of a status bar?
this.statusBar = true;
// the next parameter specifies whether the toolbar should be included
// in the size or not.
this.sizeIncludesToolbar = true;
// style included in the iframe document
this.pageStyle = "body { background-color: #fff; font-family: verdana,sans-serif; }";
if (typeof _editor_url != "undefined") {
this.editorURL = _editor_url;
} else {
this.editorURL = "";
}
// URL-s
this.imgURL = "images/";
this.popupURL = "popups/";
// configuration for plugins
this.plugins = {};
/** CUSTOMIZING THE TOOLBAR
* -------------------------
*
* It is recommended that you customize the toolbar contents in an
* external file (i.e. the one calling HTMLArea) and leave this one
* unchanged. That's because when we (InteractiveTools.com) release a
* new official version, it's less likely that you will have problems
* upgrading HTMLArea.
*/
this.toolbar = [
[ "fontname", "space",
"fontsize", "space",
"formatblock", "space",
"bold", "italic", "underline", "separator",
"strikethrough", "subscript", "superscript", "separator",
"copy", "cut", "paste", "space", "undo", "redo" ],
[ "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
"insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
"forecolor", "hilitecolor", "textindicator", "separator",
"inserthorizontalrule", "createlink", "insertimage", "inserttable", "htmlmode", "separator",
"popupeditor", "separator", "showhelp", "about" ]
];
this.fontname = {
"Arial": 'arial,helvetica,sans-seri
f',
"Courier New": 'courier new,courier,monospace',
"Georgia": 'georgia,times new roman,times,serif',
"Tahoma": 'tahoma,arial,helvetica,sa
ns-serif',
"Times New Roman": 'times new roman,times,serif',
"Verdana": 'verdana,arial,helvetica,s
ans-serif'
,
"impact": 'impact',
"WingDings": 'wingdings'
};
this.fontsize = {
"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 = {
"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) {
try {
e.execCommand(cmd);
} catch (e) {
if (HTMLArea.is_gecko) {
alert("Some revisions of Mozilla/Gecko do not support programatic " +
"access to cut/copy/paste functions, for security reasons. " +
"Your browser is one of them. Please use the standard key combinations:\n" +
"CTRL-X for cut, CTRL-C for copy, CTRL-V for paste.");
obj.element.style.display = "none";
}
}
};
// ADDING CUSTOM BUTTONS: please read below!
// format of the btnList elements is "ID: [ ToolTip, Icon, Enabled in text mode?, ACTION ]"
// - ID: unique ID for the button. If the button calls document.execCommand
// it's wise to give it the same name as the called command.
// - ACTION: function that gets called when the button is clicked.
// it has the following prototype:
// function(editor, buttonName)
// - editor is the HTMLArea object that triggered the call
// - buttonName is the ID of the clicked button
// These 2 parameters makes it possible for you to use the same
// handler for more HTMLArea objects or for more different buttons.
// - ToolTip: default tooltip, for cases when it is not defined in the -lang- file (HTMLArea.I18N)
// - Icon: path to an icon image file for the button (TODO: use one image for all buttons!)
// - Enabled in text mode: if false the button gets disabled for text-only mode; otherwise enabled all the time.
this.btnList = {
bold: [ "Bold", "images/ed_format_bold.gif
", false, function(e) {e.execCommand("bold");} ],
italic: [ "Italic", "images/ed_format_italic.g
if", false, function(e) {e.execCommand("italic");}
],
underline: [ "Underline", "images/ed_format_underlin
e.gif", false, function(e) {e.execCommand("underline"
);} ],
strikethrough: [ "Strikethrough", "images/ed_format_strike.g
if", false, function(e) {e.execCommand("strikethro
ugh");} ],
subscript: [ "Subscript", "images/ed_format_sub.gif"
, false, function(e) {e.execCommand("subscript"
);} ],
superscript: [ "Superscript", "images/ed_format_sup.gif"
, false, function(e) {e.execCommand("superscrip
t");} ],
justifyleft: [ "Justify Left", "images/ed_align_left.gif"
, false, function(e) {e.execCommand("justifylef
t");} ],
justifycenter: [ "Justify Center", "images/ed_align_center.gi
f", false, function(e) {e.execCommand("justifycen
ter");} ],
justifyright: [ "Justify Right", "images/ed_align_right.gif
", false, function(e) {e.execCommand("justifyrig
ht");} ],
justifyfull: [ "Justify Full", "images/ed_align_justify.g
if", false, function(e) {e.execCommand("justifyful
l");} ],
insertorderedlist: [ "Ordered List", "images/ed_list_num.gif", false, function(e) {e.execCommand("insertorde
redlist");
} ],
insertunorderedlist: [ "Bulleted List", "images/ed_list_bullet.gif
", false, function(e) {e.execCommand("insertunor
deredlist"
);} ],
outdent: [ "Decrease Indent", "images/ed_indent_less.gif
", false, function(e) {e.execCommand("outdent");
} ],
indent: [ "Increase Indent", "images/ed_indent_more.gif
", false, function(e) {e.execCommand("indent");}
],
forecolor: [ "Font Color", "images/ed_color_fg.gif", false, function(e) {e.execCommand("forecolor"
);} ],
hilitecolor: [ "Background Color", "images/ed_color_bg.gif", false, function(e) {e.execCommand("hilitecolo
r");} ],
inserthorizontalrule: [ "Horizontal Rule", "images/ed_hr.gif", false, function(e) {e.execCommand("inserthori
zontalrule
");} ],
createlink: [ "Insert Web Link", "images/ed_link.gif", false, function(e) {e.execCommand("createlink
", true);} ],
insertimage: [ "Insert Image", "images/ed_image.gif", false, function(e) {e.execCommand("insertimag
e");} ],
inserttable: [ "Insert Table", "images/insert_table.gif",
false, function(e) {e.execCommand("inserttabl
e");} ],
htmlmode: [ "Toggle HTML Source", "images/ed_html.gif", true, function(e) {e.execCommand("htmlmode")
;} ],
popupeditor: [ "Enlarge Editor", "images/fullscreen_maximiz
e.gif", true, function(e) {e.execCommand("popupedito
r");} ],
about: [ "About this editor", "images/ed_about.gif", true, function(e) {e.execCommand("about");} ],
showhelp: [ "Help using editor", "images/ed_help.gif", true, function(e) {e.execCommand("showhelp")
;} ],
undo: [ "Undoes your last action", "images/ed_undo.gif", false, function(e) {e.execCommand("undo");} ],
redo: [ "Redoes your last action", "images/ed_redo.gif", false, function(e) {e.execCommand("redo");} ],
cut: [ "Cut selection", "images/ed_cut.gif", false, cut_copy_paste ],
copy: [ "Copy selection", "images/ed_copy.gif", false, cut_copy_paste ],
paste: [ "Paste from clipboard", "images/ed_paste.gif", false, cut_copy_paste ]
};
/* ADDING CUSTOM BUTTONS
* ---------------------
*
* It is recommended that you add the custom buttons in an external
* file and leave this one unchanged. That's because when we
* (InteractiveTools.com) release a new official version, it's less
* likely that you will have problems upgrading HTMLArea.
*
* Example on how to add a custom button when you construct the HTMLArea:
*
* var editor = new HTMLArea("your_text_area_i
d");
* var cfg = editor.config; // this is the default configuration
* cfg.btnList["my-hilite"] =
* [ function(editor) { editor.surroundHTML('<span
style="background:yellow">
', '</span>'); }, // action
* "Highlight selection", // tooltip
* "my_hilite.gif", // image
* false // disabled in text mode
* ];
* cfg.toolbar.push(["linebre
ak", "my-hilite"]); // add the new button to the toolbar
*
* An alternate (also more convenient and recommended) way to
* accomplish this is to use the registerButton function below.
*/
// initialize tooltips from the I18N module
for (var i in this.btnList) {
var btn = this.btnList[i];
if (typeof HTMLArea.I18N.tooltips[i] != "undefined") {
btn[0] = HTMLArea.I18N.tooltips[i];
}
}
};
/** Helper function: register a new button with the configuration. It can be
* called with all 5 arguments, or with only one (first one). When called with
* only one argument it must be an object with the following properties: id,
* tooltip, image, textMode, action. Examples:
*
* 1. config.registerButton("my-
hilite", "Hilite text", "my-hilite.gif", false, function(editor) {...});
* 2. config.registerButton({
* id : "my-hilite", // the ID of your button
* tooltip : "Hilite text", // the tooltip
* image : "my-hilite.gif", // image to be displayed in the toolbar
* textMode : false, // disabled in text mode
* action : function(editor) { // called when the button is clicked
* editor.surroundHTML('<span
class="hilite">', '</span>');
* },
* context : "p" // will be disabled if outside a <p> element
* });
*/
HTMLArea.Config.prototype.
registerBu
tton = 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::register
Button]:\n
invalid arguments");
return false;
}
// check for existing id
if (typeof this.customSelects[the_id]
!= "undefined") {
alert("WARNING [HTMLArea.Config::register
Dropdown]:
\nA dropdown with the same ID already exists.");
}
if (typeof this.btnList[the_id] != "undefined") {
alert("WARNING [HTMLArea.Config::register
Dropdown]:
\nA button with the same ID already exists.");
}
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;
}
};
/** The following helper function registers a dropdown box with the editor
* configuration. You still have to add it to the toolbar, same as with the
* buttons. Call it like this:
*
* FIXME: add example
*/
HTMLArea.Config.prototype.
registerDr
opdown = function(object) {
// check for existing id
if (typeof this.customSelects[object.
id] != "undefined") {
alert("WARNING [HTMLArea.Config::register
Dropdown]:
\nA dropdown with the same ID already exists.");
}
if (typeof this.btnList[object.id] != "undefined") {
alert("WARNING [HTMLArea.Config::register
Dropdown]:
\nA button with the same ID already exists.");
}
this.customSelects[object.
id] = object;
};
/** Helper function: replace all TEXTAREA-s in the document with HTMLArea-s. */
HTMLArea.replaceAll = function(config) {
var tas = document.getElementsByTagN
ame("texta
rea");
for (var i = tas.length; i > 0; (new HTMLArea(tas[--i], config)).generate());
};
/** Helper function: replaces the TEXTAREA with the given ID with HTMLArea. */
HTMLArea.replace = function(id, config) {
var ta = document.getElementById(id
);
return ta ? (new HTMLArea(ta, config)).generate() : null;
};
// Creates the toolbar and appends it to the _htmlarea
HTMLArea.prototype._create
Toolbar = function () {
var editor = this; // to access this in nested functions
var toolbar = document.createElement("di
v");
this._toolbar = toolbar;
toolbar.className = "toolbar";
toolbar.unselectable = "1";
var tb_row = null;
var tb_objects = new Object();
this._toolbarObjects = tb_objects;
// creates a new line in the toolbar
function newLine() {
var table = document.createElement("ta
ble");
table.border = "0px";
table.cellSpacing = "0px";
table.cellPadding = "0px";
toolbar.appendChild(table)
;
// TBODY is required for IE, otherwise you don't see anything
// in the TABLE.
var tb_body = document.createElement("tb
ody");
table.appendChild(tb_body)
;
tb_row = document.createElement("tr
");
tb_body.appendChild(tb_row
);
}; // END of function: newLine
// init first line
newLine();
// updates the state of a toolbar element. This function is member of
// a toolbar element object (unnamed objects created by createButton or
// createSelect functions below).
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;
}
}; // END of function: setButtonStatus
// this function will handle creation of combo boxes. Receives as
// parameter the name of a button as defined in the toolBar config.
// This function is called from createButton, above, if the given "txt"
// doesn't match a button.
function createSelect(txt) {
var options = null;
var el = null;
var cmd = null;
var customSelects = editor.config.customSelect
s;
var context = null;
switch (txt) {
case "fontsize":
case "fontname":
case "formatblock":
// the following line retrieves the correct
// configuration option because the variable name
// inside the Config object is named the same as the
// button/select in the toolbar. For instance, if txt
// == "formatblock" we retrieve config.formatblock (or
// a different way to write it in JS is
// config["formatblock"].
options = editor.config[txt];
cmd = txt;
break;
default:
// try to fetch it from the list of registered selects
cmd = txt;
var dropdown = customSelects[cmd];
if (typeof dropdown != "undefined") {
options = dropdown.options;
context = dropdown.context;
} else {
alert("ERROR [createSelect]:\nCan't find the requested dropdown definition");
}
break;
}
if (options) {
el = document.createElement("se
lect");
var obj = {
name : txt, // field name
element : el, // the UI element (SELECT)
enabled : true, // is it enabled?
text : false, // enabled in text mode?
cmd : cmd, // command ID
state : setButtonStatus, // for changing state
context : context
};
tb_objects[txt] = obj;
for (var i in options) {
var op = document.createElement("op
tion");
op.appendChild(document.cr
eateTextNo
de(i));
op.value = options[i];
el.appendChild(op);
}
HTMLArea._addEvent(el, "change", function () {
editor._comboSelected(el, txt);
});
}
return el;
}; // END of function: createSelect
// appends a new button to toolbar
function createButton(txt) {
// the element that will be created
var el = null;
var btn = null;
switch (txt) {
case "separator":
el = document.createElement("di
v");
el.className = "separator";
break;
case "space":
el = document.createElement("di
v");
el.className = "space";
break;
case "linebreak":
newLine();
return false;
case "textindicator":
el = document.createElement("di
v");
el.appendChild(document.cr
eateTextNo
de("A"));
el.className = "indicator";
el.title = HTMLArea.I18N.tooltips.tex
tindicator
;
var obj = {
name : txt, // the button name (i.e. 'bold')
element : el, // the UI element (DIV)
enabled : true, // is it enabled?
active : false, // is it pressed?
text : false, // enabled in text mode?
cmd : "textindicator", // the command ID
state : setButtonStatus // for changing state
};
tb_objects[txt] = obj;
break;
default:
btn = editor.config.btnList[txt]
;
}
if (!el && btn) {
el = document.createElement("di
v");
el.title = btn[0];
el.className = "button";
// let's just pretend we have a button object, and
// assign all the needed information to it.
var obj = {
name : txt, // the button name (i.e. 'bold')
element : el, // the UI element (DIV)
enabled : true, // is it enabled?
active : false, // is it pressed?
text : btn[2], // enabled in text mode?
cmd : btn[3], // the command ID
state : setButtonStatus, // for changing state
context : btn[4] || null // enabled in a certain context?
};
tb_objects[txt] = obj;
// handlers to emulate nice flat toolbar buttons
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);
}
});
// when clicked, do the following:
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 img = document.createElement("im
g");
img.src = editor.imgURL(btn[1]);
img.style.width = "18px";
img.style.height = "18px";
el.appendChild(img);
} 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 in this.config.toolbar) {
if (!first) {
createButton("linebreak");
} else {
first = false;
}
var group = this.config.toolbar[i];
for (var j in group) {
var code = group[j];
if (/^([IT])\[(.*?)\]/.test(c
ode)) {
// special case, create text label
var l7ed = RegExp.$1 == "I"; // localized?
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);
};
HTMLArea.prototype._create
StatusBar = function() {
var div = document.createElement("di
v");
div.className = "statusBar";
this._htmlArea.appendChild
(div);
this._statusBar = div;
div.appendChild(document.c
reateTextN
ode(HTMLAr
ea.I18N.ms
g["Path"] + ": "));
// creates a holder for the path view
div = document.createElement("sp
an");
div.className = "statusBarTree";
this._statusBarTree = div;
this._statusBar.appendChil
d(div);
if (!this.config.statusBar) {
// disable it...
div.style.display = "none";
}
};
// Creates the HTMLArea object and replaces the textarea with it.
HTMLArea.prototype.generat
e = function () {
var editor = this; // we'll need "this" in some nested functions
// get the textarea
var textarea = this._textArea;
if (typeof textarea == "string") {
// it's not element but ID
this._textArea = textarea = document.getElementById(te
xtarea);
}
this._ta_size = {
w: textarea.offsetWidth,
h: textarea.offsetHeight
};
textarea.style.display = "none";
// create the editor framework
var htmlarea = document.createElement("di
v");
htmlarea.className = "htmlarea";
this._htmlArea = htmlarea;
// insert the editor before the textarea.
textarea.parentNode.insert
Before(htm
larea, textarea);
if (textarea.form) {
// we have a form, on submit get the HTMLArea content and
// update original textarea.
textarea.form.onsubmit = function() {
editor._textArea.value = editor.getHTML();
};
}
// add a handler for the "back/forward" case -- on body.unload we save
// the HTML content into the original textarea.
window.onunload = function() {
editor._textArea.value = editor.getHTML();
};
// creates & appends the toolbar
this._createToolbar();
// create the IFRAME
var iframe = document.createElement("if
rame");
htmlarea.appendChild(ifram
e);
this._iframe = iframe;
// creates & appends the status bar, if the case
this._createStatusBar();
// remove the default border as it keeps us from computing correctly
// the sizes. (somebody tell me why doesn't this work in IE)
if (!HTMLArea.is_ie) {
iframe.style.borderWidth = "1px";
// iframe.frameBorder = "1";
// iframe.marginHeight = "0";
// iframe.marginWidth = "0";
}
// size the IFRAME according to user's prefs or initial textarea
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.sizeIncludesT
oolbar) {
// substract toolbar height
height -= this._toolbar.offsetHeight
;
height -= this._statusBar.offsetHeig
ht;
}
if (height < 0) {
height = 0;
}
iframe.style.height = height + "px";
// the editor including the toolbar now have the same size as the
// original textarea.. which means that we need to reduce that a bit.
textarea.style.width = iframe.style.width;
textarea.style.height = iframe.style.height;
// IMPORTANT: we have to allow Mozilla a short time to recognize the
// new frame. Otherwise we get a stupid exception.
function initIframe() {
var doc = editor._iframe.contentWind
ow.documen
t;
if (!doc) {
// Try again..
// FIXME: don't know what else to do here. Normally
// we'll never reach this point.
if (HTMLArea.is_gecko) {
setTimeout(initIframe, 10);
return false;
} else {
alert("ERROR: IFRAME can't be initialized.");
}
}
if (HTMLArea.is_gecko) {
// enable editable mode for Mozilla
doc.designMode = "on";
}
editor._doc = doc;
doc.open();
var html = "<html>\n";
html += "<head>\n";
html += "<style>" + editor.config.pageStyle + "</style>\n";
html += "</head>\n";
html += "<body>\n";
html += editor._textArea.value;
html += "</body>\n";
html += "</html>";
doc.write(html);
doc.close();
if (HTMLArea.is_ie) {
// enable editable mode for IE. For some reason this
// doesn't work if done in the same place as for Gecko
// (above).
doc.body.contentEditable = true;
}
editor.focusEditor();
// intercept some events; for updating the toolbar & keyboard handlers
HTMLArea._addEvents
(doc, ["keydown", "keypress", "mousedown", "mouseup", "drag"],
function (event) {
return editor._editorEvent(HTMLAr
ea.is_ie ? editor._iframe.contentWind
ow.event : event);
});
editor.updateToolbar();
};
setTimeout(initIframe, HTMLArea.is_gecko ? 10 : 0);
};
// Switches editor mode; parameter can be "textmode" or "wysiwyg". If no
// parameter was passed this function toggles between modes.
HTMLArea.prototype.setMode
= function(mode) {
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.displ
ay = "block";
if (this.config.statusBar) {
this._statusBar.innerHTML = HTMLArea.I18N.msg["TEXT_MO
DE"];
}
break;
case "wysiwyg":
if (HTMLArea.is_gecko) {
// disable design mode before changing innerHTML
this._doc.designMode = "off";
}
this._doc.body.innerHTML = this.getHTML();
this._iframe.style.display
= "block";
this._textArea.style.displ
ay = "none";
if (HTMLArea.is_gecko) {
// we need to refresh that info for Moz-1.3a
this._doc.designMode = "on";
}
if (this.config.statusBar) {
this._statusBar.innerHTML = '';
this._statusBar.appendChil
d(document
.createTex
tNode(HTML
Area.I18N.
msg["Path"
] + ": "));
this._statusBar.appendChil
d(this._st
atusBarTre
e);
}
break;
default:
alert("Mode <" + mode + "> not defined!");
return false;
}
this._editMode = mode;
this.focusEditor();
};
/*************************
**********
**********
******
* Category: PLUGINS
**************************
**********
**********
*****/
// Create the specified plugin and register it with this HTMLArea
HTMLArea.prototype.registe
rPlugin = function(pluginName) {
this.plugins[pluginName] = eval("new " + pluginName + "(this);");
};
// static function that loads the required plugin and lang file, based on the
// language loaded already for HTMLArea. You better make sure that the plugin
// _has_ that language, otherwise shit might happen ;-)
HTMLArea.loadPlugin = function(pluginName) {
var editorurl = '';
if (typeof _editor_url != "undefined") {
editorurl = _editor_url + "/";
}
var dir = editorurl + "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";
document.write("<script type='text/javascript' src='" + dir + "/" + plugin + "'></script>");
document.write("<script type='text/javascript' src='" + dir + "/lang/" + HTMLArea.I18N.lang + ".js'></script>");
};
/*************************
**********
**********
******
* Category: EDITOR UTILITIES
**************************
**********
**********
*****/
HTMLArea.prototype.forceRe
draw = function() {
this._doc.body.style.visib
ility = "hidden";
this._doc.body.style.visib
ility = "visible";
// this._doc.body.innerHTML = this.getInnerHTML();
};
// focuses the iframe window. returns a reference to the editor document.
HTMLArea.prototype.focusEd
itor = function() {
switch (this._editMode) {
case "wysiwyg" : this._iframe.contentWindow
.focus(); break;
case "textmode": this._textArea.focus(); break;
default : alert("ERROR: mode " + this._editMode + " is not defined");
}
return this._doc;
};
// updates enabled/disable/active state of the toolbar elements
HTMLArea.prototype.updateT
oolbar = function(noStatus) {
var doc = this._doc;
var text = (this._editMode == "textmode");
var ancestors = null;
if (!text) {
ancestors = this.getAllAncestors();
if (this.config.statusBar && !noStatus) {
this._statusBarTree.innerH
TML = ''; // clear
for (var i = ancestors.length; --i >= 0;) {
var el = ancestors[i];
if (!el) {
// hell knows why we get here; this
// could be a classic example of why
// it's good to check for conditions
// that are impossible to happen ;-)
continue;
}
var a = document.createElement("a"
);
a.href = "#";
a.el = el;
a.editor = this;
a.onclick = function() {
this.blur();
this.editor.selectNodeCont
ents(this.
el);
this.editor.updateToolbar(
true);
return false;
};
a.oncontextmenu = function() {
// TODO: add context menu here
this.blur();
var info = "Inline style:\n\n";
info += this.el.style.cssText.spli
t(/;\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.cre
ateTextNod
e(txt));
this._statusBarTree.append
Child(a);
if (i != 0) {
this._statusBarTree.append
Child(docu
ment.creat
eTextNode(
String.fro
mCharCode(
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(cont
ext)) {
context = RegExp.$1;
attrs = RegExp.$2.split(",");
}
context = context.toLowerCase();
var match = (context == "*");
for (var k in ancestors) {
if (!ancestors[k]) {
// the impossible really happens.
continue;
}
if (match || (ancestors[k].tagName.toLo
werCase() == context)) {
inContext = true;
for (var ka in attrs) {
if (!eval("ancestors[k]." + attrs[ka])) {
inContext = false;
break;
}
}
if (inContext) {
break;
}
}
}
}
btn.state("enabled", (!text || btn.text) && inContext);
if (typeof cmd == "function") {
continue;
}
// look-it-up in the custom dropdown boxes
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) {
var value = ("" + doc.queryCommandValue(cmd)
).toLowerC
ase();
if (!value) {
// FIXME: what do we do here?
break;
}
// HACK -- retrieve the config option for this
// combo box. We rely on the fact that the
// variable in config has the same name as
// button name in the toolbar.
var options = this.config[cmd];
var k = 0;
// btn.element.selectedIndex = 0;
for (var j in options) {
// FIXME: the following line is scary.
if ((j.toLowerCase() == value) ||
(options[j].substr(0, value.length).toLowerCase(
) == value)) {
btn.element.selectedIndex = k;
break;
}
++k;
}
}
break;
case "textindicator":
if (!text) {
try {with (btn.element.style) {
backgroundColor = HTMLArea._makeColor(
doc.queryCommandValue(HTML
Area.is_ie
? "backcolor" : "hilitecolor"));
if (/transparent/i.test(backg
roundColor
)) {
// Mozilla
backgroundColor = HTMLArea._makeColor(doc.qu
eryCommand
Value("bac
kcolor"));
}
color = HTMLArea._makeColor(doc.qu
eryCommand
Value("for
ecolor"));
fontFamily = doc.queryCommandValue("fon
tname");
fontWeight = doc.queryCommandState("bol
d") ? "bold" : "normal";
fontStyle = doc.queryCommandState("ita
lic") ? "italic" : "normal";
}} catch (e) {
// alert(e + "\n\n" + cmd);
}
}
break;
case "htmlmode": btn.state("active", text); break;
default:
try {
btn.state("active", (!text && doc.queryCommandState(cmd)
));
} catch (e) {}
}
}
};
/** Returns a node after which we can insert other nodes, in the current
* selection. The selection is removed. It splits a text node, if needed.
*/
HTMLArea.prototype.insertN
odeAtSelec
tion = function(toBeInserted) {
if (!HTMLArea.is_ie) {
var sel = this._getSelection();
var range = this._createRange(sel);
// remove the current selection
sel.removeAllRanges();
range.deleteContents();
var node = range.startContainer;
var pos = range.startOffset;
switch (node.nodeType) {
case 3: // Node.TEXT_NODE
// we have to split it at the caret position.
if (toBeInserted.nodeType == 3) {
// do optimized insertion
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 /* Node.DOCUMENT_FRAGMENT_NOD
E */) {
selnode = selnode.firstChild;
}
node.parentNode.insertBefo
re(toBeIns
erted, node);
this.selectNodeContents(se
lnode);
this.updateToolbar();
}
break;
case 1: // Node.ELEMENT_NODE
var selnode = toBeInserted;
if (toBeInserted.nodeType == 11 /* Node.DOCUMENT_FRAGMENT_NOD
E */) {
selnode = selnode.firstChild;
}
node.insertBefore(toBeInse
rted, node.childNodes[pos]);
this.selectNodeContents(se
lnode);
this.updateToolbar();
break;
}
} else {
return null; // this function not yet used for IE <FIXME>
}
};
// Returns the deepest node that contains both endpoints of the selection.
HTMLArea.prototype.getPare
ntElement = function() {
var sel = this._getSelection();
var range = this._createRange(sel);
if (HTMLArea.is_ie) {
return range.parentElement ? range.parentElement() : this._doc.body;
} else {
var p = range.commonAncestorContai
ner;
while (p.nodeType == 3) {
p = p.parentNode;
}
return p;
}
};
// Returns an array with all the ancestor nodes of the selection.
HTMLArea.prototype.getAllA
ncestors = 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;
};
// Selects the contents inside the given node
HTMLArea.prototype.selectN
odeContent
s = function(node, pos) {
this.focusEditor();
this.forceRedraw();
var range;
var collapsed = (typeof pos != "undefined");
if (HTMLArea.is_ie) {
range = this._doc.body.createTextR
ange();
range.moveToElementText(no
de);
(collapsed) && range.collapse(pos);
range.select();
} else {
var sel = this._getSelection();
range = this._doc.createRange();
range.selectNodeContents(n
ode);
(collapsed) && range.collapse(pos);
sel.removeAllRanges();
sel.addRange(range);
}
};
/** Call this function to insert HTML code at the current position. It deletes
* the selection, if any.
*/
HTMLArea.prototype.insertH
TML = function(html) {
var sel = this._getSelection();
var range = this._createRange(sel);
if (HTMLArea.is_ie) {
range.pasteHTML(html);
} else {
// construct a new document fragment with the given HTML
var fragment = this._doc.createDocumentFr
agment();
var div = this._doc.createElement("d
iv");
div.innerHTML = html;
while (div.firstChild) {
// the following call also removes the node from div
fragment.appendChild(div.f
irstChild)
;
}
// this also removes the selection
var node = this.insertNodeAtSelection
(fragment)
;
}
};
/**
* Call this function to surround the existing HTML code in the selection with
* your tags. FIXME: buggy! This function will be deprecated "soon".
*/
HTMLArea.prototype.surroun
dHTML = function(startTag, endTag) {
var html = this.getSelectedHTML();
// the following also deletes the selection
this.insertHTML(startTag + html + endTag);
};
/// Retrieve the selected block
HTMLArea.prototype.getSele
ctedHTML = 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.clo
neContents
(), false);
}
return existing;
};
// Called when the user clicks on "InsertImage" button
HTMLArea.prototype._insert
Image = function() {
var editor = this; // for nested functions
this._popupDialog("insert_
image.html
", function(param) {
if (!param) { // user must have pressed Cancel
return false;
}
var sel = editor._getSelection();
var range = editor._createRange(sel);
editor._doc.execCommand("i
nsertimage
", false, param["f_url"]);
var img = null;
if (HTMLArea.is_ie) {
img = range.parentElement();
// wonder if this works...
if (img.tagName.toLowerCase()
!= "img") {
img = img.previousSibling;
}
} else {
img = range.startContainer.previ
ousSibling
;
}
for (field in param) {
var value = param[field];
if (!value) {
continue;
}
switch (field) {
case "f_alt" : img.alt = value; break;
case "f_border" : img.border = parseInt(value); break;
case "f_align" : img.align = value; break;
case "f_vert" : img.vspace = parseInt(value); break;
case "f_horiz" : img.hspace = parseInt(value); break;
}
}
}, null);
};
// Called when the user clicks the Insert Table button
HTMLArea.prototype._insert
Table = function() {
var sel = this._getSelection();
var range = this._createRange(sel);
var editor = this; // for nested functions
this._popupDialog("insert_
table.html
", function(param) {
if (!param) { // user must have pressed Cancel
return false;
}
var doc = editor._doc;
// create the table element
var table = doc.createElement("table")
;
// assign the given arguments
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 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");
tr.appendChild(td);
// Mozilla likes to see something inside the cell.
(HTMLArea.is_gecko) && td.appendChild(doc.createE
lement("br
"));
}
}
if (HTMLArea.is_ie) {
range.pasteHTML(table.oute
rHTML);
} else {
// insert the table
editor.insertNodeAtSelecti
on(table);
}
return true;
}, null);
};
/*************************
**********
**********
******
* Category: EVENT HANDLERS
**************************
**********
**********
*****/
// el is reference to the SELECT object
// txt is the name of the select field, as in config.toolbar
HTMLArea.prototype._comboS
elected = function(el, txt) {
this.focusEditor();
var value = el.options[el.selectedInde
x].value;
switch (txt) {
case "fontname":
case "fontsize": this.execCommand(txt, false, value); break;
case "formatblock":
(HTMLArea.is_ie) && (value = "<" + value + ">");
this.execCommand(txt, false, value);
break;
default:
// try to look it up in the registered dropdowns
var dropdown = this.config.customSelects[
txt];
if (typeof dropdown != "undefined") {
dropdown.action(this);
} else {
alert("FIXME: combo box " + txt + " not implemented");
}
}
};
// the execCommand function (intercepts some commands and replaces them with
// our own implementation)
HTMLArea.prototype.execCom
mand = function(cmdID, UI, param) {
var editor = this; // for nested functions
this.focusEditor();
switch (cmdID.toLowerCase()) {
case "htmlmode" : this.setMode(); break;
case "hilitecolor":
(HTMLArea.is_ie) && (cmdID = "backcolor");
case "forecolor":
this._popupDialog("select_
color.html
", function(color) {
if (color) { // selection not canceled
editor._doc.execCommand(cm
dID, false, "#" + color);
}
}, HTMLArea._colorToRgb(this.
_doc.query
CommandVal
ue(cmdID))
);
break;
case "createlink":
if (HTMLArea.is_ie || !UI) {
this._doc.execCommand(cmdI
D, UI, param);
} else {
// browser is Mozilla & wants UI
var param;
if ((param = prompt("Enter URL"))) {
this._doc.execCommand(cmdI
D, false, param);
}
}
break;
case "popupeditor":
if (HTMLArea.is_ie) {
window.open(this.popupURL(
"fullscree
n.html"), "ha_fullscreen",
"toolbar=no,location=no,di
rectories=
no,status=
no,menubar
=no," +
"scrollbars=no,resizable=y
es,width=6
40,height=
480");
} else {
window.open(this.popupURL(
"fullscree
n.html"), "ha_fullscreen",
"toolbar=no,menubar=no,per
sonalbar=n
o,width=64
0,height=4
80," +
"scrollbars=no,resizable=y
es");
}
// pass this object to the newly opened window
HTMLArea._object = this;
break;
case "inserttable": this._insertTable(); break;
case "insertimage": this._insertImage(); break;
case "about" : this._popupDialog("about.h
tml", null, null); break;
case "showhelp" : window.open("reference.htm
l", "ha_help"); break;
default: this._doc.execCommand(cmdI
D, UI, param);
}
this.updateToolbar();
return false;
};
/** A generic event handler for things that happen in the IFRAME's document.
* This function also handles key bindings. */
HTMLArea.prototype._editor
Event = function(ev) {
var editor = this;
var keyEvent = (HTMLArea.is_ie && ev.type == "keydown") || (ev.type == "keypress");
if (keyEvent && ev.ctrlKey) {
var sel = null;
var range = null;
var key = String.fromCharCode(HTMLAr
ea.is_ie ? ev.keyCode : ev.charCode).toLowerCase()
;
var cmd = null;
var value = null;
switch (key) {
case 'a':
if (!HTMLArea.is_ie) {
// KEY select all
sel = this._getSelection();
sel.removeAllRanges();
range = this._createRange();
range.selectNodeContents(t
his._doc.b
ody);
sel.addRange(range);
HTMLArea._stopEvent(ev);
}
break;
// simple key commands follow
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;
// headings
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) {
// execute simple command
this.execCommand(cmd, false, value);
HTMLArea._stopEvent(ev);
}
}
/*
else if (keyEvent) {
// other keys here
switch (ev.keyCode) {
case 13: // KEY enter
// if (HTMLArea.is_ie) {
this.insertHTML("<br />");
HTMLArea._stopEvent(ev);
// }
break;
}
}
*/
// update the toolbar state after some time
if (editor._timerToolbar) {
clearTimeout(editor._timer
Toolbar);
}
editor._timerToolbar = setTimeout(function() {
editor.updateToolbar();
editor._timerToolbar = null;
}, 50);
};
// retrieve the HTML
HTMLArea.prototype.getHTML
= function() {
switch (this._editMode) {
case "wysiwyg" : return HTMLArea.getHTML(this._doc
.body, false);
case "textmode" : return this._textArea.value;
default : alert("Mode <" + mode + "> not defined!");
}
return false;
};
// retrieve the HTML (fastest version, but uses innerHTML)
HTMLArea.prototype.getInne
rHTML = function() {
switch (this._editMode) {
case "wysiwyg" : return this._doc.body.innerHTML;
case "textmode" : return this._textArea.value;
default : alert("Mode <" + mode + "> not defined!");
}
return false;
};
// completely change the HTML inside
HTMLArea.prototype.setHTML
= function(html) {
switch (this._editMode) {
case "wysiwyg" : this._doc.body.innerHTML = html; break;
case "textmode" : this._textArea.value = html; break;
default : alert("Mode <" + mode + "> not defined!");
}
return false;
};
/*************************
**********
**********
******
* Category: UTILITY FUNCTIONS
**************************
**********
**********
*****/
// browser identification
HTMLArea.agt = navigator.userAgent.toLowe
rCase();
HTMLArea.is_ie = ((HTMLArea.agt.indexOf("ms
ie") != -1) && (HTMLArea.agt.indexOf("ope
ra") == -1));
HTMLArea.is_opera = (HTMLArea.agt.indexOf("ope
ra") != -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");
// variable used to pass the object to the popup editor window.
HTMLArea._object = null;
// FIXME!!! this should return false for IE < 5.5
HTMLArea.checkSupportedBro
wser = 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;
};
// selection & ranges
// returns the current selection object
HTMLArea.prototype._getSel
ection = function() {
if (HTMLArea.is_ie) {
return this._doc.selection;
} else {
return this._iframe.contentWindow
.getSelect
ion();
}
};
// returns a range for the current selection
HTMLArea.prototype._create
Range = function(sel) {
if (HTMLArea.is_ie) {
return sel.createRange();
} else {
this.focusEditor();
if (typeof sel != "undefined") {
return sel.getRangeAt(0);
} else {
return this._doc.createRange();
}
}
};
// event handling
HTMLArea._addEvent = function(el, evname, func) {
if (HTMLArea.is_ie) {
el.attachEvent("on" + evname, func);
} else {
el.addEventListener(evname
, func, true);
}
};
HTMLArea._addEvents = function(el, evs, func) {
for (var i in evs) {
HTMLArea._addEvent(el, evs[i], func);
}
};
HTMLArea._removeEvent = function(el, evname, func) {
if (HTMLArea.is_ie) {
el.detachEvent("on" + evname, func);
} else {
el.removeEventListener(evn
ame, func, true);
}
};
HTMLArea._removeEvents = function(el, evs, func) {
for (var i in evs) {
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) {
// remove the class first, if already there
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.isBlockElement = function(el) {
var 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 iframe address ";
return (blockTags.indexOf(" " + el.tagName.toLowerCase() + " ") != -1);
};
HTMLArea.needsClosingTag = function(el) {
var closingTags = " script style div span tr td tbody table em strong font a ";
return (closingTags.indexOf(" " + el.tagName.toLowerCase() + " ") != -1);
};
// performs HTML encoding of some given string
HTMLArea.htmlEncode = function(str) {
// we don't need regexp for that, but.. so be it for now.
str = str.replace(/&/ig, "&");
str = str.replace(/</ig, "<");
str = str.replace(/>/ig, ">");
str = str.replace(/\x22/ig, """);
// \x22 means '"' -- we use hex reprezentation so that we don't disturb
// JS compressors (well, at least mine fails.. ;)
return str;
};
// Retrieves the HTML code from the given node. This is a replacement for
// getting innerHTML, using standard DOM calls.
HTMLArea.getHTML = function(root, outputRoot) {
var html = "";
switch (root.nodeType) {
case 1: // Node.ELEMENT_NODE
case 11: // Node.DOCUMENT_FRAGMENT_NOD
E
var closed;
var i;
if (outputRoot) {
closed = (!(root.hasChildNodes() || HTMLArea.needsClosingTag(r
oot)));
html = "<" + root.tagName.toLowerCase()
;
var attrs = root.attributes;
for (i = 0; i < attrs.length; ++i) {
var a = attrs.item(i);
if (!a.specified) {
continue;
}
var name = a.nodeName.toLowerCase();
if (/_moz/.test(name)) {
// Mozilla reports some special tags
// here; we don't need them.
continue;
}
var value;
if (name != "style") {
// IE5.5 reports 25 when cellSpacing is
// 1; other values might be doomed too.
// For this reason we extract the
// values directly from the root node.
// I'm starting to HATE JavaScript
// development. Browser differences
// suck.
if (typeof root[a.nodeName] != "undefined") {
value = root[a.nodeName];
} else {
value = a.nodeValue;
}
} else { // IE fails to put style in attributes list
// FIXME: cssText reported by IE is UPPERCASE
value = root.style.cssText;
}
if (/_moz/.test(value)) {
// Mozilla reports some special tags
// here; we don't need them.
continue;
}
html += " " + name + '="' + value + '"';
}
html += closed ? " />" : ">";
}
for (i = root.firstChild; i; i = i.nextSibling) {
html += HTMLArea.getHTML(i, true);
}
if (outputRoot && !closed) {
html += "</" + root.tagName.toLowerCase()
+ ">";
}
break;
case 3: // Node.TEXT_NODE
html = HTMLArea.htmlEncode(root.d
ata);
break;
case 8: // Node.COMMENT_NODE
html = "<!--" + root.data + "-->";
break; // skip comments, for now.
}
return html;
};
// creates a rgb-style color from a number
HTMLArea._makeColor = function(v) {
if (typeof v != "number") {
// already in rgb (hopefully); IE doesn't get here.
return v;
}
// IE sends number; convert to rgb.
var r = v & 0xFF;
var g = (v >> 8) & 0xFF;
var b = (v >> 16) & 0xFF;
return "rgb(" + r + "," + g + "," + b + ")";
};
// returns hexadecimal color representation from a number or a rgb-style color.
HTMLArea._colorToRgb = function(v) {
// returns the hex representation of one byte (2 digits)
function hex(d) {
return (d < 16) ? ("0" + d.toString(16)) : d.toString(16);
};
if (typeof v == "number") {
// we're talking to IE here
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") {
// in rgb(...) form -- Mozilla
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);
}
// doesn't match RE?! maybe uses percentages or float numbers
// -- FIXME: not yet implemented.
return null;
}
if (v[0] == "#") {
// already hex rgb (hopefully :D )
return v;
}
// if everything else fails ;)
return null;
};
// modal dialogs for Mozilla (for IE we're using the showModalDialog() call).
// receives an URL to the popup dialog and a function that receives one value;
// this function will get called after the dialog is closed, with the return
// value of the dialog.
HTMLArea.prototype._popupD
ialog = function(url, action, init) {
Dialog(this.popupURL(url),
action, init);
};
// paths
HTMLArea.prototype.imgURL = function(file, plugin) {
if (typeof plugin == "undefined") {
return this.config.editorURL + file;
} else {
return this.config.editorURL + "plugins/" + plugin + "/img/" + file;
}
};
HTMLArea.prototype.popupUR
L = function(file) {
return this.config.editorURL + this.config.popupURL + file;
};
// EOF
// Local variables: //
// c-basic-offset:8 //
// indent-tabs-mode:t //
// End: //
and here is the my program code...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%
response.setHeader("Cache-
Control","
no-store")
; //HTTP 1.1
response.setHeader("Pragma
","no-cach
e"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<%
boolean isAdmin;
String lastvisitedpage = convertNull((String)reques
t.getAttri
bute("last
VisitedPag
e"));
if(lastvisitedpage.equals(
"adminList
Handler")|
|lastvisit
edpage.equ
als("admin
FormHandle
r"))
isAdmin=true;
else
isAdmin=false;
%>
<html xmlns="
http://www.w3.org/1999/xhtml"
>
<head>
<%if(isAdmin){%>
<title>Welcome to Bulletin Administrator</title>
<%} else{%>
<title>Welcome to Bulletin Tool</title>
<%}%>
<script type="text/javascript" src="htmlarea/htmlarea.js"
></script>
<script type="text/javascript" src="htmlarea/dialog.js"><
/script>
<script type="text/javascript" src="htmlarea/lang/en.js">
</script>
<style type="text/css">@import url(htmlarea/htmlarea.css)
;
a:link, a:visited { color: #00f; }
a:hover { color: #048; }
a:active { color: #f00; }
textarea { background-color: #fff; }
</style>
<script language="JavaScript" type="text/javascript">
javascript:window.history.
forward(1)
;
</script>
<script language="JavaScript" type="text/javascript">
<!-- Begin
function firstWindow(viewForm) {
var particleTitle=viewForm.art
icleTitle.
value;
var particleText = viewForm.articleText.value
;
viewWindow = window.open("",'Window','w
idth=600,h
eight=350,
left=200, top=200, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=yes');
viewWindow.document.write(
"<html>");
viewWindow.document.write(
"<STYLE TYPE='text/css'>");
viewWindow.document.write(
"<!--");
viewWindow.document.write(
"BODY");
viewWindow.document.write(
"{COLOR:bl
ack; BACKGROUND-COLOR: white; font-size:11pt;font-family
:arial;}")
;
viewWindow.document.write(
".redhead {FONT-WEIGHT: 700; FONT-SIZE: 12pt; COLOR: #da2325; FONT-FAMILY:Arial;}");
viewWindow.document.write(
".graydate
{COLOR: gray; FONT-WEIGHT: 700;FONT-STYLE:italic;FONT
-SIZE:9pt;
FONT-FAMIL
Y:Arial;}"
);
viewWindow.document.write(
".graycont
act {COLOR: gray; FONT-SIZE:10pt;FONT-FAMILY
:Arial;}")
;
viewWindow.document.write(
"--></STYL
E>");
viewWindow.document.write(
"<title> Preview of the article </title> <BODY>");
viewWindow.document.write(
"<SPAN CLASS='redhead'>");
viewWindow.document.write(
particleTi
tle);
viewWindow.document.write(
"</SPAN> <p> ");
viewWindow.document.write(
particleTe
xt);
viewWindow.document.write(
"</html>")
;
viewWindow.document.close(
);
viewWindow.focus();
}
function confirmSubmit(submitForm,m
sg) {
var doc = submitForm;
//var msg = "Are you sure you want to submit this article?";
if (confirm(msg)) {
return true;
} else {
return false;
}
}
function ShowMoreInfo(){
var winl = (screen.width - 434) / 2;
var wint = (screen.height - 241) / 2;
window.open('moreInfo.html
','' ,'width=434,height=241,top
='+wint+',
left='+win
l+'', true);
}
function clear()
{
this.value = "";
this.focus();
}
//end -->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<%if(isAdmin){%>
<%@ include file="adminHead.jsp"%>
<%} else{%>
<%@ include file="head.jsp"%>
<%}%>
<!--to show welcome -->
<font face='Arial' size='2' color='black'><b>Welcome</
font> </b>
<%
String name = (String)session.getAttribu
te("name")
;
if(name != null&&!name.equals("null")
){
out.println("<font face='Arial' size='2' color='red'><b>");
out.println(name);
out.println("<br>");
out.println("</b></font>")
;
out.println("</font>");
out.println("<br>");
}
%>
<% String error = (String)request.getAttribu
te("error"
);%>
<%!
private String convertNull(String possibleNullValue){
if (possibleNullValue == null)
return "";
else
return possibleNullValue.trim();
}
private String isChecked (HttpServletRequest request, String param, String testValue){
if (request.getParameter(para
m)==null && testValue == null)
return " checked ";
if (request.getParameter(para
m)==null)
return "";
if ((request.getParameter(par
am)).equal
s(testValu
e) )
return " checked ";
else
return "";
}
%>
<%
session.setAttribute("norm
alEnterFor
m","yes");
String ucid=convertNull((String)s
ession.get
Attribute(
"ucid"));
boolean isSuperAdmin=false;
if(("isSuperAdmin").equals
((String)s
ession.get
Attribute(
"isSuperAd
min"))){
isSuperAdmin=true;
}
String thepage = convertNull((String)reques
t.getAttri
bute("page
"));
String modify = convertNull((String)reques
t.getAttri
bute("modi
fy"));
String articleID = convertNull((String)reques
t.getAttri
bute("arti
cleID"));
String [] str;
String submitValue="";
String viewID="";
Vector articleVector = (Vector)request.getAttribu
te("articl
eVector");
String[] monthDesc={"January","Febr
uary","Mar
ch","April
","May","J
une","July
","August"
,"Septembe
r","Octobe
r","Novemb
er","Decem
ber"};
String nextView="";
String post_uid="";
String category="";
Vector deptVector=new Vector();
HashMap categoryHashMap=(HashMap)s
ession.get
Attribute(
"categoryH
ashMap");
if(categoryHashMap==null)
categoryHashMap=new HashMap();
int categorySize=0;
String categorySizeStr= (String)categoryHashMap.ge
t("numberO
fcategory"
);
if(categorySizeStr!=null)
categorySize=Integer.parse
Int(catego
rySizeStr)
;
if(isAdmin){ //adminForm
nextView=convertNull((Stri
ng)request
.getAttrib
ute("nextV
iew"));
post_uid=convertNull((Stri
ng)request
.getAttrib
ute("post_
uid"));
category=convertNull((Stri
ng)request
.getAttrib
ute("categ
ory"));
System.out.println("now it is in adminForm "+lastvisitedpage);
}
else //articleForm
{
deptVector = (Vector)session.getAttribu
te("deptVe
ctor");
if(deptVector==null)
deptVector=new Vector();
System.out.println("now it is in articleForm "+lastvisitedpage);
}
if(articleVector==null)
articleVector=new Vector();
if(articleVector.size() != 0){
//System.out.println("arti
clevector is not null");
str = new String[articleVector.size(
)];
//System.out.println("arti
cleVector.
size(): "+articleVector.size());
}
else{
//System.out.println("arti
clevector is null");
str = new String[10];
}
//get the current date as initial date for start and end date, if Vector is not empty, then use date from Vector
GregorianCalendar currentDay=new GregorianCalendar();
String currentYear=Integer.toStri
ng(current
Day.get(Gr
egorianCal
endar.YEAR
));
String currentMonth=Integer.toStr
ing(curren
tDay.get(G
regorianCa
lendar.MON
TH)+1);
String currentDate=Integer.toStri
ng(current
Day.get(Gr
egorianCal
endar.DATE
));
String start_mm = currentMonth;
String start_dd = currentDate;
String start_yy = currentYear;
String end_mm = currentMonth;
String end_dd = currentDate;
String end_yy = currentYear;
String more_contact ="";
String phone1 = "";
String phone2 = "";
String phone3 = "";
String phone = "";
if(articleVector.size() != 0){
//System.out.println("arti
cleVector is not null in articleForm");
str = (String[])articleVector.ge
t(0);
start_mm = str[2].substring(5, 7).trim();
start_dd = str[2].substring(8, 10).trim();
start_yy = str[2].substring(0, 4).trim();
end_mm = str[3].substring(5, 7).trim();
end_dd = str[3].substring(8, 10).trim();
end_yy = str[3].substring(0, 4).trim();
more_contact = convertNull(str[4]);
if(str[5]== null||str[5].length()!=10)
{
phone1 = ""; phone2 = ""; phone3 = "";
}
else{
phone1 = str[5].substring(0,3).trim
();
phone2 = str[5].substring(3,6).trim
();
phone3 = str[5].substring(6,10).tri
m();
}
}
else{
//System.out.println("arti
cleVector is null in articleForm");
for(int i = 0; i < 10; i++){
str[i] = "";
}
}
%>
<form name="form1" method = "post" action = "ArticleFormHandler">
<input type="hidden" name="page" value="<%=thepage%>" />
<input type="hidden" name="modify" value="<%=modify%>" />
<input type="hidden" name="articleID" value="<%=articleID%>" />
<%if(isAdmin){ //adminForm
%>
<!--pass nextView from form to formhandler-->
<input type="hidden" name="nextView" value="<%=nextView%>" />
<input type="hidden" name="lastVisitedPage" value="adminForm" />
<input type="hidden" name="post_uid" value="<%=post_uid%>" />
<input type="hidden" name="category" value="<%=category%>" />
<%}
else //articleForm
{%>
<input type="hidden" name="lastVisitedPage" value="articleForm" />
<%}%>
<%
if(error!=null){
%>
<font color='red'><b><%=error%><
/b></font>
<%
}
%>
<table width="300">
<tr><td align="left"><font face="Arial" size="2" color="#2C2C81"><b>
<!-- <a href='javascript:ShowMoreI
nfo();' style='{Text-Decoration:Un
derline;}'
>
-->
<a href="
http://csd.njit.edu/bulletin" target="_blank">
Bulletin Guidelines. </a>
</b></font><br />
<br /></td></tr>
<tr><td align="left"><font face="Arial" size="2" color="#2C2C81"><i>
Remember, items that have previously been posted should not be reposted, including reminders.
</i></font><br />
<br /></td></tr>
<tr><td align="left"><font face="Arial" size="2" color="#2C2C81"><b>
<%=isAdmin?"Please check the following form to approve or reject the article:":"Please fill out the following form to publish your article:"%>
</b><br />
<br /></td></tr>
<tr><td align="left"><font face="Arial" size="2" color="#2C2C81"><i>
Please mouse over the title of any section header for a brief help descr
iption.
</i></font><br />
<br /></td></tr>
<tr><td align="left"><div title="Enter a brief descriptive title here"><font face="Arial" size="2" color="#2C2C81"><b>Title:<
/b></div><
/td></tr>
<tr><td><input type = "text" name = "articleTitle" size="80" value = "<%=str[0]%>"maxlength="80
" /></td></tr>
<tr><td align="left">
<div id="texttitle" title="Type or copy & paste the full text of your bulletin here. Do not enter anything you do not want to actually appear in the bulletin in this box.">
<font face="Arial" size="2" color="#2C2C81"><b>Text:</
b>
(HTML Source Code) <b>For non-HTML text, use <BR> for new paragraph.</b>
<input type="button" onclick='javascript:firstW
indow(this
.form)' value='View' />
</div>
</td></tr>
<tr><td><textarea id='id1' name = "articleText" rows="18" cols="60"><%=str[1]%></tex
tarea></td
></tr>
<script type="text/javascript" defer="1">
// All our custom buttons will call this function when clicked.
// We use the buttonId parameter to determine what button
// triggered the call.
// FIXME!!! this should return false for IE < 5.5
function checkBrowse() {
//return false;
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 false;
}
}
return HTMLArea.is_gecko || HTMLArea.is_ie;
};
function clickHandler(editor, buttonId) {
switch (buttonId) {
case "my":
var html = prompt("Enter some HTML code here");
if (html) {
editor.insertHTML(html);
}
break;
case "my-date":
editor.insertHTML((new Date()).toString());
break;
case "my-bold":
editor.execCommand("bold")
;
editor.execCommand("italic
");
break;
case "my-hilite":
editor.surroundHTML("<span
class=\"hilite\">", "</span>");
break;
}
};
</script>
<%if(isAdmin){
%>
<script type="text/javascript" defer="1">
// Create a new configuration object
var config = new HTMLArea.Config();
// Register our custom buttons
config.registerButton("my"
, "Insert HTML code", "images/my.gif", false, clickHandler);
config.registerButton("my-
date", "Insert date/time", "my-date.gif", false, clickHandler);
config.registerButton("my-
bold", "Toggle bold/italic", "my-bold.gif", false, clickHandler);
config.registerButton("my-
hilite", "Hilite selection", "my-hilite.gif", false, clickHandler);
// Append the buttons to the default toolbar
//config.toolbar.push(["my
-toc", "my-date", "my-bold", "my-hilite"]);
if(!document.all){ //Netscape Navigator Detected
config.toolbar = [
[ "fontname", "space",
"fontsize", "space",
"formatblock", "space",
"bold", "italic", "underline", "separator",
"strikethrough", "subscript", "superscript", "separator",
"copy", "cut", "paste" ],
[ "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
"insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
"forecolor", "hilitecolor", "textindicator", "separator",
"inserthorizontalrule", "createlink", "insertimage", "inserttable", "separator",
"popupeditor", "separator", "showhelp", "my" ]
];
}else{
config.toolbar = [
[ "fontname", "space",
"fontsize", "space",
"formatblock", "space",
"bold", "italic", "underline", "separator",
"strikethrough", "subscript", "superscript", "separator",
"copy", "cut", "paste" ],
[ "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
"insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
"forecolor", "hilitecolor", "textindicator", "separator",
"inserthorizontalrule", "createlink", "insertimage", "inserttable", "htmlmode", "separator",
"popupeditor", "separator", "showhelp", "my" ]
];
}
// Replace an existing textarea with an HTMLArea object having the above config.
if(checkBrowse()){
HTMLArea.replace("id1", config);
document.getElementById("t
exttitle")
.innerHTML
= "<font face='Arial' size='2' color='#2C2C81'><b>Text - HTML Editor:</b><b> (Support IE 5.5 and higher, Netscape 7.1, Mozilla 1.3)<br><b> (If the Text Area doesn't appear, <A HREF='javascript:history.g
o(0)'>Clic
k here to refresh the page</A>)</b>";
}
//HTMLArea.replace("id1");
</script>
<%}else{%>
<script type="text/javascript" defer="1">
// Create a new configuration object
var config = new HTMLArea.Config();
// Append the buttons to the default toolbar
//config.toolbar.push(["my
-toc", "my-date", "my-bold", "my-hilite"]);
config.toolbar = [
[ "fontname", "space",
"fontsize", "space",
"formatblock", "space",
"bold", "italic", "separator",
"copy", "cut", "paste" ],
[ "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
"insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
"inserthorizontalrule", "createlink", "insertimage", "inserttable", "separator",
"popupeditor", "separator", "showhelp"]
];
// Replace an existing textarea with an HTMLArea object having the above config.
if(checkBrowse()){
HTMLArea.replace("id1", config);
document.getElementById("t
exttitle")
.innerHTML
= "<font face='Arial' size='2' color='#2C2C81'><b>Text - HTML Editor:</b><b> (Support IE 5.5 and higher, Netscape 7.1, Mozilla 1.3) <br><b> (If the Text Area doesn't appear, <A HREF='javascript:history.g
o(0)'>Clic
k here to refresh the page</A>)</b>";
}
//HTMLArea.replace("id1");
</script>
<%}%>
<tr><td align="left"><div title="Enter the date you would like your bulletin to begin appearing. This is typically no more than a week or two before the event.">
<font face="Arial" size="2" color="#2C2C81"><b>Publish
- Start Date:</b></font></div></td
></tr>
<tr><td>
<select name="start_mm">
<%for(int i=1;i<=12;i++){%>
<option value="<%=i%>"<%if(Integer
.parseInt(
start_mm)=
=i) out.println("SELECTED"); %> ><%=monthDesc[i-1]%>
<%}%>
</option>
</select> /
<select name="start_dd">
<%for(int i=1;i<=31;i++){%>
<option <%if(Integer.parseInt(star
t_dd)==i) out.println("SELECTED"); %>><%=i%>
<%}%>
</option>
</select> /
<select name="start_yy">
<%for(int i=Integer.parseInt(current
Year);i<=I
nteger.par
seInt(curr
entYear)+4
;i++){%>
<option <%if(Integer.parseInt(star
t_yy)==i) out.println("SELECTED"); %>><%=i%>
<%}%>
</option>
</select>
</td></tr>
<tr><td align="left"><div title="Enter the date you would like your bulletin to stop appearing. This is typically the date of the event.">
<font face="Arial" size="2" color="#2C2C81"><b>Publish
- End Date:</b></font></div></td
></tr>
<tr><td>
<select name="end_mm">
<%for(int i=1;i<=12;i++){%>
<option value="<%=i%>"<%if(Integer
.parseInt(
end_mm)==i
) out.println("SELECTED"); %> ><%=monthDesc[i-1]%>
<%}%>
</option>
</select> /
<select name="end_dd">
<%for(int i=1;i<=31;i++){%>
<option <%if(Integer.parseInt(end_
dd)==i) out.println("SELECTED"); %>><%=i%>
<%}%>
</option>
</select> /
<select name="end_yy">
<%for(int i=Integer.parseInt(current
Year);i<=I
nteger.par
seInt(curr
entYear)+4
;i++){%>
<option <%if(Integer.parseInt(end_
yy)==i) out.println("SELECTED"); %>><%=i%>
<%}%>
</option>
</select>
</td></tr>
<tr><td align="left"><div title="Choose the category in which you would like your bulletin to appear, using the information posted in the bulletin guidelines. If an incorrect category is chosen, an administrator may change it before posting.">
<font face="Arial" size="2" color="#2C2C81"><b>Categor
y:</b></fo
nt></div><
/td></tr>
</table>
<%
String check;
if(articleVector.size() > 1 ){
//clear the "j_selected" in categoryHashMap
for(int j = 0; j < categorySize; j++){
categoryHashMap.put(j+"_se
lected",""
);
}
//find out which category has been selected
for(int i = 0; i < articleVector.size()-1; i++){
String[] strtmp = (String[])articleVector.ge
t(i+1);
check = strtmp[0];
//System.out.println("chec
k: "+check.charAt(0));
//to set the categoryHashMap as "selected" if there is the same code in the article_info for the article_id
if(categoryHashMap.size() > 0 ){
for(int j = 0; j < categorySize; j++){
if(check.equals(categoryHa
shMap.get(
j+"_code")
))
categoryHashMap.put(j+"_se
lected","s
elected");
}//end of inner for
}//end of inner if
}//end of outer for
}//end of outer if
%>
<table>
<tr>
<select name="selectedCategory">
<%
if(categoryHashMap.size() > 0 ){
System.out.println("catego
rysize="+c
ategorySiz
e);
System.out.println("isSupe
rAdmin?="+
isSuperAdm
in);
for (int k = 0; k < categorySize; k++){
System.out.println("priv="
+(String)c
ategoryHas
hMap.get(k
+"_priv"))
;
System.out.println("select
ed="+(Stri
ng)categor
yHashMap.g
et(k+"_sel
ected"));
if(!isAdmin||("selected").
equals((St
ring)categ
oryHashMap
.get(k+"_s
elected"))
||(isSuper
Admin&&("E
").equalsI
gnoreCase(
(String)ca
tegoryHash
Map.get(k+
"_priv")))
){
%>
<option value="<%=categoryHashMap.
get(k+"_co
de")%>" <%=categoryHashMap.get(k+"
_selected"
)%> > <%=categoryHashMap.get(k+"
_des")%>
<% }
}
}
%>
</option>
</select>
</tr>
</table>
<table>
<tr>
<td align="left"><div title="Enter the full name of someone to contact for further information.">
<font face="Arial" size="2" color="#2C2C81"><b>Further
Contact:</b>(Optional)</di
v></td>
</tr>
<tr>
<td><input type = "text" name = "more_contact" size="50" value = "<%=more_contact%>"maxleng
th="80" /></td>
</tr>
</table>
<table>
<tr>
<td align="left"><div title="Enter the phone number of someone to contact for further information.">
<font face="Arial" size="2" color="#2C2C81"><b>Telepho
ne:</b>(Op
tional)</d
iv></td>
</tr>
<tr>
<td>
<input type="text" size="3" maxlength="3" value = "<%=phone1%>" name="phone1" />
-
<input type="text" size="3" maxlength="3" value = "<%=phone2%>" name="phone2" />
-
<input type="text" size="4" maxlength="4" value = "<%=phone3%>" name="phone3" />
</td>
</tr>
<%
//if(!isAdmin){//articleFo
rm
if(1==2){//disable department for both articleForm and adminForm
%>
<tr>
<td align="left"><font face="Arial" size="2" color="#2C2C81"><b>
<%
if(deptVector.size()>1)
out.println("Please select your Department:");
else
out.println("Your Department:");
%>
</b>
</td>
</tr>
<tr>
<td>
<select name="deptIndex">
<%
if(deptVector.size() > 0 ){
for(int i = 0; i < deptVector.size(); i++){
String [] str1= (String[])deptVector.get(i
);
%>
<option value="<%=i%>" <%=(str1[0].equals(str[7])
&&str1[1].
equals(str
[8]))||
(deptVector.size()==1)?"se
lected":""
%> > <%=str1[2]%>
<%
}
}
%>
</option>
</select>
</td>
</tr>
<%
}
%>
<%
if(isAdmin){
submitValue="Publish";
}
else
{
submitValue="Submit for Approval";
}
%>
</table>
<table>
<br />
<br />
<% System.out.println(isAdmin
);%>
<%if(isAdmin){//adminForm
%>
<input type="submit" value="<%=submitValue%>" name="approve" onclick="return confirmSubmit(this.form,'A
re you sure you want to publish this article?')" />
<input type="submit" value="Reject" name="delete" onclick="return confirmSubmit(this.form,'A
re you sure you want to reject this article?')" />
<%}
else { //articleForm
%>
<input type="submit" value="Submit for Approval" name="approval" onclick="return confirmSubmit(this.form,'A
re you sure you want to submit this article?')" />
<input type="submit" value="Save Draft" name="edit" />
<%}%>
<!--<input type=button OnClick='javascript:firstW
indow(this
.form)' value='View' ></div>-->
<input type="reset" value="reset" onClick="form1.articleText
.setText("
");"/>
<input type="submit" value="Cancel" name="cancel" />
</form>
</table>
</body>
</html>
Any suggestions on how to reset the form items.