source: trunk/expressoMail1_2/js/rich_text_editor.js @ 4828

Revision 4828, 27.3 KB checked in by airton, 13 years ago (diff)

Ticket #2146 - Implementacao da funcionalidade de multiplas assinaturas

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