2 Copyright (c) 2003-2011, 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
30 'width: 16px !important;' +
\r
31 'height: 16px !important;' +
\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 ) && !element.isReadOnly() )
\r
135 return { form : CKEDITOR.TRISTATE_OFF };
\r
138 editor.contextMenu.addListener( function( element )
\r
140 if ( element && !element.isReadOnly() )
\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 switch( element.getAttribute( 'type' ) )
\r
157 return { button : CKEDITOR.TRISTATE_OFF };
\r
160 return { checkbox : CKEDITOR.TRISTATE_OFF };
\r
163 return { radio : CKEDITOR.TRISTATE_OFF };
\r
166 return { imagebutton : CKEDITOR.TRISTATE_OFF };
\r
169 return { textfield : CKEDITOR.TRISTATE_OFF };
\r
173 if ( name == 'img' && element.data( 'cke-real-element-type' ) == 'hiddenfield' )
\r
174 return { hiddenfield : CKEDITOR.TRISTATE_OFF };
\r
179 editor.on( 'doubleclick', function( evt )
\r
181 var element = evt.data.element;
\r
183 if ( element.is( 'form' ) )
\r
184 evt.data.dialog = 'form';
\r
185 else if ( element.is( 'select' ) )
\r
186 evt.data.dialog = 'select';
\r
187 else if ( element.is( 'textarea' ) )
\r
188 evt.data.dialog = 'textarea';
\r
189 else if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'hiddenfield' )
\r
190 evt.data.dialog = 'hiddenfield';
\r
191 else if ( element.is( 'input' ) )
\r
193 switch ( element.getAttribute( 'type' ) )
\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
210 evt.data.dialog = 'textfield';
\r
217 afterInit : function( editor )
\r
219 var dataProcessor = editor.dataProcessor,
\r
220 htmlFilter = dataProcessor && dataProcessor.htmlFilter,
\r
221 dataFilter = dataProcessor && dataProcessor.dataFilter;
\r
223 // Cleanup certain IE form elements default values.
\r
224 if ( CKEDITOR.env.ie )
\r
226 htmlFilter && htmlFilter.addRules(
\r
230 input : function( input )
\r
232 var attrs = input.attributes,
\r
234 // Old IEs don't provide type for Text inputs #5522
\r
236 attrs.type = 'text';
\r
237 if ( type == 'checkbox' || type == 'radio' )
\r
238 attrs.value == 'on' && delete attrs.value;
\r
246 dataFilter.addRules(
\r
250 input : function( element )
\r
252 if ( element.attributes.type == 'hidden' )
\r
253 return editor.createFakeParserElement( element, 'cke_hidden', 'hiddenfield' );
\r
259 requires : [ 'image', 'fakeobjects' ]
\r
262 if ( CKEDITOR.env.ie )
\r
264 CKEDITOR.dom.element.prototype.hasAttribute = function( name )
\r
266 var $attr = this.$.attributes.getNamedItem( name );
\r
268 if ( this.getName() == 'input' )
\r
273 return this.$.className.length > 0;
\r
275 return !!this.$.checked;
\r
277 var type = this.getAttribute( 'type' );
\r
278 return type == 'checkbox' || type == 'radio' ? this.$.value != 'on' : this.$.value;
\r
282 return !!( $attr && $attr.specified );
\r