Ignore:
Timestamp:
09/09/11 15:26:36 (13 years ago)
Author:
airton
Message:

Ticket #2086 - Troca do atual editor de emails do expresso

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/js/rich_text_editor.js

    r4828 r5083  
    11function 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  
     2    this.emwindow   = new Array; 
     3    this.editor = "body_1"; 
     4    this.table = ""; 
     5    this.id = "1"; 
     6    this.saveFlag = 0; 
     7    this.signatures = false; 
     8    this.replyController = false;  
     9    this.newImageId = false; 
     10    this.plain = new Array; 
     11    this.editorReady = true; 
     12} 
     13 
     14// This code was written by Tyler Akins and has been placed in the 
     15// public domain.  It would be nice if you left this header intact. 
     16// Base64 code from Tyler Akins -- http://rumkin.com 
     17 
     18var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 
     19 
     20var ua = navigator.userAgent.toLowerCase(); 
     21if (ua.indexOf(" chrome/") >= 0 || ua.indexOf(" firefox/") >= 0 || ua.indexOf(' gecko/') >= 0) { 
     22    var StringMaker = function () { 
     23        this.str = ""; 
     24        this.length = 0; 
     25        this.append = function (s) { 
     26            this.str += s; 
     27            this.length += s.length; 
     28        } 
     29        this.prepend = function (s) { 
     30            this.str = s + this.str; 
     31            this.length += s.length; 
     32        } 
     33        this.toString = function () { 
     34            return this.str; 
     35        } 
     36    } 
     37} else { 
     38    var StringMaker = function () { 
     39        this.parts = []; 
     40        this.length = 0; 
     41        this.append = function (s) { 
     42            this.parts.push(s); 
     43            this.length += s.length; 
     44        } 
     45        this.prepend = function (s) { 
     46            this.parts.unshift(s); 
     47            this.length += s.length; 
     48        } 
     49        this.toString = function () { 
     50            return this.parts.join(''); 
     51        } 
     52    } 
     53} 
     54 
     55cRichTextEditor.prototype.fromJSON = function( value ) 
     56{ 
     57    return (new Function( "return " + this.decode64( value )))(); 
     58} 
     59 
     60cRichTextEditor.prototype.decode64 = function(input) {  
     61        if( typeof input === "undefined" ) return ''; 
     62 
     63        var output = new StringMaker(); 
     64        var chr1, chr2, chr3; 
     65        var enc1, enc2, enc3, enc4; 
     66        var i = 0; 
     67 
     68        // remove all characters that are not A-Z, a-z, 0-9, +, /, or = 
     69        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 
     70 
     71        while (i < input.length) { 
     72                enc1 = keyStr.indexOf(input.charAt(i++)); 
     73                enc2 = keyStr.indexOf(input.charAt(i++)); 
     74                enc3 = keyStr.indexOf(input.charAt(i++)); 
     75                enc4 = keyStr.indexOf(input.charAt(i++)); 
     76 
     77                chr1 = (enc1 << 2) | (enc2 >> 4); 
     78                chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 
     79                chr3 = ((enc3 & 3) << 6) | enc4; 
     80 
     81                output.append(String.fromCharCode(chr1)); 
     82 
     83                if (enc3 != 64) { 
     84                        output.append(String.fromCharCode(chr2)); 
     85                } 
     86                if (enc4 != 64) { 
     87                        output.append(String.fromCharCode(chr3)); 
     88                } 
     89        } 
     90 
     91        return output.toString(); 
     92} 
     93 
     94 
     95cRichTextEditor.prototype.loadEditor = function(ID) { 
     96         
     97        var parentDiv = document.getElementById("body_position_" + ID); 
     98        var pObj = "body_" + ID; 
     99        var textArea = document.createElement("TEXTAREA"); 
     100        textArea.id = pObj; 
     101        textArea.style.height = '500'; 
     102        textArea.style.width = '100%'; 
     103        parentDiv.appendChild(textArea); 
     104        RichTextEditor.plain[ID] = false;  
     105         
     106        if(preferences.plain_text_editor == 1) 
     107          RichTextEditor.plain[ID] = true;   
     108        else  
     109                  RichTextEditor.active(pObj); 
     110} 
     111 
     112cRichTextEditor.prototype.getSignaturesOptions = function() { 
     113         
     114        if(RichTextEditor.signatures !== false) 
     115            return RichTextEditor.signatures; 
     116                 
     117        var signatures = this.fromJSON( preferences.signatures ); 
     118        var signature_types = this.fromJSON( preferences.signature_types ); 
     119 
     120        for( key in signatures ) 
     121            if( !signature_types[key] ) 
     122                signatures[key] = signatures[key].replace( /\n/g, "<br>" ); 
     123                  
     124        RichTextEditor.signatures = signatures; 
     125        return signatures; 
     126 
     127} 
     128 
     129cRichTextEditor.prototype.getSignatureDefault = function() { 
     130          
     131        if(RichTextEditor.signatures === false) 
     132            RichTextEditor.signatures = RichTextEditor.getSignaturesOptions();  
     133          
     134        if(!RichTextEditor.signatures ||   
     135           !RichTextEditor.signatures[preferences.signature_default || ""]) 
     136        { 
     137          preferences.use_signature = "0"; //Desabilita o uso da assinatura 
     138          return ''; 
     139        }  
     140         
     141        return unescape(RichTextEditor.signatures[preferences.signature_default]); 
     142 
     143} 
     144 
     145cRichTextEditor.prototype.createImage = function(){ 
     146        if (preferences.auto_save_draft == 1) 
     147        { 
     148                        autosave_time = 200000; 
     149                        clearTimeout(openTab.autosave_timer[currentTab]); 
     150        } 
     151                 
     152        var form = document.getElementById("attachment_window"); 
     153         
     154        if (form == null){ 
     155                form = document.createElement("DIV"); 
     156                form.id  = "attachment_window"; 
     157                form.style.visibility = "hidden"; 
     158                form.style.position = "absolute"; 
     159                form.style.background = "#eeeeee"; 
     160                form.style.left = "0px"; 
     161                form.style.top  = "0px";  
     162                form.style.width = "0px"; 
     163                form.style.height = "0px"; 
     164                document.body.appendChild(form); 
     165        } 
     166                var form_upload = Element('form_upload'); 
     167                if (form_upload == null) 
     168                        form_upload = document.createElement("DIV"); 
     169                form_upload.id = "form_upload"; 
     170                form_upload.style.position = "absolute"; 
     171                form_upload.style.top = "5px"; 
     172                form_upload.style.left = "5px"; 
     173                form_upload.name = get_lang("Upload File"); 
     174                form_upload.style.width = "450px"; 
     175                form_upload.style.height = "75px"; 
     176                form_upload.innerHTML = get_lang('Select the desired image file')+':<br>'+ 
     177                '<input name="image_at" maxlength="255" size="40" id="inputFile_img" type="file"><br>' + 
     178                '<input title="' + get_lang('Include') + '"  value="' + get_lang('Include') + '"' +  
     179                'type="button" onclick="RichTextEditor.addInputFile();">&nbsp;' + 
     180                '<input title="' + get_lang('Close') + '"  value="' + get_lang('Close') + '"' + 
     181                ' type="button" onclick="win.close()">'; 
     182                form.appendChild(form_upload); 
    56183                 
    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  
    94 cRichTextEditor.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  
    126 cRichTextEditor.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  
    171 cRichTextEditor.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  
    210 cRichTextEditor.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  
    246 cRichTextEditor.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  
    306 cRichTextEditor.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  
    323 cRichTextEditor.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  
    430 cRichTextEditor.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  
    478 cRichTextEditor.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.'));  
     184                this.showWindow(form); 
     185} 
     186cRichTextEditor.prototype.showWindow = function (div){ 
     187 
     188                if(! div) { 
    483189                        return; 
    484190                } 
    485         } 
    486         else{ 
    487                 if (mainField.window.getSelection() == ''){ 
    488                                 alert(get_lang('Chose the text you want transform in link before.'));  
    489                         return; 
     191                 
     192                if(! this.emwindow[div.id]) { 
     193                        div.style.width  =  div.firstChild.style.width; 
     194                        div.style.height = div.firstChild.style.height; 
     195                        div.style.zIndex = "10000";                      
     196                        var title = div.firstChild.name; 
     197                        var wHeight = div.offsetHeight + "px"; 
     198                        var wWidth =  div.offsetWidth   + "px"; 
     199                        div.style.width = div.offsetWidth - 5; 
     200 
     201                        win = new dJSWin({ 
     202                                id: 'win_'+div.id, 
     203                                content_id: div.id, 
     204                                width: wWidth, 
     205                                height: wHeight, 
     206                                title_color: '#3978d6', 
     207                                bg_color: '#eee', 
     208                                title: title, 
     209                                title_text_color: 'white', 
     210                                button_x_img: '../phpgwapi/images/winclose.gif', 
     211                                border: true}); 
     212                         
     213                        this.emwindow[div.id] = win; 
     214                        win.draw(); 
    490215                } 
    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 
     216                else 
     217                        win = this.emwindow[div.id]; 
     218                win.open();      
     219} 
    500220cRichTextEditor.prototype.addInputFile = function() 
    501221{ 
     
    518238        } 
    519239        // End: Verify image extension. 
    520         var id = this.editor.substr(5); // border_id 
     240        var id =  currentTab; 
    521241        divFiles = document.getElementById("divFiles_"+id); 
    522242        var countDivFiles = divFiles.childNodes.length + 1; 
     
    535255        RichTextEditor.saveFlag = 0; // See if save function finished 
    536256        var save_link = document.getElementById("save_message_options_"+id); 
     257        save_link.onclick = function () {}; 
     258        this.newImageId = new Date().getTime(); 
     259        CKEDITOR.instances['body_'+id].insertHtml('<img id="'+this.newImageId+'" src=""/>'); 
    537260        save_msg(id,true); 
    538         RichTextEditor.insertImgHtml(id);  
     261} 
     262 
     263cRichTextEditor.prototype.execPosInstance = function(inst) { 
     264          
     265        var editor =  CKEDITOR.instances[inst];  
     266         
     267        
     268        var id = inst.replace('body_',''); 
     269         
     270        editor.document.on('keydown', function(event) 
     271        { 
     272            away = false; 
     273            var save_link = Element("save_message_options_"+id); 
     274            save_link.onclick = function onclick() {openTab.toPreserve[id] = true;save_msg(id);} ; 
     275            save_link.className = 'message_options'; 
     276        }); 
     277         
     278        //Adicionando atalhos de preferencias   
     279//TODO: Não esta pegando o numero (keycode) 
     280//        if (preferences.use_shortcuts == '1') 
     281//        { 
     282//            CKEDITOR.instances[inst].document.on('keyup', function(event){ 
     283//                    if(event.keyCode == 27){                          
     284//                            delete_border(id,'false');}  //Tecla delete fechar aba           
     285//            }); 
     286//        }   
     287        
     288        // IM Module Enabled 
     289        if( window.parent.loadscript && loadscript.autoStatusIM ) 
     290        { 
     291            CKEDITOR.instances[inst].document.on('keydown', function(event){ 
     292                   loadscript.autoStatusIM; 
     293            });                  
     294        } 
     295         
     296        if (preferences.auto_save_draft == 1) 
     297        { 
     298            openTab.autosave_timer[id] = false; 
     299            var save_link = document.getElementById("save_message_options"+id); 
     300            CKEDITOR.instances[inst].document.on('keydown', function(event){ 
     301               if (openTab.autosave_timer[id]) 
     302                    clearTimeout(openTab.autosave_timer[id]); 
     303               openTab.autosave_timer[id] = setTimeout("save_msg("+id+")", autosave_time); 
     304                         
     305            });   
     306        } 
     307        ///////////////////////////////////////////////////////////////////////////////////// 
     308         
     309    
     310        
     311       RichTextEditor.editorReady = true; 
     312} 
     313cRichTextEditor.prototype.setPlain = function (active,id){ 
     314      RichTextEditor.plain[id] = active; 
     315      if(active === true) 
     316      { 
     317            CKEDITOR.instances['body_'+id].destroy(); 
     318            var height = document.body.scrollHeight; 
     319            height -= 330; 
     320            $('#body_'+id).height(height); 
     321            $('#body_'+id).keydown(function(event) { 
     322                away = false; 
     323                var save_link = Element("save_message_options_"+id); 
     324                save_link.onclick = function onclick() {openTab.toPreserve[id] = true;save_msg(id);} ; 
     325                save_link.className = 'message_options'; 
     326            }); 
     327 
     328      }    
     329      else 
     330          RichTextEditor.active('body_'+id); 
     331} 
     332 
     333cRichTextEditor.prototype.getData = function (inst){   
     334    var id = inst.replace('body_',''); 
     335     
     336    if(RichTextEditor.plain[id] === true) 
     337        return $('#'+inst).val(); 
     338    else 
     339        return CKEDITOR.instances[inst].getData(); 
     340} 
     341cRichTextEditor.prototype.setData = function (id,data){ 
     342     
     343     if(this.plain[id] === true) 
     344        $('#'+id).val(data); 
     345     else 
     346        CKEDITOR.instances[id].setData(data) 
     347} 
     348cRichTextEditor.prototype.setInitData = function (id,data,reply,recursion){ 
     349     
     350    if(recursion === undefined) recursion = 1; 
     351    else recursion++;     
     352     
     353     if(this.plain[id] === true) 
     354     { 
     355                 if($('#'+id) !== undefined) 
     356                        $('#'+id).val(data); 
     357         else 
     358                          setTimeout(function() {RichTextEditor.setInitData(id,data,reply,recursion); }, 500); 
     359         }   
     360     else 
     361     { 
     362       if( RichTextEditor.editorReady === true && CKEDITOR.instances['body_'+id] !== undefined )     
     363       { 
     364           var editor =   CKEDITOR.instances['body_'+id];    
     365           editor.insertHtml(''); 
     366           var selection = editor.getSelection(); 
     367           if(selection !== undefined && selection !== null) var selectionRanges = selection.getRanges();  
     368 
     369           editor.insertHtml('<div><br type="_moz"></div>'+data); 
     370            
     371          if(selection !== null) selection.selectRanges(selectionRanges);  
     372           
     373          editor.execCommand("autogrow"); //Atualiza tamanho do editor 
     374           
     375          //Caso não for uma resposta votla o foco para o input to 
     376          if(reply === undefined)     
     377                  setTimeout("$('#to_"+id+"').focus()",100); 
     378   
     379       } 
     380       else if(recursion < 20) 
     381           setTimeout(function() {RichTextEditor.setInitData(id,data,reply,recursion); }, 500); 
     382     }  
     383} 
     384 
     385cRichTextEditor.prototype.destroy = function(id) 
     386{ 
     387        //Remove Instancia do editor 
     388        if( CKEDITOR.instances[id] !== undefined )    
     389             CKEDITOR.remove(CKEDITOR.instances[id]); 
     390} 
     391cRichTextEditor.prototype.active = function(id) 
     392{ 
     393    
     394   //Remove Instancia do editor caso ela exista 
     395    if( CKEDITOR.instances[id] !== undefined )    
     396         CKEDITOR.remove(CKEDITOR.instances[id]); 
     397      
     398     $('#'+id).ckeditor(  
     399          function() {RichTextEditor.execPosInstance(id)}, 
     400          { 
     401              toolbar:'mail'       
     402          });  
     403 
     404} 
     405cRichTextEditor.prototype.focus = function(id) 
     406{ 
     407    if(RichTextEditor.plain[id]  === true) 
     408        $('#body_'+id).focus(); 
     409    else 
     410        CKEDITOR.instances['body_'+id].focus();  
     411 
     412} 
     413//Função reseta o atributo contentEditable para resolver bug de cursor ao trocar abas  
     414cRichTextEditor.prototype.setEditable = function(id) {  
     415        if( CKEDITOR.instances['body_'+ id] === undefined ) return;     
     416        var element = CKEDITOR.instances['body_'+ id].document.getBody();  
     417        element.removeAttribute('contentEditable');  
     418        element.setAttribute('contentEditable','true');  
    539419}  
    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  
    560 cRichTextEditor.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  
    576 cRichTextEditor.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  
    612 cRichTextEditor.prototype.incrementField = function(id_val){ 
    613         var field_text = document.getElementById(id_val); 
    614         field_text.value = parseInt(field_text.value)+1; 
    615 } 
    616  
    617 cRichTextEditor.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  
    623 cRichTextEditor.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 } 
    660 cRichTextEditor.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  
    695 cRichTextEditor.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  
    708 cRichTextEditor.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  
    718 cRichTextEditor.prototype.hide_pc = function() 
    719 { 
    720         document.getElementById("palettecolor").style.visibility="hidden"; 
    721 } 
    722  
    723 cRichTextEditor.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  
    733 cRichTextEditor.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  
    743420//Build the Object 
    744421RichTextEditor = new cRichTextEditor(); 
Note: See TracChangeset for help on using the changeset viewer.