source: branches/2.2/expressoMail1_2/js/rich_text_editor.js @ 4233

Revision 4233, 23.3 KB checked in by rodsouza, 13 years ago (diff)

Ticket #1824 - Traduz frases do envio de e-mail em texto puro.

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