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