// HyperTextArea http://hypertextarea.sourceforge.net // Type javascript:HyperTextArea.about() into your browser location on any page hosting a HyperTextArea for license details. function HyperTextArea(name, html, width, height,resourcePath,styleSheetUrl,delayRender){ this.isRichText = false; this.rng = null; this.name = name; this.html = html||""; this.width = width; this.height = height; this.resourcePath = resourcePath||""; this.styleSheetUrl = styleSheetUrl||null; if(this.resourcePath.length && this.resourcePath.substring(this.resourcePath.length-1) != "/"){ this.resourcePath = this.resourcePath + "/"; } this.delayRender = delayRender||false; this.controlNames = new Array(); this.controlsByName = new Array(); this.toolbarNames = new Array(); this.designModeRetryCount = 0; this.isSrcView = false; this.init = function(){ HyperTextArea.areas[this.name] = this; //check to see if designMode mode is available if (document.getElementById) { if (document.all) { //check for Internet Explorer 5+ this.isRichText = true; } else { //check for browsers that support designmode //make sure that this is not safari (and perhaps other khtml based browsers) which returns "inherit" for document.designMode if (document.designMode && document.designMode.toLowerCase() != "inherit"){ this.isRichText = true; } } } this.addControl(new Toolbar("toolbar0")); //menus styleMenu = new Menu("formatblock","formatblock"); styleMenu.addItems("","Style","
","Paragraph","
","Preformatted"); this.addControl(styleMenu); fontMenu = new Menu("fontname","fontname"); fontMenu.addItems("","Font","Arial, Helvetica, sans-serif","Arial","Courier New, Courier, mono","Courier New","Times New Roman, Times, serif","Times New Roman","Verdana, Arial, Helvetica, sans-serif","Verdana"); this.addControl(fontMenu); sizeMenu = new Menu("fontsize","fontsize"); sizeMenu.addItems("","Size",1,1,2,2,3,3,4,4,5,5,6,6,7,7); this.addControl(sizeMenu); this.addControl(new Toolbar("toolbar1")); //add default controls this.addControl(new TextFormatButton("bold","Bold","images/post_button_bold.gif","bold")); this.addControl(new TextFormatButton("italic","Italic","images/post_button_italic.gif","italic")); this.addControl(new Spacer()); this.addControl(new TextFormatButton("left","Align Left","images/post_button_left_just.gif","justifyleft")); this.addControl(new TextFormatButton("center","Center","images/post_button_centre.gif","justifycenter")); this.addControl(new TextFormatButton("right","Align Right","images/post_button_right_just.gif","justifyright")); this.addControl(new Spacer()); this.addControl(new TextFormatButton("orderedlist","Ordered List","images/post_button_numbered_list.gif","insertorderedlist")); this.addControl(new TextFormatButton("unorderedlist","Unordered List","images/post_button_list.gif","insertunorderedlist")); this.addControl(new Spacer()); this.addControl(new TextFormatButton("outdent","Outdent","images/post_button_outdent.gif","outdent")); this.addControl(new TextFormatButton("indent","Indent","images/post_button_indent.gif","indent")); this.addControl(new TextFormatButton("forecolor","Text Color","images/post_button_textcolor.gif","forecolor")); this.addControl(new TextFormatButton("hilitecolor","Background Color","images/post_button_bgcolor.gif","hilitecolor")); this.addControl(new Spacer()); this.addControl(new Button("insertImage","images/post_button_image.gif","Insert Image","addImage")); this.addControl(new TextFormatButton("link","Create Link","images/post_button_hyperlink.gif","createlink")); this.addControl(new Button("insertTable","images/post_button_table.gif","Insert Table","insertTableDialog")); } this.addControl = function(control){ control.resourcePath = this.resourcePath; control.area = this; i = this.controlNames.length this.controlNames[eval(i)] = control.name; this.controlsByName[control.name] = control; } this.getControl = function(name){ return this.controlsByName[name]; } this.replaceControl = function(oldName,newControl){ if(this.getControl(oldName)){ for(i=0;i' + html + ''); } this.getControlNames = function(lable){ text= lable + "\n\n"; for(i=0;i '; text = text + ''; document.writeln(text); } this._renderRTE = function(){ document.writeln(''); this._renderControls(); document.writeln(''); document.writeln('
View Source'); //reimplement this so that it is not in an iframe, rather in a div. document.writeln(''); document.writeln(''); document.getElementById('hdn' + this.name).value = this.html; this.initializeContent(this.html); setTimeout('onHyperTextAreaLoad(\'' + this.name + '\')', 500); } this.initializeContent = function(html){ HyperTextArea.activeArea = this; var frameHtml = "\n"; frameHtml += "\n"; if (this.styleSheetUrl){ frameHtml += "\n"; } frameHtml += "\n"; frameHtml += "\n"; frameHtml += html; frameHtml += "\n"; frameHtml += ""; if (document.all) { var oRTE = frames[this.name].document; oRTE.open(); oRTE.write(frameHtml); oRTE.close(); } else { var oRTE = document.getElementById(this.name).contentWindow.document; oRTE.open(); oRTE.write(frameHtml); oRTE.close(); //attach a keyboard handler for Mozilla to make keyboard shortcuts for formatting text work oRTE.addEventListener("keypress", kb_handler, true); } } this.setContent = function(html){ HyperTextArea.activeArea = this; var oRTE; if (document.all) { oRTE = frames[this.name].document; } else { oRTE = document.getElementById(this.name).contentWindow.document; } body = oRTE.getElementsByTagName("body"); body.innerHTML = html; } this.update = function(){ this.setViewMode(false); //set message value var oHdnMessage = document.getElementById('hdn' + this.name); var oRTE = document.getElementById(this.name); if (this.isRichText) { if (oHdnMessage.value == null) oHdnMessage.value = ""; if (document.all) { oHdnMessage.value = frames[this.name].document.body.innerHTML; } else { oHdnMessage.value = oRTE.contentWindow.document.body.innerHTML; } //if there is no content (other than formatting) set value to nothing if (stripHTML(oHdnMessage.value.replace(" ", " ")) == "") oHdnMessage.value = ""; this.html = oHdnMessage.value; } } this.setToolbarsVisible = function(isVisible){ visibleStyle = isVisible?"visible":"hidden"; for (x=0;x' text = text + ''; text = text + ''; return text; } this.execute = function(){ this.area.formatText(this.command,this.option); } } function Button(name,icon,title,methodName){ this.name=name; this.getRenderedText = function(){ text = ' '; return text; } } function Spacer(name){ this.name = name this.getRenderedText = function(){ return ' ' text = text + ''; text = text + '' } } function Toolbar(name, isFirstToolbar){ this.name = name this.isFirstToolbar = isFirstToolbar||false; this.getRenderedText = function(){ this.area.toolbarNames[this.area.toolbarNames.length] = this.name; text = ' \n' + text; } return text; } } function Menu(name,cmd){ this.name = name; this.cmd = cmd; this.area = null; this.items = new Array(); this.addItem = function(value,lable){ this.items[this.items.length] = new MenuItem(value,lable); } this.addItems = function(){ for (i=0;i
' if(this.isFirstToolbar){ text = ' \n"; for (i=0;i "+thisItem.lable+"\n"; } text = text + ""; return text; } } function MenuItem(value,lable){ this.value = value; this.lable = lable; } HyperTextArea.areas = new Array(); HyperTextArea.getArea = function(name){ return HyperTextArea.areas[name]; } HyperTextArea.activeArea = null; HyperTextArea.about = function(){ var area; for(i in HyperTextArea.areas){ area = HyperTextArea.getArea(i); break; } window.open(area.resourcePath + "about.html"); } HyperTextArea.updateAllAreas = function(){ //iterate over all areas and call update for(i in HyperTextArea.areas){ area = HyperTextArea.areas[i]; area.update(); } } HyperTextArea.forms = new Array(); function getOffsetTop(elm) { var mOffsetTop = elm.offsetTop; var mOffsetParent = elm.offsetParent; while(mOffsetParent){ mOffsetTop += mOffsetParent.offsetTop; mOffsetParent = mOffsetParent.offsetParent; } return mOffsetTop; } function getOffsetLeft(elm) { var mOffsetLeft = elm.offsetLeft; var mOffsetParent = elm.offsetParent; while(mOffsetParent) { mOffsetLeft += mOffsetParent.offsetLeft; mOffsetParent = mOffsetParent.offsetParent; } return mOffsetLeft; } function kb_handler(evt, rte) { //contributed by Anti Veeranna (thanks Anti!) if (evt.ctrlKey) { var key = String.fromCharCode(evt.charCode).toLowerCase(); var cmd = ''; switch (key) { case 'b': cmd = "bold"; break; case 'i': cmd = "italic"; break; case 'u': cmd = "underline"; break; }; if (cmd) { evt.target.ownerDocument.execCommand(cmd,false,true); // stop the event bubble evt.preventDefault(); evt.stopPropagation(); } } } function stripHTML(oldString) { var newString = oldString.replace(/(<([^>]+)>)/ig,""); //replace carriage returns and line feeds newString = escape(newString) newString = newString.replace("%0D%0A"," "); newString = newString.replace("%0A"," "); newString = newString.replace("%0D"," "); newString = unescape(newString) //trim string newString = trim(newString); return newString; } function trim(inputString) { // Removes leading and trailing spaces from the passed string. Also removes // consecutive spaces and replaces it with one space. If something besides // a string is passed in (null, custom object, etc.) then return the input. if (typeof inputString != "string") { return inputString; } var retValue = inputString; var ch = retValue.substring(0, 1); while (ch == " ") { // Check for spaces at the beginning of the string retValue = retValue.substring(1, retValue.length); ch = retValue.substring(0, 1); } ch = retValue.substring(retValue.length-1, retValue.length); while (ch == " ") { // Check for spaces at the end of the string retValue = retValue.substring(0, retValue.length-1); ch = retValue.substring(retValue.length-1, retValue.length); } while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings } return retValue; // Return the trimmed string back to the user } function getPaletteAsString(){ hexArray = new Array("00","55","AA","FF"); out = ""; out2 = ""; line = "" row = 1; count = 1; for(i=hexArray.length-1;i>=0;i--){ val0 = hexArray[i]; for(j=hexArray.length-1;j>=0;j--){ val1 = hexArray[j]; for(k=hexArray.length-1;k>=0;k--){ val2 = hexArray[k]; hexVal = val0+val1+val2; line = line + "\n "; if(count==1 || (row % 2) == 0){ if(((count - 1) % 8) == 0){ out = out + "\n "; row++ } out = out + line; if((count % 8) == 0){ out = out + "\n "; } }else{ if(((count - 1) % 8) == 0){ out2 = out2 + "\n"; row++ } out2 = out2 + line; if((count % 8) == 0){ out2 = out2 + "\n "; } } line = ""; count++; } } } out = '' + out + out2 + "
"; return out; } function getTableDialogAsString(){ out = ''; return out; } function enableDesignMode(areaName){ try{ if (document.all) { frames[areaName].document.designMode = "On"; }else{ contentDocument = document.getElementById(areaName).contentDocument; contentDocument.designMode = "on"; } self.status = ""; area.setContent(area.html) }catch(e){ //attempt to recover from any exceptions exp = "enableDesignMode('"+areaName+"')"; area = HyperTextArea.getArea(areaName); area.designModeRetryCount++ self.status = "Error in setting designMode property on attempt number "+ area.designModeRetryCount +". Retrying."; if(area.designModeRetryCount <= 10){ t = setTimeout(exp,100); }else{ self.status = areaName + " failed to initialize properly"; throw e; } } } function onHyperTextAreaLoad(areaName) { self.status = "attempting to set designMode property"; area = HyperTextArea.getArea(areaName); area.cpWindow = frames['cp' + areaName].window; //enables the area to determine what form it belongs to area.form = document.getElementById("hdn"+areaName).form; //attaches to the forms submit handler only once formAlreadyStored = false; for(i=0;i