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

Revision 4258, 23.2 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1726 - Corrige local do opcao do envio de e-mail em texto puro. r4218

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