2 Copyright (c) 2003-2009, 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
23 // All buttons use the same code to register. So, to avoid
\r
24 // duplications, let's use this tool function.
\r
25 var addButtonCommand = function( buttonName, commandName, dialogFile )
\r
27 editor.addCommand( commandName, new CKEDITOR.dialogCommand( commandName ) );
\r
29 editor.ui.addButton( buttonName,
\r
31 label : lang.common[ buttonName.charAt(0).toLowerCase() + buttonName.slice(1) ],
\r
32 command : commandName
\r
34 CKEDITOR.dialog.add( commandName, dialogFile );
\r
37 var dialogPath = this.path + 'dialogs/';
\r
38 addButtonCommand( 'Form', 'form', dialogPath + 'form.js' );
\r
39 addButtonCommand( 'Checkbox', 'checkbox', dialogPath + 'checkbox.js' );
\r
40 addButtonCommand( 'Radio', 'radio', dialogPath + 'radio.js' );
\r
41 addButtonCommand( 'TextField', 'textfield', dialogPath + 'textfield.js' );
\r
42 addButtonCommand( 'Textarea', 'textarea', dialogPath + 'textarea.js' );
\r
43 addButtonCommand( 'Select', 'select', dialogPath + 'select.js' );
\r
44 addButtonCommand( 'Button', 'button', dialogPath + 'button.js' );
\r
45 addButtonCommand( 'ImageButton', 'imagebutton', CKEDITOR.plugins.getPath('image') + 'dialogs/image.js' );
\r
46 addButtonCommand( 'HiddenField', 'hiddenfield', dialogPath + 'hiddenfield.js' );
\r
48 // If the "menu" plugin is loaded, register the menu items.
\r
49 if ( editor.addMenuItems )
\r
51 editor.addMenuItems(
\r
55 label : lang.form.menu,
\r
62 label : lang.checkboxAndRadio.checkboxTitle,
\r
63 command : 'checkbox',
\r
69 label : lang.checkboxAndRadio.radioTitle,
\r
76 label : lang.textfield.title,
\r
77 command : 'textfield',
\r
83 label : lang.hidden.title,
\r
84 command : 'hiddenfield',
\r
85 group : 'hiddenfield'
\r
90 label : lang.image.titleButton,
\r
91 command : 'imagebutton',
\r
92 group : 'imagebutton'
\r
97 label : lang.button.title,
\r
104 label : lang.select.title,
\r
105 command : 'select',
\r
111 label : lang.textarea.title,
\r
112 command : 'textarea',
\r
118 // If the "contextmenu" plugin is loaded, register the listeners.
\r
119 if ( editor.contextMenu )
\r
121 editor.contextMenu.addListener( function( element )
\r
123 if ( element && element.hasAscendant( 'form', true ) )
\r
124 return { form : CKEDITOR.TRISTATE_OFF };
\r
127 editor.contextMenu.addListener( function( element )
\r
131 var name = element.getName();
\r
133 if ( name == 'select' )
\r
134 return { select : CKEDITOR.TRISTATE_OFF };
\r
136 if ( name == 'textarea' )
\r
137 return { textarea : CKEDITOR.TRISTATE_OFF };
\r
139 if ( name == 'input' )
\r
141 var type = element.getAttribute( 'type' );
\r
143 if ( type == 'text' || type == 'password' )
\r
144 return { textfield : CKEDITOR.TRISTATE_OFF };
\r
146 if ( type == 'button' || type == 'submit' || type == 'reset' )
\r
147 return { button : CKEDITOR.TRISTATE_OFF };
\r
149 if ( type == 'checkbox' )
\r
150 return { checkbox : CKEDITOR.TRISTATE_OFF };
\r
152 if ( type == 'radio' )
\r
153 return { radio : CKEDITOR.TRISTATE_OFF };
\r
155 if ( type == 'image' )
\r
156 return { imagebutton : CKEDITOR.TRISTATE_OFF };
\r
159 if ( name == 'img' && element.getAttribute( '_cke_real_element_type' ) == 'hiddenfield' )
\r
160 return { hiddenfield : CKEDITOR.TRISTATE_OFF };
\r
166 afterInit : function( editor )
\r
168 // Cleanup certain IE form elements default values.
\r
169 if( CKEDITOR.env.ie )
\r
171 var dataProcessor = editor.dataProcessor,
\r
172 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
\r
174 htmlFilter && htmlFilter.addRules(
\r
178 input : function( input )
\r
180 var attrs = input.attributes,
\r
182 if( type == 'checkbox' || type == 'radio' )
\r
183 attrs.value == 'on' && delete attrs.value;
\r
189 requires : [ 'image' ]
\r
192 if ( CKEDITOR.env.ie )
\r
194 CKEDITOR.dom.element.prototype.hasAttribute = function( name )
\r
196 var $attr = this.$.attributes.getNamedItem( name );
\r
198 if ( this.getName() == 'input' )
\r
203 return this.$.className.length > 0;
\r
205 return !!this.$.checked;
\r
207 var type = this.getAttribute( 'type' );
\r
208 if ( type == 'checkbox' || type == 'radio' )
\r
209 return this.$.value != 'on';
\r
215 return !!( $attr && $attr.specified );
\r