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

Revision 4302, 24.3 KB checked in by airton, 13 years ago (diff)

Ticket #1820 - Traduz frases do envio e email em texto puro - r4268

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