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