source: sandbox/2.5.1-evolucao/library/ckeditor/plugins/expresso/plugin.js @ 8264

Revision 8264, 12.7 KB checked in by angelo, 10 years ago (diff)

Ticket #0000 - sincronizacao parcial das alteracoes do trunk com este sandbox

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