source: trunk/library/ckeditor/plugins/expresso/plugin.js @ 8247

Revision 8247, 10.7 KB checked in by angelo, 10 years ago (diff)

Ticket #3493 - Atualizar bibioteca CKEditor do Expresso

  • Property svn:executable set to *
Line 
1
2
3CKEDITOR.plugins.add('expresso',
4{
5   
6    init: function (editor) {
7        var pluginName = 'expresso';
8        editor.ui.addButton('expAddImage',
9            {
10                label: 'Adicionar Imagem',
11                command: 'imgDialog',
12                icon: CKEDITOR.plugins.getPath('expresso') + 'img/Image.gif'
13            });
14                       
15        editor.ui.addRichCombo('expSignature',
16        {
17                    label: 'Assinaturas',
18                    voiceLabel : "Assinaturas",
19                    title: 'Assinaturas',
20                    className : 'cke_format',
21                    panel :
22                    {
23                           css : [ CKEDITOR.config.contentsCss, CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ],
24                           voiceLabel : 'xala'
25                    },
26
27                    init : function()
28                    {
29                         var options = RichTextEditor.getSignaturesOptions();
30                         for( var key in options )
31                             this.add(  options[key],key,key);   
32                                             
33                    },
34                   
35                    onClick : function( value )
36                    {         
37                       editor.focus();
38                       editor.fire( 'saveSnapshot' );
39                       editor.insertHtml(unescape(value));
40                       editor.fire( 'saveSnapshot' );
41                    }
42
43        });
44       
45       
46        editor.addCommand( 'imgDialog',new CKEDITOR.dialogCommand( 'imgDialog' ) );
47
48                if ( editor.contextMenu )
49                {
50                        editor.addMenuGroup( 'mygroup', 10 );
51                        editor.addMenuItem( 'My Dialog',
52                        {
53                                label : 'Adicionar imagem',
54                                command : 'imgDialog',
55                                group : 'mygroup',
56                icon: CKEDITOR.plugins.getPath('expresso') + 'img/Image.gif'
57                        });
58                        editor.contextMenu.addListener( function( element )
59                        {
60                                return {'My Dialog' : CKEDITOR.TRISTATE_OFF};
61                        });
62                }
63               
64                CKEDITOR.dialog.add( 'imgDialog', function( api )
65                {
66            var ID = currentTab;
67                        // CKEDITOR.dialog.definition
68                        var dialogDefinition =
69                        {
70                               
71                title : 'Inserir Imagem',
72                                minWidth : 400,
73                                minHeight : 70,
74                                contents : [
75                                        {
76                                                id : 'tab1',
77                                                label : 'Label',
78                                                title : 'Title',
79                                                expand : true,
80                                                padding : 0,
81                                                elements :
82                                                [
83                                                        {
84                                                                type : 'html',
85                                                                html :  '<form id="fileupload_img'+ID+'" class="fileupload" action="mailAttachment:img" method="POST">    <input type="file" name="files[]"  onclick="bindFileUpload(this);" style="margin-left:10px"></form>'
86                                                        }
87                                                ]
88                                        }
89                                ],
90                                buttons : [ CKEDITOR.dialog.cancelButton]
91                               
92                        };
93                               
94                        return dialogDefinition;
95                } );
96       
97         
98
99    }
100});
101function bindFileUpload(e) {
102        var ID = currentTab;
103        var fileUploadIMG = $(e).parents('form');
104        var fileUploadMSG = $('#fileupload_msg'+ID);
105        var maxAttachmentSize = (preferences.max_attachment_size !== "" && preferences.max_attachment_size != 0) ? (parseInt(preferences.max_attachment_size.replace('M', '')) * 1048576 ) : false;
106        fileUploadIMG.fileupload({
107                type: 'post',
108                dataType : 'json',
109                url: "../prototype/post.php",
110                forceIframeTransport: true,
111                formData: function(form) {
112                        return [
113                                {
114                                        name : "mailAttachment[0][source]",
115                                        value : "files0"
116                                },
117                                {
118                                        name : "mailAttachment[0][disposition]",
119                                        value : $('#attDisposition'+ID).val()
120                                },
121                                {
122                                        name: "MAX_FILE_SIZE",
123                                        value : maxAttachmentSize
124                                }
125                        ];
126                },
127                add: function (e, data) {
128            var iterator = idattachbycontent;
129                        if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize || is_ie) {
130                                setTimeout(function() {
131                                        $('#attDisposition'+ID).val('embedded');
132                                        jqXHR[iterator] = data.submit();
133                                }, 100);
134                        }
135            fileUploadMSG.find(' .attachments-list').show();
136                        $.each(data.files, function (index, file) {     
137                                var attach = {};
138                                attach.fullFileName = file.name;
139                                attach.fileName = file.name;
140                                if(file.name.length > 20)
141                                        attach.fileName = file.name.substr(0, 17) + "..." + file.name.substr(file.name.length-9, file.name.length);
142                                attach.fileSize = formatBytes(file.size);
143                                if(maxAttachmentSize && file.size > maxAttachmentSize)
144                                        attach.error = 'Tamanho de arquivo nao permitido!!'
145                                else
146                    attach.error = true;
147                                var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));   
148
149                                upload.find('.att-box-delete').click(function(){
150                                        var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
151                       
152                    var content_body = RichTextEditor.getData('body_'+ID);
153                    var imagens = content_body.match(/<img[^>]*>/g);
154       
155                    if(imagens != null)
156                        for (var x = 0; x < imagens.length; x++)
157                            if(imagens[x].indexOf('src="../prototype/getArchive.php?mailAttachment='+idAttach+'"') !== -1)
158                                content_body = content_body.replace(imagens[x],'');
159         
160                    RichTextEditor.setData('body_'+ID,content_body);   
161                                       
162                    $('.attachments-list').find('input[value="'+idAttach+'"]').remove();
163                    delAttachment(ID, idAttach);
164                                        $(this).parent().qtip("destroy");
165                    $(this).parent().remove();
166                    if(!fileUploadMSG.find(' .attachments-list').find(".att-box").length){
167                        fileUploadMSG.find(' .attachments-list').hide();
168                    }
169                    if(jqXHR){
170                        jqXHR[iterator].abort();
171                    }
172                                });
173                               
174                fileUploadMSG.find('.attachments-list').append(upload);
175                fileUploadMSG.find('.attachments-list .att-box:last').qtip({
176                    content: DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist_tooltip.ejs", {attach : attach}),
177                    position: {
178                        corner: {
179                            tooltip: 'bottomMiddle',
180                            target: 'topMiddle'
181                        },
182                        adjust: {
183                           resize: true,
184                           scroll: true,
185                           screen: true
186                        }
187                    },
188                    show: {
189                        when: 'mouseover', // Don't specify a show event
190                        ready: false // Show the tooltip when ready
191                    },
192                    hide: 'mouseout', // Don't specify a hide event
193                    style: {
194                        border: {
195                            width: 1,
196                            radius: 5
197                        },
198                        width: {
199                             min: 75,
200                             max : 1000
201                        },
202                        padding: 3,
203                        textAlign: 'left',
204                        tip: true, // Give it a speech bubble tip with automatic corner detection
205                        name: (typeof(attach.error) == 'boolean' ? 'light' : 'red') // Style it according to the preset 'cream' style
206                    }
207                });
208                        if(!maxAttachmentSize || file.size < maxAttachmentSize){
209                                if(data.fileInput){
210                                        fileUploadMSG.find('.fileinput-button.new').append(data.fileInput[0]).removeClass('new');
211                                        fileUploadMSG.find('.attachments-list').find('[type=file]').addClass('hidden');
212                                }
213                        }else{
214                                fileUploadMSG.find(' .fileinput-button.new').removeClass('new');
215                        }                                       
216                CKEDITOR.instances['body_'+ID].insertHtml('<img src=""/>');
217                idattachbycontent++;
218                        });
219               
220            CKEDITOR.dialog.getCurrent().hide();       
221                       
222                },
223                done: function(e, data){
224            var attach_box = fileUploadMSG.find('.att-box-loading:first').parents('.att-box');
225            var attach = {
226                fullFileName : attach_box.find(".att-box-fullfilename").text(),
227                fileSize : attach_box.find(".att-box-filesize").text(),
228                OK : true,
229                error : false
230            };
231            if(!!data.result && data.result != "[]" ){
232                var newAttach = data.result;                             
233                if(!newAttach.mailAttachment.error || newAttach.rollback !== false){
234                                        attach_box.append('<input type="hidden" name="fileId[]" value="'+newAttach['mailAttachment'][0][0].id+'"/>');
235                                        addAttachment(ID,newAttach['mailAttachment'][0][0].id);
236                                        var content_body  = RichTextEditor.getData('body_'+ID);
237                                        var rex = new RegExp('<img src="" [^\/>]*\/>', 'i');
238                                        var newImg = '<img src="../prototype/getArchive.php?mailAttachment='+newAttach['mailAttachment'][0][0].id+'" />';
239                                        content_body = content_body.replace(rex,newImg);
240                                        RichTextEditor.setData('body_'+ID,content_body);
241                                }else{
242                                        attach_box.addClass('invalid-email-box');
243                    attach.error = newAttach.mailAttachment.error ? newAttach.mailAttachment.error : 'Erro ao anexar...';
244                }
245                        }else {
246                attach_box.addClass('invalid-email-box');
247                attach.error = 'Erro ao anexar...';
248            }
249            attach_box.qtip("destroy").qtip({
250                content: DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist_tooltip.ejs", {attach : attach}),
251                position: {
252                    corner: {
253                        tooltip: 'bottomMiddle',
254                        target: 'topMiddle'
255                    },
256                    adjust: {
257                       resize: true,
258                       scroll: true,
259                       screen: true
260                    }
261                },
262                show: {
263                    when: 'mouseover', // Don't specify a show event
264                    ready: false // Show the tooltip when ready
265                },
266                hide: 'mouseout', // Don't specify a hide event
267                style: {
268                    border: {
269                        width: 1,
270                        radius: 5
271                    },
272                    width: {
273                         min: 75,
274                         max : 1000
275                    },
276                    padding: 3,
277                    textAlign: 'left',
278                    tip: true, // Give it a speech bubble tip with automatic corner detection
279                    name: (attach.error == false ? 'blue' : 'red')// Style it according to the preset 'cream' style
280                }
281            });
282            fileUploadMSG.find(' .att-box-loading:first').remove();
283                }
284        });
285}
Note: See TracBrowser for help on using the repository browser.