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