function cRichTextEditor(){ this.editor; this.table; this.id; this.buildEditor(); } cRichTextEditor.prototype.loadEditor = function(ID) { this.id = ID; parentDiv = document.getElementById("body_position_"+this.id); this.editor = "body_"+this.id; if(this.table.parentNode) this.table.parentNode.removeChild(this.table); if(parentDiv.firstChild){ parentDiv.insertBefore(this.table,parentDiv.firstChild); } else parentDiv.appendChild(this.table); if(!Element(this.editor)){ iframe = document.createElement("IFRAME"); iframe.id = this.editor; iframe.name = this.editor; iframe.width = "99%"; iframe.height = 300; iframe.setAttribute("unselectable","on"); iframe.setAttribute("tabIndex","1"); var checkbox = document.createElement("INPUT"); checkbox.id = 'viewsource_rt_checkbox'; checkbox.type = "checkbox"; checkbox.setAttribute("tabIndex","-1"); checkbox.onclick = function () {RichTextEditor.viewsource(this.checked)}; var text = document.createTextNode(get_lang('View HTML source') + '.'); parentDiv.appendChild(iframe); parentDiv.appendChild(checkbox); parentDiv.appendChild(text); } else{ Element("viewsource_rt_checkbox").checked=false; } document.getElementById('fontname').selectedIndex = 1; document.getElementById('fontsize').selectedIndex = 1; } cRichTextEditor.prototype.viewsource = function(source) { var html; var mainField = document.getElementById(this.editor).contentWindow; if (source) { if (is_ie){ connector.loadScript('html2xhtml'); html = frames[this.editor].document.body; var xhtml = get_xhtml(html, 'en', 'iso-8859-1'); frames[this.editor].document.body.innerText = xhtml; document.getElementById("table_richtext_toolbar").style.visibility="hidden"; } else{ html = document.createTextNode(document.getElementById(this.editor).contentWindow.document.body.innerHTML); document.getElementById(this.editor).contentWindow.document.body.innerHTML = ""; html = document.getElementById(this.editor).contentWindow.document.importNode(html,false); document.getElementById(this.editor).contentWindow.document.body.appendChild(html); document.getElementById("table_richtext_toolbar").style.visibility="hidden"; } } else { if (is_ie){ var output = escape(frames[this.editor].document.body.innerText); output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E"); output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E"); frames[this.editor].document.body.innerHTML = unescape(output); document.getElementById("table_richtext_toolbar").style.visibility="visible"; } else{ html = document.getElementById(this.editor).contentWindow.document.body.ownerDocument.createRange(); html.selectNodeContents(document.getElementById(this.editor).contentWindow.document.body); document.getElementById(this.editor).contentWindow.document.body.innerHTML = html.toString(); document.getElementById("table_richtext_toolbar").style.visibility="visible"; } } } cRichTextEditor.prototype.buildEditor = function() { this.table = document.createElement("TABLE"); this.table.id = "table_richtext_toolbar"; this.table.className = "richtext_toolbar"; this.table.width = "100%"; var tbody = document.createElement("TBODY"); var tr = document.createElement("TR"); var td = document.createElement("TD"); var div_button_rt = document.createElement("DIV"); selectBox=document.createElement("SELECT"); selectBox.id="fontname"; selectBox.setAttribute("tabIndex","-1"); selectBox.onchange = function () {RichTextEditor.Select("fontname");}; selectBox.className = 'select_richtext'; var option1 = new Option(get_lang('Font'), 'Font'); var option2 = new Option('Arial', 'Arial'); var option3 = new Option('Courier', 'Courier'); var option4 = new Option('Times New Roman', 'Times'); if (is_ie){ selectBox.add(option1); selectBox.add(option2); selectBox.add(option3); selectBox.add(option4); } else{ selectBox.add(option1, null); selectBox.add(option2, null); selectBox.add(option3, null); selectBox.add(option4, null); } div_button_rt.appendChild(selectBox); selectBox=document.createElement("SELECT"); selectBox.id="fontsize"; selectBox.setAttribute("tabIndex","-1"); selectBox.setAttribute("unselectable","on"); selectBox.className = 'select_richtext'; selectBox.onchange = function () {RichTextEditor.Select("fontsize");}; var option1 = new Option(get_lang('Size'), 'Size'); var option2 = new Option('1 (8 pt)','1' ); var option3 = new Option('2 (10 pt)','2'); var option4 = new Option('3 (12 pt)','3'); var option5 = new Option('4 (14 pt)','4'); var option6 = new Option('5 (18 pt)','5'); var option7 = new Option('6 (24 pt)','6'); var option8 = new Option('7 (36 pt)','7'); if (is_ie){ selectBox.add(option1); selectBox.add(option2); selectBox.add(option3); selectBox.add(option4); selectBox.add(option5); selectBox.add(option6); selectBox.add(option7); selectBox.add(option8); } else{ selectBox.add(option1, null); selectBox.add(option2, null); selectBox.add(option3, null); selectBox.add(option4, null); selectBox.add(option5, null); selectBox.add(option6, null); selectBox.add(option7, null); selectBox.add(option8, null); } div_button_rt.appendChild(selectBox); var buttons = ['bold', 'italic', 'underline', 'forecolor', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'undo', 'redo', 'insertorderedlist', 'insertunorderedlist', 'outdent', 'indent', 'link', 'signature']; for (var i=0; i")); } } else{ mainField.document.execCommand('inserthtml', false, preferences.signature.replace(/\n/g, "
")); } } else mainField.document.execCommand(command, false, option); //mainField.focus(); } catch (e) {} } cRichTextEditor.prototype.createLink = function(){ var mainField = document.getElementById(this.editor).contentWindow; if (is_ie){ if ((mainField.document.selection.createRange().text) == ''){ alert(get_lang('Chose the text you want transform in link before.')); return; } } else{ if (mainField.window.getSelection() == ''){ alert(get_lang('Chose the text you want transform in link before.')); return; } } var szURL = prompt(get_lang('Enter with link URL:", "http://"')); if ((szURL != null) && (szURL != "")){ this.editorCommand("CreateLink", szURL); } } cRichTextEditor.prototype.Select = function(selectname) { var mainField = Element(this.editor).contentWindow; var cursel = document.getElementById(selectname).selectedIndex; if (cursel != 0) { var selected = document.getElementById(selectname).options[cursel].value; mainField.document.execCommand(selectname, false, selected); document.getElementById(selectname).selectedIndex = cursel; } mainField.focus(); } cRichTextEditor.prototype.show_pc = function(command) { connector.loadScript("color_palette"); ColorPalette.loadPalette(this.id); if (ColorPalette.div.style.visibility != "visible") ColorPalette.div.style.visibility="visible"; else this.hide_pc(); } cRichTextEditor.prototype.hide_pc = function() { document.getElementById("palettecolor").style.visibility="hidden"; } cRichTextEditor.prototype.getOffsetTop = function(elm) { var mOffsetTop = elm.offsetTop;1 var mOffsetParent = elm.offsetParent; while(mOffsetParent){ mOffsetTop += mOffsetParent.offsetTop; mOffsetParent = mOffsetParent.offsetParent; } return mOffsetTop; } cRichTextEditor.prototype.getOffsetLeft = function(elm) { var mOffsetLeft = elm.offsetLeft; var mOffsetParent = elm.offsetParent; while(mOffsetParent){ mOffsetLeft += mOffsetParent.offsetLeft; mOffsetParent = mOffsetParent.offsetParent; } return mOffsetLeft; } //Build the Object RichTextEditor = new cRichTextEditor();