source: sandbox/2.3-MailArchiver/expressoMail1_2/js/rich_text_editor.js @ 6779

Revision 6779, 24.4 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

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            if (szURL.indexOf('://') == -1) szURL = 'http://' + szURL;
437                this.editorCommand("CreateLink", szURL);
438        }
439}
440
441// It include the image file in emails body
442// It saves and attach in drafts folder and open it
443cRichTextEditor.prototype.addInputFile = function()
444{
445        //Begin: Verify if the image extension is allowed.
446        var imgExtensions = new Array("jpeg", "jpg", "gif", "png", "bmp", "xbm", "tiff", "pcx");
447        var inputFile = document.getElementById('inputFile_img');       
448        if(!inputFile.value) return false;
449        var fileExtension = inputFile.value.split(".");
450        fileExtension = fileExtension[(fileExtension.length-1)];
451        var deniedExtension = true;
452        for(var i=0; i<imgExtensions.length; i++) {
453                if(imgExtensions[i].toUpperCase() == fileExtension.toUpperCase()) {
454                        deniedExtension = false;
455                        break;
456                }
457        }
458        if(deniedExtension) {
459                alert(get_lang('File extension forbidden or invalid file') + '.');
460                return false;
461        }
462        // End: Verify image extension.
463        var id = this.editor.substr(5); // border_id
464        divFiles = document.getElementById("divFiles_"+id);
465        var countDivFiles = divFiles.childNodes.length + 1;
466
467        var divFiles = document.getElementById('divFiles_'+id);
468        inputFile.id = 'inputFile_'+id +"_"+countDivFiles;
469        inputFile.name = 'file_'+countDivFiles;
470        divFile = document.createElement('DIV');
471        divFile.appendChild(inputFile);
472        divFiles.appendChild(divFile);
473
474        var form_upload = document.getElementById('form_upload');
475        form_upload.parentNode.removeChild(form_upload);
476        win.close();
477
478        RichTextEditor.saveFlag = 0; // See if save function finished
479        var save_link = document.getElementById("save_message_options_"+id);
480        save_msg(id,true);
481        RichTextEditor.insertImgHtml(id);
482}
483
484cRichTextEditor.prototype.insertImgHtml = function (id)
485{
486        if ( RichTextEditor.saveFlag == 0 )
487        {
488            setTimeout( function(){ RichTextEditor.insertImgHtml(id); },1000 );
489        }
490        else
491        {
492            if ( RichTextEditor.saveFlag == 1 )
493            {
494                var folderNameDraft = "INBOX" + cyrus_delimiter + draftsfolder;
495                this.editorCommand('Image', './inc/show_embedded_attach.php?msg_folder=' + folderNameDraft + '&msg_num='+openTab.imapUid[id]+'&msg_part='+(openTab.countFile[id]+1));
496                        openTab.toPreserve[id] = true;
497                        save_msg(id,true);
498            }
499        }
500}
501
502cRichTextEditor.prototype.insertTableHtml = function (){
503        var id = this.editor.substr(5); // border_id
504        var     rows = document.getElementById('rows').value;
505        var     cols = document.getElementById('cols').value;
506        var border = document.getElementById('border').value;
507        var insertTable = '<table border="'+border+'px"><tbody>';
508        for (var i = 0; i < rows; i++){
509                insertTable += "<tr>"; 
510                for (var j = 0; j < cols; j++)
511                        insertTable += "<td>&nbsp;</td>";       
512                insertTable += "</tr>";
513        }
514        insertTable += "</tbody></table>";
515        this.editorCommand('Table', insertTable);
516}
517
518cRichTextEditor.prototype.createTable = function(){
519        var form = document.getElementById("table_window");
520        if (form == null){
521                form = document.createElement("DIV");
522                form.id  = "table_window";
523                form.style.visibility = "hidden";
524                form.style.position = "absolute";
525                form.style.background = "#eeeeee";
526                form.style.left = "0px";
527                form.style.top  = "0px";
528                form.style.width = "0px";
529                form.style.height = "0px";
530                document.body.appendChild(form);
531        }
532               
533                var form_table = document.createElement("DIV");
534                form_table.id = "form_table";
535                form_table.style.position = "absolute";
536                form_table.style.top = "5px";
537                form_table.style.left = "5px";
538                form_table.style.width = "190px";
539                form_table.style.height = "90px";
540                form_table.name = get_lang("Insert Table");             
541                form_table.innerHTML = get_lang('Select the table size')+':<br><br><table cellspacing="0"><tbody><tr><td align="center">'+
542                                                                get_lang('Rows')+':</td><td></td><td align="center">'+get_lang('Cols')+':</td><td></td><td align="center">'+get_lang('Border')+':</td></tr>'+
543                                                                        '<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>'+
544                                                                        '<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>'+
545                                                                        '<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>'+
546                                                                        '</tr></tbody></table>'+
547                                                                        '&nbsp;&nbsp;&nbsp;<input title="'+get_lang('Close')+'"  value="' + get_lang('Close') + '" type="button" onclick="win.close()">&nbsp;'+
548                                                                        '<input title="' + get_lang('Include') + '"  value="' + get_lang('Include') + '" type="button" onclick="RichTextEditor.insertTableHtml();win.close();">';       
549                form.appendChild(form_table);
550               
551                this.showWindow(form);
552                }
553
554cRichTextEditor.prototype.incrementField = function(id_val){
555        var field_text = document.getElementById(id_val);
556        field_text.value = parseInt(field_text.value)+1;
557}
558
559cRichTextEditor.prototype.decrementField = function(id_val){
560        var field_text = document.getElementById(id_val);
561        if (parseInt(field_text.value) > 0)
562                field_text.value = parseInt(field_text.value)-1;
563}
564
565cRichTextEditor.prototype.createImage = function(){
566        if (preferences.auto_save_draft == 1){
567                        autosave_time = 200000;
568                        clearTimeout(openTab.autosave_timer[currentTab]);
569                }
570        var form = document.getElementById("attachment_window");
571        if (form == null){
572                form = document.createElement("DIV");
573                form.id  = "attachment_window";
574                form.style.visibility = "hidden";
575                form.style.position = "absolute";
576                form.style.background = "#eeeeee";
577                form.style.left = "0px";
578                form.style.top  = "0px";
579                form.style.width = "0px";
580                form.style.height = "0px";
581                document.body.appendChild(form);
582        }
583                var form_upload = Element('form_upload');
584                if (form_upload == null)
585                        form_upload = document.createElement("DIV");
586                form_upload.id = "form_upload";
587                form_upload.style.position = "absolute";
588                form_upload.style.top = "5px";
589                form_upload.style.left = "5px";
590                form_upload.name = get_lang("Upload File");
591                form_upload.style.width = "550px";
592                form_upload.style.height = "100px";
593                form_upload.innerHTML = get_lang('Select the desired image file')+':<br>'+
594                                                                '<input name="image_at" maxlength="255" size="50" id="inputFile_img" type="file"><br/><br/>' +
595                                                                '<input title="' + get_lang('Include') + '"  value="' + get_lang('Include') + '"' + 'type="button" onclick="RichTextEditor.addInputFile();">&nbsp;' +
596                                                                '<input title="' + get_lang('Close') + '"  value="' + get_lang('Close') + '"' +
597                                                                ' type="button" onclick="win.close()">';
598                                                           
599                form.appendChild(form_upload);
600               
601                this.showWindow(form);
602}
603cRichTextEditor.prototype.showWindow = function (div){
604
605                if(! div) {
606                        return;
607                }
608               
609                if(! this.emwindow[div.id]) {
610                        div.style.width  =  div.firstChild.style.width;
611                        div.style.height = div.firstChild.style.height;
612                        div.style.zIndex = "10000";                     
613                        var title = div.firstChild.name;
614                        var wHeight = div.offsetHeight + "px";
615                        var wWidth =  div.offsetWidth   + "px";
616                        div.style.width = div.offsetWidth - 5;
617
618                        win = new dJSWin({
619                                id: 'win_'+div.id,
620                                content_id: div.id,
621                                width: wWidth,
622                                height: wHeight,
623                                title_color: '#3978d6',
624                                bg_color: '#eee',
625                                title: title,
626                                title_text_color: 'white',
627                                button_x_img: '../phpgwapi/images/winclose.gif',
628                                border: true });
629                       
630                        this.emwindow[div.id] = win;
631                        win.draw();
632                }
633                else
634                        win = this.emwindow[div.id];
635                win.open();     
636}
637
638cRichTextEditor.prototype.Select = function(selectname)
639{
640        var mainField = Element(this.editor).contentWindow;
641        var cursel = document.getElementById(selectname).selectedIndex;
642
643        if (cursel != 0) {
644                var selected = document.getElementById(selectname).options[cursel].value;
645                mainField.document.execCommand(selectname, false, selected);
646                document.getElementById(selectname).selectedIndex = "Size"; //cursel;
647        }
648        mainField.focus();
649}
650
651cRichTextEditor.prototype.show_pc = function(command)
652{
653        connector.loadScript("color_palette");
654        ColorPalette.loadPalette(this.id);
655        if (ColorPalette.div.style.visibility != "visible")
656                ColorPalette.div.style.visibility="visible";
657        else
658                this.hide_pc();
659}
660
661cRichTextEditor.prototype.hide_pc = function()
662{
663        document.getElementById("palettecolor").style.visibility="hidden";
664}
665
666cRichTextEditor.prototype.getOffsetTop = function(elm) {
667  var mOffsetTop = elm.offsetTop;1
668  var mOffsetParent = elm.offsetParent;
669  while(mOffsetParent){
670    mOffsetTop += mOffsetParent.offsetTop;
671    mOffsetParent = mOffsetParent.offsetParent;
672  }
673  return mOffsetTop;
674}
675
676cRichTextEditor.prototype.getOffsetLeft = function(elm) {
677  var mOffsetLeft = elm.offsetLeft;
678  var mOffsetParent = elm.offsetParent;
679  while(mOffsetParent){
680    mOffsetLeft += mOffsetParent.offsetLeft;
681    mOffsetParent = mOffsetParent.offsetParent;
682  }
683  return mOffsetLeft;
684}
685
686cRichTextEditor.prototype.saveSelection = function() {
687        //save last selection for IE
688        try {
689                RichTextEditor.selRng = Element(this.editor).contentWindow.document.selection.createRange();
690                RichTextEditor.selBmk = RichTextEditor.selRng.getBookmark();
691        }
692        catch (e) {
693                RichTextEditor.selRng = null;
694                RichTextEditor.selBmk = null;
695        }
696}
697
698cRichTextEditor.prototype.restoreSelection = function() {
699        //restablish last selection for IE
700        if (RichTextEditor.selRng!=null)
701        {
702                try {
703                        RichTextEditor.selRng.moveToBookmark(RichTextEditor.selBmk);
704                        RichTextEditor.selRng.select();
705                }
706                catch (e) { }
707        }
708}
709
710//Build the Object
711RichTextEditor = new cRichTextEditor();
Note: See TracBrowser for help on using the repository browser.