source: sandbox/3.0/phpgwapi/js/ckeditor/_source/plugins/forms/plugin.js @ 2862

Revision 2862, 5.3 KB checked in by rodsouza, 14 years ago (diff)

Ticket #663 - Atualizando e centralizando o CKEditor (v. 3.2.1)

Line 
1/*
2Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
3For licensing, see LICENSE.html or http://ckeditor.com/license
4*/
5
6/**
7 * @file Forms Plugin
8 */
9
10CKEDITOR.plugins.add( 'forms',
11{
12        init : function( editor )
13        {
14                var lang = editor.lang;
15
16                editor.addCss(
17                        'form' +
18                        '{' +
19                                'border: 1px dotted #FF0000;' +
20                                'padding: 2px;' +
21                        '}' );
22
23                // All buttons use the same code to register. So, to avoid
24                // duplications, let's use this tool function.
25                var addButtonCommand = function( buttonName, commandName, dialogFile )
26                {
27                        editor.addCommand( commandName, new CKEDITOR.dialogCommand( commandName ) );
28
29                        editor.ui.addButton( buttonName,
30                                {
31                                        label : lang.common[ buttonName.charAt(0).toLowerCase() + buttonName.slice(1) ],
32                                        command : commandName
33                                });
34                        CKEDITOR.dialog.add( commandName, dialogFile );
35                };
36
37                var dialogPath = this.path + 'dialogs/';
38                addButtonCommand( 'Form',                       'form',                 dialogPath + 'form.js' );
39                addButtonCommand( 'Checkbox',           'checkbox',             dialogPath + 'checkbox.js' );
40                addButtonCommand( 'Radio',                      'radio',                dialogPath + 'radio.js' );
41                addButtonCommand( 'TextField',          'textfield',    dialogPath + 'textfield.js' );
42                addButtonCommand( 'Textarea',           'textarea',             dialogPath + 'textarea.js' );
43                addButtonCommand( 'Select',                     'select',               dialogPath + 'select.js' );
44                addButtonCommand( 'Button',                     'button',               dialogPath + 'button.js' );
45                addButtonCommand( 'ImageButton',        'imagebutton',  CKEDITOR.plugins.getPath('image') + 'dialogs/image.js' );
46                addButtonCommand( 'HiddenField',        'hiddenfield',  dialogPath + 'hiddenfield.js' );
47
48                // If the "menu" plugin is loaded, register the menu items.
49                if ( editor.addMenuItems )
50                {
51                        editor.addMenuItems(
52                                {
53                                        form :
54                                        {
55                                                label : lang.form.menu,
56                                                command : 'form',
57                                                group : 'form'
58                                        },
59
60                                        checkbox :
61                                        {
62                                                label : lang.checkboxAndRadio.checkboxTitle,
63                                                command : 'checkbox',
64                                                group : 'checkbox'
65                                        },
66
67                                        radio :
68                                        {
69                                                label : lang.checkboxAndRadio.radioTitle,
70                                                command : 'radio',
71                                                group : 'radio'
72                                        },
73
74                                        textfield :
75                                        {
76                                                label : lang.textfield.title,
77                                                command : 'textfield',
78                                                group : 'textfield'
79                                        },
80
81                                        hiddenfield :
82                                        {
83                                                label : lang.hidden.title,
84                                                command : 'hiddenfield',
85                                                group : 'hiddenfield'
86                                        },
87
88                                        imagebutton :
89                                        {
90                                                label : lang.image.titleButton,
91                                                command : 'imagebutton',
92                                                group : 'imagebutton'
93                                        },
94
95                                        button :
96                                        {
97                                                label : lang.button.title,
98                                                command : 'button',
99                                                group : 'button'
100                                        },
101
102                                        select :
103                                        {
104                                                label : lang.select.title,
105                                                command : 'select',
106                                                group : 'select'
107                                        },
108
109                                        textarea :
110                                        {
111                                                label : lang.textarea.title,
112                                                command : 'textarea',
113                                                group : 'textarea'
114                                        }
115                                });
116                }
117
118                // If the "contextmenu" plugin is loaded, register the listeners.
119                if ( editor.contextMenu )
120                {
121                        editor.contextMenu.addListener( function( element )
122                                {
123                                        if ( element && element.hasAscendant( 'form', true ) )
124                                                return { form : CKEDITOR.TRISTATE_OFF };
125                                });
126
127                        editor.contextMenu.addListener( function( element )
128                                {
129                                        if ( element )
130                                        {
131                                                var name = element.getName();
132
133                                                if ( name == 'select' )
134                                                        return { select : CKEDITOR.TRISTATE_OFF };
135
136                                                if ( name == 'textarea' )
137                                                        return { textarea : CKEDITOR.TRISTATE_OFF };
138
139                                                if ( name == 'input' )
140                                                {
141                                                        var type = element.getAttribute( 'type' );
142
143                                                        if ( type == 'text' || type == 'password' )
144                                                                return { textfield : CKEDITOR.TRISTATE_OFF };
145
146                                                        if ( type == 'button' || type == 'submit' || type == 'reset' )
147                                                                return { button : CKEDITOR.TRISTATE_OFF };
148
149                                                        if ( type == 'checkbox' )
150                                                                return { checkbox : CKEDITOR.TRISTATE_OFF };
151
152                                                        if ( type == 'radio' )
153                                                                return { radio : CKEDITOR.TRISTATE_OFF };
154
155                                                        if ( type == 'image' )
156                                                                return { imagebutton : CKEDITOR.TRISTATE_OFF };
157                                                }
158
159                                                if ( name == 'img' && element.getAttribute( '_cke_real_element_type' ) == 'hiddenfield' )
160                                                        return { hiddenfield : CKEDITOR.TRISTATE_OFF };
161                                        }
162                                });
163                }
164        },
165
166        afterInit : function( editor )
167        {
168                // Cleanup certain IE form elements default values.
169                if ( CKEDITOR.env.ie )
170                {
171                        var dataProcessor = editor.dataProcessor,
172                                htmlFilter = dataProcessor && dataProcessor.htmlFilter;
173
174                        htmlFilter && htmlFilter.addRules(
175                        {
176                                elements :
177                                {
178                                        input : function( input )
179                                        {
180                                                var attrs = input.attributes,
181                                                        type = attrs.type;
182                                                if ( type == 'checkbox' || type == 'radio' )
183                                                        attrs.value == 'on' && delete attrs.value;
184                                        }
185                                }
186                        } );
187                }
188        },
189        requires : [ 'image' ]
190} );
191
192if ( CKEDITOR.env.ie )
193{
194        CKEDITOR.dom.element.prototype.hasAttribute = function( name )
195        {
196                var $attr = this.$.attributes.getNamedItem( name );
197
198                if ( this.getName() == 'input' )
199                {
200                        switch ( name )
201                        {
202                                case 'class' :
203                                        return this.$.className.length > 0;
204                                case 'checked' :
205                                        return !!this.$.checked;
206                                case 'value' :
207                                        var type = this.getAttribute( 'type' );
208                                        if ( type == 'checkbox' || type == 'radio' )
209                                                return this.$.value != 'on';
210                                        break;
211                                default:
212                        }
213                }
214
215                return !!( $attr && $attr.specified );
216        };
217}
Note: See TracBrowser for help on using the repository browser.