source: branches/2.3/expressoMail1_2/js/rich_text_editor.js @ 5006

Revision 5006, 24.4 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #2221 - Falha ao inserir mais de uma imagem no corpo da mensagem

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