[2] | 1 | function cRichTextEditor(){ |
---|
[271] | 2 | this.emwindow = new Array; |
---|
[320] | 3 | this.editor = "body_1"; |
---|
| 4 | this.table = ""; |
---|
| 5 | this.id = "1"; |
---|
[2] | 6 | this.buildEditor(); |
---|
[271] | 7 | this.saveFlag = 0; |
---|
[2] | 8 | } |
---|
| 9 | |
---|
| 10 | cRichTextEditor.prototype.loadEditor = function(ID) { |
---|
[320] | 11 | var _this = this; |
---|
| 12 | _this.id = ID; |
---|
[2] | 13 | parentDiv = document.getElementById("body_position_"+this.id); |
---|
| 14 | this.editor = "body_"+this.id; |
---|
[320] | 15 | |
---|
| 16 | if(this.table.parentNode) |
---|
| 17 | this.table.parentNode.removeChild(this.table); |
---|
[2] | 18 | |
---|
[320] | 19 | if( parentDiv.firstChild ) |
---|
| 20 | { |
---|
| 21 | if (!parentDiv.firstChild.hasChildNodes()) |
---|
| 22 | parentDiv.insertBefore(this.table,parentDiv.firstChild); |
---|
[2] | 23 | } |
---|
| 24 | else |
---|
| 25 | parentDiv.appendChild(this.table); |
---|
| 26 | |
---|
[320] | 27 | if(!Element(this.editor)) |
---|
| 28 | { |
---|
| 29 | this.createElementEditor(this.editor); |
---|
| 30 | } |
---|
| 31 | else |
---|
| 32 | { |
---|
| 33 | Element("viewsource_rt_checkbox").checked=false; |
---|
| 34 | } |
---|
| 35 | |
---|
[811] | 36 | document.getElementById('fontname').selectedIndex = 0; |
---|
| 37 | document.getElementById('fontsize').selectedIndex = 0; |
---|
[320] | 38 | } |
---|
| 39 | |
---|
| 40 | cRichTextEditor.prototype.createElementEditor = function(pObj) |
---|
| 41 | { |
---|
[2] | 42 | iframe = document.createElement("IFRAME"); |
---|
[320] | 43 | iframe.id = pObj; |
---|
| 44 | iframe.name = pObj; |
---|
[2] | 45 | iframe.width = "99%"; |
---|
| 46 | iframe.height = 300; |
---|
| 47 | iframe.setAttribute("unselectable","on"); |
---|
| 48 | iframe.setAttribute("tabIndex","1"); |
---|
[790] | 49 | |
---|
| 50 | config_events( iframe, 'onload', function( ) |
---|
| 51 | { |
---|
| 52 | iframe.contentWindow.document.designMode = "on"; |
---|
[3238] | 53 | if ( iframe.contentWindow.document.documentElement ){ |
---|
[790] | 54 | iframe.contentWindow.document.documentElement.style.background = '#fff'; |
---|
[3238] | 55 | iframe.contentWindow.document.documentElement.style.fontSize = '16px'; |
---|
| 56 | } |
---|
[790] | 57 | }); |
---|
| 58 | |
---|
[2] | 59 | var checkbox = document.createElement("INPUT"); |
---|
| 60 | checkbox.id = 'viewsource_rt_checkbox'; |
---|
| 61 | checkbox.type = "checkbox"; |
---|
| 62 | checkbox.setAttribute("tabIndex","-1"); |
---|
| 63 | checkbox.onclick = function () {RichTextEditor.viewsource(this.checked)}; |
---|
| 64 | var text = document.createTextNode(get_lang('View HTML source') + '.'); |
---|
| 65 | parentDiv.appendChild(iframe); |
---|
| 66 | parentDiv.appendChild(checkbox); |
---|
| 67 | parentDiv.appendChild(text); |
---|
| 68 | } |
---|
| 69 | |
---|
[3130] | 70 | cRichTextEditor.prototype.loadStyle = function(tag, css_file) { |
---|
| 71 | var theRules = new Array(); |
---|
| 72 | var stylePRE = ""; |
---|
| 73 | for(var s = 0; s < document.styleSheets.length; s++) { |
---|
| 74 | if(document.styleSheets[s].href != null && |
---|
| 75 | document.styleSheets[s].href.match("templates/"+template+"/"+css_file)){ |
---|
| 76 | if (document.styleSheets[s].cssRules) |
---|
| 77 | theRules = document.styleSheets[s].cssRules; |
---|
| 78 | else if (document.styleSheets[s].rules) |
---|
| 79 | theRules = document.styleSheets[s].rules; |
---|
| 80 | break; |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | for(var s = 0;s < theRules.length; s++){ |
---|
| 84 | if(theRules[s].selectorText.toLowerCase() == tag.toLowerCase()){ |
---|
| 85 | stylePRE = theRules[s].style; |
---|
| 86 | break; |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | var _body = Element(this.editor); |
---|
| 90 | var i_doc = (document.all) ? _body.contentWindow.document: _body.contentDocument; |
---|
| 91 | var hh1 = i_doc.getElementsByTagName('head')[0]; |
---|
| 92 | // For IE |
---|
| 93 | if(typeof(hh1) == 'undefined'){ |
---|
| 94 | hh1 = i_doc.createElement("head"); |
---|
| 95 | i_doc.appendChild(hh1); |
---|
| 96 | } |
---|
| 97 | var ss1 = i_doc.createElement('style'); |
---|
| 98 | ss1.setAttribute("type", "text/css"); |
---|
| 99 | var def = tag.toLowerCase()+' {'+stylePRE.cssText+'}'; |
---|
| 100 | if (ss1.styleSheet) { |
---|
| 101 | ss1.styleSheet.cssText = def; |
---|
| 102 | } else { |
---|
| 103 | var tt1 = i_doc.createTextNode(def); |
---|
| 104 | ss1.appendChild(tt1); |
---|
| 105 | } |
---|
| 106 | hh1.appendChild(ss1); |
---|
| 107 | } |
---|
| 108 | |
---|
[2] | 109 | cRichTextEditor.prototype.viewsource = function(source) { |
---|
| 110 | var html; |
---|
| 111 | var mainField = document.getElementById(this.editor).contentWindow; |
---|
| 112 | if (source) { |
---|
| 113 | if (is_ie){ |
---|
| 114 | connector.loadScript('html2xhtml'); |
---|
| 115 | html = frames[this.editor].document.body; |
---|
| 116 | var xhtml = get_xhtml(html, 'en', 'iso-8859-1'); |
---|
| 117 | frames[this.editor].document.body.innerText = xhtml; |
---|
| 118 | document.getElementById("table_richtext_toolbar").style.visibility="hidden"; |
---|
| 119 | } |
---|
| 120 | else{ |
---|
| 121 | html = document.createTextNode(document.getElementById(this.editor).contentWindow.document.body.innerHTML); |
---|
| 122 | document.getElementById(this.editor).contentWindow.document.body.innerHTML = ""; |
---|
| 123 | html = document.getElementById(this.editor).contentWindow.document.importNode(html,false); |
---|
| 124 | document.getElementById(this.editor).contentWindow.document.body.appendChild(html); |
---|
| 125 | document.getElementById("table_richtext_toolbar").style.visibility="hidden"; |
---|
| 126 | } |
---|
| 127 | } else { |
---|
| 128 | if (is_ie){ |
---|
| 129 | var output = escape(frames[this.editor].document.body.innerText); |
---|
| 130 | output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E"); |
---|
| 131 | output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E"); |
---|
| 132 | frames[this.editor].document.body.innerHTML = unescape(output); |
---|
| 133 | document.getElementById("table_richtext_toolbar").style.visibility="visible"; |
---|
| 134 | } |
---|
| 135 | else{ |
---|
| 136 | html = document.getElementById(this.editor).contentWindow.document.body.ownerDocument.createRange(); |
---|
| 137 | html.selectNodeContents(document.getElementById(this.editor).contentWindow.document.body); |
---|
| 138 | document.getElementById(this.editor).contentWindow.document.body.innerHTML = html.toString(); |
---|
| 139 | document.getElementById("table_richtext_toolbar").style.visibility="visible"; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | cRichTextEditor.prototype.buildEditor = function() { |
---|
| 145 | this.table = document.createElement("TABLE"); |
---|
| 146 | this.table.id = "table_richtext_toolbar"; |
---|
| 147 | this.table.className = "richtext_toolbar"; |
---|
| 148 | this.table.width = "100%"; |
---|
| 149 | var tbody = document.createElement("TBODY"); |
---|
| 150 | var tr = document.createElement("TR"); |
---|
| 151 | var td = document.createElement("TD"); |
---|
| 152 | var div_button_rt = document.createElement("DIV"); |
---|
| 153 | |
---|
| 154 | selectBox=document.createElement("SELECT"); |
---|
| 155 | selectBox.id="fontname"; |
---|
| 156 | selectBox.setAttribute("tabIndex","-1"); |
---|
| 157 | selectBox.onchange = function () {RichTextEditor.Select("fontname");}; |
---|
| 158 | selectBox.className = 'select_richtext'; |
---|
| 159 | var option1 = new Option(get_lang('Font'), 'Font'); |
---|
| 160 | var option2 = new Option('Arial', 'Arial'); |
---|
| 161 | var option3 = new Option('Courier', 'Courier'); |
---|
| 162 | var option4 = new Option('Times New Roman', 'Times'); |
---|
| 163 | if (is_ie){ |
---|
| 164 | selectBox.add(option1); |
---|
| 165 | selectBox.add(option2); |
---|
| 166 | selectBox.add(option3); |
---|
| 167 | selectBox.add(option4); |
---|
| 168 | } |
---|
| 169 | else{ |
---|
| 170 | selectBox.add(option1, null); |
---|
| 171 | selectBox.add(option2, null); |
---|
| 172 | selectBox.add(option3, null); |
---|
| 173 | selectBox.add(option4, null); |
---|
| 174 | } |
---|
| 175 | div_button_rt.appendChild(selectBox); |
---|
| 176 | |
---|
| 177 | selectBox=document.createElement("SELECT"); |
---|
| 178 | selectBox.id="fontsize"; |
---|
| 179 | selectBox.setAttribute("tabIndex","-1"); |
---|
| 180 | selectBox.setAttribute("unselectable","on"); |
---|
| 181 | selectBox.className = 'select_richtext'; |
---|
| 182 | selectBox.onchange = function () {RichTextEditor.Select("fontsize");}; |
---|
| 183 | var option1 = new Option(get_lang('Size'), 'Size'); |
---|
| 184 | var option2 = new Option('1 (8 pt)','1' ); |
---|
| 185 | var option3 = new Option('2 (10 pt)','2'); |
---|
| 186 | var option4 = new Option('3 (12 pt)','3'); |
---|
| 187 | var option5 = new Option('4 (14 pt)','4'); |
---|
| 188 | var option6 = new Option('5 (18 pt)','5'); |
---|
| 189 | var option7 = new Option('6 (24 pt)','6'); |
---|
| 190 | var option8 = new Option('7 (36 pt)','7'); |
---|
| 191 | if (is_ie){ |
---|
| 192 | selectBox.add(option1); |
---|
| 193 | selectBox.add(option2); |
---|
| 194 | selectBox.add(option3); |
---|
| 195 | selectBox.add(option4); |
---|
| 196 | selectBox.add(option5); |
---|
| 197 | selectBox.add(option6); |
---|
| 198 | selectBox.add(option7); |
---|
| 199 | selectBox.add(option8); |
---|
| 200 | } |
---|
| 201 | else{ |
---|
| 202 | selectBox.add(option1, null); |
---|
| 203 | selectBox.add(option2, null); |
---|
| 204 | selectBox.add(option3, null); |
---|
| 205 | selectBox.add(option4, null); |
---|
| 206 | selectBox.add(option5, null); |
---|
| 207 | selectBox.add(option6, null); |
---|
| 208 | selectBox.add(option7, null); |
---|
| 209 | selectBox.add(option8, null); |
---|
| 210 | } |
---|
| 211 | div_button_rt.appendChild(selectBox); |
---|
| 212 | |
---|
| 213 | var buttons = ['bold', 'italic', 'underline', 'forecolor', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', |
---|
[351] | 214 | 'undo', 'redo', 'insertorderedlist', 'insertunorderedlist', 'outdent', 'indent', 'link', 'image', 'table', 'signature']; |
---|
[2] | 215 | |
---|
| 216 | for (var i=0; i<buttons.length; i++){ |
---|
| 217 | var img = document.createElement("IMG"); |
---|
| 218 | img.id = buttons[i]; |
---|
| 219 | img.className = 'imagebutton'; |
---|
| 220 | img.align = 'center'; |
---|
[790] | 221 | img.src = './templates/'+template+'/images/'+buttons[i]+'.gif'; |
---|
[2] | 222 | img.title = get_lang(buttons[i]); |
---|
| 223 | img.style.cursor = 'pointer'; |
---|
| 224 | |
---|
| 225 | if (buttons[i] == 'forecolor') |
---|
| 226 | img.onclick = function () {RichTextEditor.show_pc('forecolor')}; |
---|
| 227 | else if (buttons[i] == 'link') |
---|
| 228 | img.onclick = function () {RichTextEditor.createLink();}; |
---|
[271] | 229 | else if (buttons[i] == 'image') |
---|
| 230 | img.onclick = function () {RichTextEditor.createImage();}; |
---|
| 231 | else if (buttons[i] == 'table') |
---|
| 232 | img.onclick = function () {RichTextEditor.createTable();}; |
---|
[2] | 233 | else |
---|
| 234 | img.onclick = function () {RichTextEditor.editorCommand(this.id,'');}; |
---|
| 235 | |
---|
| 236 | img.onmouseover = function () {this.style.border="outset 2px";}; |
---|
| 237 | img.onmouseout = function () {this.style.border="solid 2px #C0C0C0";}; |
---|
| 238 | div_button_rt.appendChild(img); |
---|
| 239 | } |
---|
[3400] | 240 | if(preferences.use_SpellChecker != '0'){ |
---|
| 241 | selectBox=document.createElement("SELECT"); |
---|
| 242 | selectBox.id="selectLanguage"; |
---|
| 243 | selectBox.setAttribute("tabIndex","-1"); |
---|
| 244 | selectBox.setAttribute("unselectable","on"); |
---|
| 245 | selectBox.className = 'select_richtext'; |
---|
| 246 | selectBox.onchange = function () {RichTextEditor.Select("selectLanguage");}; |
---|
| 247 | var option1 = new Option(get_lang("Portuguese"),"pt_BR" ); |
---|
| 248 | option1.selected = true; |
---|
| 249 | var option2 = new Option(get_lang("English"),'en'); |
---|
| 250 | var option3 = new Option(get_lang("Spanish"),'es'); |
---|
| 251 | if (is_ie){ |
---|
| 252 | selectBox.add(option1); |
---|
| 253 | selectBox.add(option2); |
---|
| 254 | selectBox.add(option3); |
---|
| 255 | } |
---|
| 256 | else{ |
---|
| 257 | selectBox.add(option1, null); |
---|
| 258 | selectBox.add(option2, null); |
---|
| 259 | selectBox.add(option3, null); |
---|
| 260 | } |
---|
| 261 | div_button_rt.appendChild(selectBox); |
---|
[2] | 262 | |
---|
[3400] | 263 | // spellCheck button |
---|
| 264 | var img = document.createElement("IMG"); |
---|
| 265 | img.id = "spellCheck"; |
---|
| 266 | img.className = 'imagebutton'; |
---|
| 267 | img.align = 'center'; |
---|
| 268 | img.src = './templates/'+template+'/images/'+img.id+'.gif'; |
---|
| 269 | img.title = get_lang(img.id); |
---|
| 270 | img.style.cursor = 'pointer'; |
---|
| 271 | img.onclick = function () {RichTextEditor.editorCommand(this.id,'');}; |
---|
| 272 | img.onmouseover = function () {this.style.border="outset 2px";}; |
---|
| 273 | img.onmouseout = function () {this.style.border="solid 2px #C0C0C0";}; |
---|
| 274 | div_button_rt.appendChild(img); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | |
---|
[2] | 278 | td.appendChild(div_button_rt); |
---|
| 279 | tr.appendChild(td); |
---|
| 280 | tbody.appendChild(tr); |
---|
| 281 | this.table.appendChild(tbody); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | cRichTextEditor.prototype.editorCommand = function(command, option) { |
---|
| 285 | try { |
---|
[271] | 286 | var mainField = document.getElementById(this.editor).contentWindow; |
---|
[2] | 287 | mainField.focus(); |
---|
[389] | 288 | var signature = preferences.type_signature == 'html' ? preferences.signature : preferences.signature.replace(/\n/g, "<br>"); |
---|
[2] | 289 | if (command == 'signature'){ |
---|
| 290 | if (is_ie){ |
---|
| 291 | var sel = document.selection; |
---|
| 292 | if (sel!=null) |
---|
| 293 | { |
---|
| 294 | var rng = sel.createRange(); |
---|
| 295 | if (rng!=null) |
---|
[389] | 296 | rng.pasteHTML(signature); |
---|
[2] | 297 | } |
---|
| 298 | } |
---|
| 299 | else{ |
---|
[389] | 300 | mainField.document.execCommand('inserthtml', false, signature); |
---|
[2] | 301 | } |
---|
| 302 | } |
---|
[271] | 303 | else if (command == 'CreateLink') |
---|
| 304 | mainField.document.execCommand('CreateLink', false, option); |
---|
| 305 | else if (command == 'Table'){ |
---|
| 306 | if (is_ie){ |
---|
| 307 | var sel = document.selection; |
---|
| 308 | if (sel!=null) |
---|
| 309 | { |
---|
| 310 | var rng = sel.createRange(); |
---|
| 311 | if (rng!=null) |
---|
| 312 | rng.pasteHTML(option); |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | else |
---|
| 316 | mainField.document.execCommand('inserthtml', false, option); |
---|
| 317 | } |
---|
[279] | 318 | else if (command == 'Image') |
---|
[271] | 319 | mainField.document.execCommand('InsertImage', false, option); |
---|
[3400] | 320 | else if (command == 'spellCheck' && preferences.use_SpellChecker != '0'){ |
---|
| 321 | beginSpellCheck(); // configure |
---|
| 322 | spellCheck(); // run spellChecker |
---|
| 323 | } |
---|
[279] | 324 | else |
---|
| 325 | mainField.document.execCommand(command, false, option); |
---|
[2] | 326 | //mainField.focus(); |
---|
[320] | 327 | } catch (e) {/* alert(e);*/ } |
---|
[2] | 328 | } |
---|
| 329 | |
---|
| 330 | cRichTextEditor.prototype.createLink = function(){ |
---|
| 331 | var mainField = document.getElementById(this.editor).contentWindow; |
---|
| 332 | if (is_ie){ |
---|
| 333 | if ((mainField.document.selection.createRange().text) == ''){ |
---|
[53] | 334 | alert(get_lang('Chose the text you want transform in link before.')); |
---|
[2] | 335 | return; |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | else{ |
---|
| 339 | if (mainField.window.getSelection() == ''){ |
---|
[53] | 340 | alert(get_lang('Chose the text you want transform in link before.')); |
---|
[2] | 341 | return; |
---|
| 342 | } |
---|
| 343 | } |
---|
[163] | 344 | var szURL = prompt(get_lang('Enter with link URL:'), 'http://'); |
---|
[2] | 345 | if ((szURL != null) && (szURL != "")){ |
---|
| 346 | this.editorCommand("CreateLink", szURL); |
---|
| 347 | } |
---|
| 348 | } |
---|
| 349 | |
---|
[271] | 350 | // It include the image file in emails body |
---|
| 351 | // It saves and attach in drafts folder and open it |
---|
| 352 | cRichTextEditor.prototype.addInputFile = function() |
---|
| 353 | { |
---|
[320] | 354 | //Begin: Verify if the image extension is allowed. |
---|
| 355 | var imgExtensions = new Array("jpeg", "jpg", "gif", "png", "bmp", "xbm", "tiff", "pcx"); |
---|
| 356 | var inputFile = document.getElementById('inputFile_img'); |
---|
| 357 | if(!inputFile.value) return false; |
---|
| 358 | var fileExtension = inputFile.value.split("."); |
---|
| 359 | fileExtension = fileExtension[(fileExtension.length-1)]; |
---|
| 360 | var deniedExtension = true; |
---|
| 361 | for(var i=0; i<imgExtensions.length; i++) { |
---|
| 362 | if(imgExtensions[i].toUpperCase() == fileExtension.toUpperCase()) { |
---|
| 363 | deniedExtension = false; |
---|
| 364 | break; |
---|
| 365 | } |
---|
| 366 | } |
---|
| 367 | if(deniedExtension) { |
---|
| 368 | alert(get_lang('File extension forbidden or invalid file') + '.'); |
---|
| 369 | return false; |
---|
| 370 | } |
---|
| 371 | // End: Verify image extension. |
---|
[271] | 372 | var id = this.editor.substr(5); // border_id |
---|
| 373 | divFiles = document.getElementById("divFiles_"+id); |
---|
| 374 | var countDivFiles = divFiles.childNodes.length + 1; |
---|
| 375 | |
---|
| 376 | var divFiles = document.getElementById('divFiles_'+id); |
---|
| 377 | inputFile.id = 'inputFile_'+id +"_"+countDivFiles; |
---|
| 378 | inputFile.name = 'file_'+countDivFiles; |
---|
| 379 | divFile = document.createElement('DIV'); |
---|
| 380 | divFile.appendChild(inputFile); |
---|
| 381 | divFiles.appendChild(divFile); |
---|
| 382 | |
---|
| 383 | var form_upload = document.getElementById('form_upload'); |
---|
| 384 | form_upload.parentNode.removeChild(form_upload); |
---|
| 385 | win.close(); |
---|
| 386 | |
---|
| 387 | RichTextEditor.saveFlag = 0; // See if save function finished |
---|
[607] | 388 | var save_link = document.getElementById("save_message_options_"+id); |
---|
[320] | 389 | //save_link.onclick = function () {}; |
---|
[1005] | 390 | save_msg(id,true); |
---|
[271] | 391 | setTimeout("RichTextEditor.insertImgHtml("+id+")",1000); |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | cRichTextEditor.prototype.insertImgHtml = function (id){ |
---|
| 395 | if (RichTextEditor.saveFlag == 0) |
---|
| 396 | setTimeout("RichTextEditor.insertImgHtml("+id+")",500); |
---|
| 397 | else |
---|
[320] | 398 | if (RichTextEditor.saveFlag == 1) |
---|
[3865] | 399 | { |
---|
[607] | 400 | this.editorCommand('Image', './inc/show_embedded_attach.php?msg_folder=INBOX/'+draftsfolder+'&msg_num='+openTab.imapUid[id]+'&msg_part='+(openTab.countFile[id]+1)); |
---|
[271] | 401 | // this.editorCommand('Image', '.inc/gotodownload.php?msg_folder="+msg_folder+"&msg_number="+msg_number+"&idx_file="+idx_file+"&msg_part="+msg_part+params')); |
---|
[3865] | 402 | openTab.toPreserve[id] = true; |
---|
| 403 | save_msg(id,true); |
---|
| 404 | } |
---|
[271] | 405 | } |
---|
| 406 | |
---|
| 407 | cRichTextEditor.prototype.insertTableHtml = function (){ |
---|
| 408 | var id = this.editor.substr(5); // border_id |
---|
[329] | 409 | var rows = document.getElementById('rows').value; |
---|
| 410 | var cols = document.getElementById('cols').value; |
---|
| 411 | var border = document.getElementById('border').value; |
---|
| 412 | var insertTable = '<table border="'+border+'px"><tbody>'; |
---|
| 413 | for (var i = 0; i < rows; i++){ |
---|
[271] | 414 | insertTable += "<tr>"; |
---|
[329] | 415 | for (var j = 0; j < cols; j++) |
---|
[271] | 416 | insertTable += "<td> </td>"; |
---|
| 417 | insertTable += "</tr>"; |
---|
| 418 | } |
---|
| 419 | insertTable += "</tbody></table>"; |
---|
| 420 | this.editorCommand('Table', insertTable); |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | cRichTextEditor.prototype.createTable = function(){ |
---|
| 424 | var form = document.getElementById("table_window"); |
---|
| 425 | if (form == null){ |
---|
| 426 | form = document.createElement("DIV"); |
---|
| 427 | form.id = "table_window"; |
---|
| 428 | form.style.visibility = "hidden"; |
---|
| 429 | form.style.position = "absolute"; |
---|
| 430 | form.style.background = "#eeeeee"; |
---|
| 431 | form.style.left = "0px"; |
---|
| 432 | form.style.top = "0px"; |
---|
| 433 | form.style.width = "0px"; |
---|
| 434 | form.style.height = "0px"; |
---|
| 435 | document.body.appendChild(form); |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | var form_table = document.createElement("DIV"); |
---|
| 439 | form_table.id = "form_table"; |
---|
| 440 | form_table.style.position = "absolute"; |
---|
| 441 | form_table.style.top = "5px"; |
---|
| 442 | form_table.style.left = "5px"; |
---|
[329] | 443 | form_table.style.width = "190px"; |
---|
| 444 | form_table.style.height = "90px"; |
---|
| 445 | form_table.name = get_lang("Insert Table"); |
---|
| 446 | form_table.innerHTML = get_lang('Select the table size')+':<br><br><table cellspacing="0"><tbody><tr><td align="center">'+ |
---|
| 447 | get_lang('Rows')+':</td><td></td><td align="center">'+get_lang('Cols')+':</td><td></td><td align="center">'+get_lang('Border')+':</td></tr>'+ |
---|
[790] | 448 | '<tr><td align="right"><input type="text" readonly="true" id="rows" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'rows\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'rows\');"></img></td>'+ |
---|
| 449 | '<td align="right"><input type="text" readonly="true" id="cols" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'cols\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'cols\');"></img></td>'+ |
---|
| 450 | '<td align="right"><input type="text" readonly="true" id="border" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'border\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'border\');"></img></td>'+ |
---|
[329] | 451 | '</tr></tbody></table>'+ |
---|
[690] | 452 | ' <input title="'+get_lang('Close')+'" value="' + get_lang('Close') + '" type="button" onclick="win.close()"> '+ |
---|
| 453 | '<input title="' + get_lang('Include') + '" value="' + get_lang('Include') + '" type="button" onclick="RichTextEditor.insertTableHtml();win.close();">'; |
---|
[271] | 454 | form.appendChild(form_table); |
---|
| 455 | |
---|
| 456 | this.showWindow(form); |
---|
| 457 | } |
---|
| 458 | |
---|
[329] | 459 | cRichTextEditor.prototype.incrementField = function(id_val){ |
---|
| 460 | var field_text = document.getElementById(id_val); |
---|
| 461 | field_text.value = parseInt(field_text.value)+1; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | cRichTextEditor.prototype.decrementField = function(id_val){ |
---|
| 465 | var field_text = document.getElementById(id_val); |
---|
| 466 | if (parseInt(field_text.value) > 0) |
---|
| 467 | field_text.value = parseInt(field_text.value)-1; |
---|
| 468 | } |
---|
| 469 | |
---|
[271] | 470 | cRichTextEditor.prototype.createImage = function(){ |
---|
[646] | 471 | if (preferences.auto_save_draft == 1){ |
---|
| 472 | autosave_time = 200000; |
---|
| 473 | clearTimeout(openTab.autosave_timer[currentTab]); |
---|
| 474 | } |
---|
[271] | 475 | var form = document.getElementById("attachment_window"); |
---|
| 476 | if (form == null){ |
---|
| 477 | form = document.createElement("DIV"); |
---|
| 478 | form.id = "attachment_window"; |
---|
| 479 | form.style.visibility = "hidden"; |
---|
| 480 | form.style.position = "absolute"; |
---|
| 481 | form.style.background = "#eeeeee"; |
---|
| 482 | form.style.left = "0px"; |
---|
| 483 | form.style.top = "0px"; |
---|
| 484 | form.style.width = "0px"; |
---|
| 485 | form.style.height = "0px"; |
---|
| 486 | document.body.appendChild(form); |
---|
| 487 | } |
---|
[1296] | 488 | var form_upload = Element('form_upload'); |
---|
| 489 | if (form_upload == null) |
---|
| 490 | form_upload = document.createElement("DIV"); |
---|
[271] | 491 | form_upload.id = "form_upload"; |
---|
| 492 | form_upload.style.position = "absolute"; |
---|
| 493 | form_upload.style.top = "5px"; |
---|
| 494 | form_upload.style.left = "5px"; |
---|
| 495 | form_upload.name = get_lang("Upload File"); |
---|
| 496 | form_upload.style.width = "450px"; |
---|
| 497 | form_upload.style.height = "75px"; |
---|
| 498 | form_upload.innerHTML = get_lang('Select the desired image file')+':<br>'+ |
---|
| 499 | '<input name="image_at" maxlength="255" size="50" id="inputFile_img" type="file"><br>' + |
---|
[690] | 500 | '<input title="' + get_lang('Include') + '" value="' + get_lang('Include') + '"' + 'type="button" onclick="RichTextEditor.addInputFile();"> ' + |
---|
| 501 | '<input title="' + get_lang('Close') + '" value="' + get_lang('Close') + '"' + |
---|
[271] | 502 | ' type="button" onclick="win.close()">'; |
---|
| 503 | form.appendChild(form_upload); |
---|
| 504 | |
---|
| 505 | this.showWindow(form); |
---|
| 506 | } |
---|
| 507 | cRichTextEditor.prototype.showWindow = function (div){ |
---|
| 508 | |
---|
| 509 | if(! div) { |
---|
| 510 | return; |
---|
| 511 | } |
---|
| 512 | |
---|
| 513 | if(! this.emwindow[div.id]) { |
---|
| 514 | div.style.width = div.firstChild.style.width; |
---|
| 515 | div.style.height = div.firstChild.style.height; |
---|
| 516 | div.style.zIndex = "10000"; |
---|
| 517 | var title = div.firstChild.name; |
---|
| 518 | var wHeight = div.offsetHeight + "px"; |
---|
| 519 | var wWidth = div.offsetWidth + "px"; |
---|
| 520 | div.style.width = div.offsetWidth - 5; |
---|
| 521 | |
---|
| 522 | win = new dJSWin({ |
---|
| 523 | id: 'win_'+div.id, |
---|
| 524 | content_id: div.id, |
---|
| 525 | width: wWidth, |
---|
| 526 | height: wHeight, |
---|
| 527 | title_color: '#3978d6', |
---|
| 528 | bg_color: '#eee', |
---|
| 529 | title: title, |
---|
| 530 | title_text_color: 'white', |
---|
| 531 | button_x_img: '../phpgwapi/images/winclose.gif', |
---|
| 532 | border: true }); |
---|
| 533 | |
---|
| 534 | this.emwindow[div.id] = win; |
---|
| 535 | win.draw(); |
---|
| 536 | } |
---|
| 537 | else |
---|
| 538 | win = this.emwindow[div.id]; |
---|
| 539 | win.open(); |
---|
| 540 | } |
---|
| 541 | |
---|
[2] | 542 | cRichTextEditor.prototype.Select = function(selectname) |
---|
| 543 | { |
---|
| 544 | var mainField = Element(this.editor).contentWindow; |
---|
| 545 | var cursel = document.getElementById(selectname).selectedIndex; |
---|
| 546 | |
---|
| 547 | if (cursel != 0) { |
---|
| 548 | var selected = document.getElementById(selectname).options[cursel].value; |
---|
| 549 | mainField.document.execCommand(selectname, false, selected); |
---|
[3544] | 550 | document.getElementById(selectname).selectedIndex = "Size"; //cursel; |
---|
[2] | 551 | } |
---|
| 552 | mainField.focus(); |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | cRichTextEditor.prototype.show_pc = function(command) |
---|
| 556 | { |
---|
| 557 | connector.loadScript("color_palette"); |
---|
| 558 | ColorPalette.loadPalette(this.id); |
---|
| 559 | if (ColorPalette.div.style.visibility != "visible") |
---|
| 560 | ColorPalette.div.style.visibility="visible"; |
---|
| 561 | else |
---|
| 562 | this.hide_pc(); |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | cRichTextEditor.prototype.hide_pc = function() |
---|
| 566 | { |
---|
| 567 | document.getElementById("palettecolor").style.visibility="hidden"; |
---|
| 568 | } |
---|
| 569 | |
---|
| 570 | cRichTextEditor.prototype.getOffsetTop = function(elm) { |
---|
| 571 | var mOffsetTop = elm.offsetTop;1 |
---|
| 572 | var mOffsetParent = elm.offsetParent; |
---|
| 573 | while(mOffsetParent){ |
---|
| 574 | mOffsetTop += mOffsetParent.offsetTop; |
---|
| 575 | mOffsetParent = mOffsetParent.offsetParent; |
---|
| 576 | } |
---|
| 577 | return mOffsetTop; |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | cRichTextEditor.prototype.getOffsetLeft = function(elm) { |
---|
| 581 | var mOffsetLeft = elm.offsetLeft; |
---|
| 582 | var mOffsetParent = elm.offsetParent; |
---|
| 583 | while(mOffsetParent){ |
---|
| 584 | mOffsetLeft += mOffsetParent.offsetLeft; |
---|
| 585 | mOffsetParent = mOffsetParent.offsetParent; |
---|
| 586 | } |
---|
| 587 | return mOffsetLeft; |
---|
| 588 | } |
---|
| 589 | |
---|
| 590 | //Build the Object |
---|
[320] | 591 | RichTextEditor = new cRichTextEditor(); |
---|