source: branches/2.2.0.1/expressoMail1_2/js/rich_text_editor.js @ 4450

Revision 4450, 23.5 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1726 - Corrigido o envio de mensagem com imagem no corpo do e-mail. r4379

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