source: sandbox/2.2.0.2/expressoMail1_2/js/rich_text_editor.js @ 4291

Revision 4291, 23.9 KB checked in by airton, 13 years ago (diff)

Ticket #1820 - Permitindo o envio de email em texto puro - r4252

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