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

Revision 4285, 23.4 KB checked in by diogenesduarte, 13 years ago (diff)

Ticket #1853 - Corrigindo bloqueio ao redigir e-mails depois de mudar de aba

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