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

Revision 4309, 24.4 KB checked in by airton, 13 years ago (diff)

Ticket #1820 - Corrigindo bloqueio ao redigir emails apos mudar de aba - r4296

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