2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
10 CKEDITOR.plugins.add( 'forms',
\r
12 init : function( editor )
\r
14 var lang = editor.lang;
\r
19 'border: 1px dotted #FF0000;' +
\r
26 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/hiddenfield.gif' ) + ');' +
\r
27 'background-position: center center;' +
\r
28 'background-repeat: no-repeat;' +
\r
29 'border: 1px solid #a9a9a9;' +
\r
34 // All buttons use the same code to register. So, to avoid
\r
35 // duplications, let's use this tool function.
\r
36 var addButtonCommand = function( buttonName, commandName, dialogFile )
\r
38 editor.addCommand( commandName, new CKEDITOR.dialogCommand( commandName ) );
\r
40 editor.ui.addButton( buttonName,
\r
42 label : lang.common[ buttonName.charAt(0).toLowerCase() + buttonName.slice(1) ],
\r
43 command : commandName
\r
45 CKEDITOR.dialog.add( commandName, dialogFile );
\r
48 var dialogPath = this.path + 'dialogs/';
\r
49 addButtonCommand( 'Form', 'form', dialogPath + 'form.js' );
\r
50 addButtonCommand( 'Checkbox', 'checkbox', dialogPath + 'checkbox.js' );
\r
51 addButtonCommand( 'Radio', 'radio', dialogPath + 'radio.js' );
\r
52 addButtonCommand( 'TextField', 'textfield', dialogPath + 'textfield.js' );
\r
53 addButtonCommand( 'Textarea', 'textarea', dialogPath + 'textarea.js' );
\r
54 addButtonCommand( 'Select', 'select', dialogPath + 'select.js' );
\r
55 addButtonCommand( 'Button', 'button', dialogPath + 'button.js' );
\r
56 addButtonCommand( 'ImageButton', 'imagebutton', CKEDITOR.plugins.getPath('image') + 'dialogs/image.js' );
\r
57 addButtonCommand( 'HiddenField', 'hiddenfield', dialogPath + 'hiddenfield.js' );
\r
59 // If the "menu" plugin is loaded, register the menu items.
\r
60 if ( editor.addMenuItems )
\r
62 editor.addMenuItems(
\r
66 label : lang.form.menu,
\r
73 label : lang.checkboxAndRadio.checkboxTitle,
\r
74 command : 'checkbox',
\r
80 label : lang.checkboxAndRadio.radioTitle,
\r
87 label : lang.textfield.title,
\r
88 command : 'textfield',
\r
94 label : lang.hidden.title,
\r
95 command : 'hiddenfield',
\r
96 group : 'hiddenfield'
\r
101 label : lang.image.titleButton,
\r
102 command : 'imagebutton',
\r
103 group : 'imagebutton'
\r
108 label : lang.button.title,
\r
109 command : 'button',
\r
115 label : lang.select.title,
\r
116 command : 'select',
\r
122 label : lang.textarea.title,
\r
123 command : 'textarea',
\r
129 // If the "contextmenu" plugin is loaded, register the listeners.
\r
130 if ( editor.contextMenu )
\r
132 editor.contextMenu.addListener( function( element )
\r
134 if ( element && element.hasAscendant( 'form', true ) )
\r
135 return { form : CKEDITOR.TRISTATE_OFF };
\r
138 editor.contextMenu.addListener( function( element )
\r
142 var name = element.getName();
\r
144 if ( name == 'select' )
\r
145 return { select : CKEDITOR.TRISTATE_OFF };
\r
147 if ( name == 'textarea' )
\r
148 return { textarea : CKEDITOR.TRISTATE_OFF };
\r
150 if ( name == 'input' )
\r
152 var type = element.getAttribute( 'type' );
\r
154 if ( type == 'text' || type == 'password' )
\r
155 return { textfield : CKEDITOR.TRISTATE_OFF };
\r
157 if ( type == 'button' || type == 'submit' || type == 'reset' )
\r
158 return { button : CKEDITOR.TRISTATE_OFF };
\r
160 if ( type == 'checkbox' )
\r
161 return { checkbox : CKEDITOR.TRISTATE_OFF };
\r
163 if ( type == 'radio' )
\r
164 return { radio : CKEDITOR.TRISTATE_OFF };
\r
166 if ( type == 'image' )
\r
167 return { imagebutton : CKEDITOR.TRISTATE_OFF };
\r
170 if ( name == 'img' && element.getAttribute( '_cke_real_element_type' ) == 'hiddenfield' )
\r
171 return { hiddenfield : CKEDITOR.TRISTATE_OFF };
\r
176 editor.on( 'doubleclick', function( evt )
\r
178 var element = evt.data.element;
\r
180 if ( element.is( 'form' ) )
\r
181 evt.data.dialog = 'form';
\r
182 else if ( element.is( 'select' ) )
\r
183 evt.data.dialog = 'select';
\r
184 else if ( element.is( 'textarea' ) )
\r
185 evt.data.dialog = 'textarea';
\r
186 else if ( element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'hiddenfield' )
\r
187 evt.data.dialog = 'hiddenfield';
\r
188 else if ( element.is( 'input' ) )
\r
190 var type = element.getAttribute( 'type' );
\r
194 case 'text' : case 'password':
\r
195 evt.data.dialog = 'textfield';
\r
197 case 'button' : case 'submit' : case 'reset' :
\r
198 evt.data.dialog = 'button';
\r
201 evt.data.dialog = 'checkbox';
\r
204 evt.data.dialog = 'radio';
\r
207 evt.data.dialog = 'imagebutton';
\r
214 afterInit : function( editor )
\r
216 var dataProcessor = editor.dataProcessor,
\r
217 htmlFilter = dataProcessor && dataProcessor.htmlFilter,
\r
218 dataFilter = dataProcessor && dataProcessor.dataFilter;
\r
220 // Cleanup certain IE form elements default values.
\r
221 if ( CKEDITOR.env.ie )
\r
223 htmlFilter && htmlFilter.addRules(
\r
227 input : function( input )
\r
229 var attrs = input.attributes,
\r
231 if ( type == 'checkbox' || type == 'radio' )
\r
232 attrs.value == 'on' && delete attrs.value;
\r
240 dataFilter.addRules(
\r
244 input : function( element )
\r
246 if ( element.attributes.type == 'hidden' )
\r
247 return editor.createFakeParserElement( element, 'cke_hidden', 'hiddenfield' );
\r
253 requires : [ 'image', 'fakeobjects' ]
\r
256 if ( CKEDITOR.env.ie )
\r
258 CKEDITOR.dom.element.prototype.hasAttribute = function( name )
\r
260 var $attr = this.$.attributes.getNamedItem( name );
\r
262 if ( this.getName() == 'input' )
\r
267 return this.$.className.length > 0;
\r
269 return !!this.$.checked;
\r
271 var type = this.getAttribute( 'type' );
\r
272 if ( type == 'checkbox' || type == 'radio' )
\r
273 return this.$.value != 'on';
\r
279 return !!( $attr && $attr.specified );
\r