// // htmlArea v1.05 - Copyright (c) 2002 interactivetools.com, inc. // A free WYSIWYG editor replacement for fields. // // For more information visit: // http://www.interactivetools.com/products/htmlarea/ // /* ---------------------------------------------------------------------- *\ 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,bckgrnd,w,h) { //bgcolor added by wally // Default Settings var imgURL = _editor_url + 'img/'; // 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' + ' Arial\n' + ' Courier New\n' + ' Georgia\n' + ' Tahoma\n' + ' Times New Roman\n' + ' Verdana\n' + ' WingDings\n' + ' ' + ' \n' + ' \n' + '\n' */ /* + '\n' + ' \n' + ' \n' + '\n' + ' 1234567\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' + '' /* + '\n' */ + '\n' + '\n' + '' /* + '' */ + '' // added by wally /* + '\n' // removed by wally - to be altered for file upload soon. */ + '\n' /* + '\n' + '' // ----------- // CAUTION: You may NOT remove or hide this button. If displays the "About this editor" popup // and is required by the license agreement for the editor. + '' // ----------- + '\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', bckgrnd , '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.php", editdoc, "resizable: no; help: no; status: no; scroll: no; dialogHeight: 255px;"); // edited by wally: insert_image.html -> insert_image.php, added dialogHeight: 220px; } // show about {corrected by wally} else if (cmdID.toLowerCase() == 'about'){ var html = 'About\n' + '\n' + '\n\n' + 'htmlArea by interactivetools.com\n' + 'A free WYSIWYG editor replacement for <textarea> fields.\n\n' + '\n' + 'Copyright (c) 2002 interactivetools.com, inc.\n\n' + 'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n' + 'a) The above copyright notice, this permission notice, and the "About this editor" button that appears as a question mark in the editor interface, shall be included in all copies or substantial portions of the Software.\n\n' + 'b) The "About this editor" button that appears as a question mark ("?") in the editor interface must always be visible in the editor interface and bring up the original "About" dialog window when clicked.\n\n' + 'c) The "About" dialog window and its contents, including the link to interactivetools.com can not be amended.\n\n' + 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n' + '\n\n' + 'For more information visit:\n' + 'http://www.interactivetools.com/products/htmlarea/\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); } else if (cmdID.toLowerCase() == 'linebreak'){ // added by wally editor_insertHTML(objname,''); } // 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','LineBreak'); // LineBreak added by wally for (i=0; i\n' + '\n' + '\n' + '' + contents + '\n' + '
\n' + 'Copyright (c) 2002 interactivetools.com, inc.\n\n' + 'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n' + 'a) The above copyright notice, this permission notice, and the "About this editor" button that appears as a question mark in the editor interface, shall be included in all copies or substantial portions of the Software.\n\n' + 'b) The "About this editor" button that appears as a question mark ("?") in the editor interface must always be visible in the editor interface and bring up the original "About" dialog window when clicked.\n\n' + 'c) The "About" dialog window and its contents, including the link to interactivetools.com can not be amended.\n\n' + 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n' + '\n\n' + '
For more information visit:\n' + 'http://www.interactivetools.com/products/htmlarea/\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); } else if (cmdID.toLowerCase() == 'linebreak'){ // added by wally editor_insertHTML(objname,''); } // 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