2 Copyright (c) 2003-2012, 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 requires : [ 'dialog' ],
\r
13 init : function( editor )
\r
15 var lang = editor.lang;
\r
20 'border: 1px dotted #FF0000;' +
\r
27 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/hiddenfield.gif' ) + ');' +
\r
28 'background-position: center center;' +
\r
29 'background-repeat: no-repeat;' +
\r
30 'border: 1px solid #a9a9a9;' +
\r
31 'width: 16px !important;' +
\r
32 'height: 16px !important;' +
\r
35 // All buttons use the same code to register. So, to avoid
\r
36 // duplications, let's use this tool function.
\r
37 var addButtonCommand = function( buttonName, commandName, dialogFile )
\r
39 editor.addCommand( commandName, new CKEDITOR.dialogCommand( commandName ) );
\r
41 editor.ui.addButton( buttonName,
\r
43 label : lang.common[ buttonName.charAt(0).toLowerCase() + buttonName.slice(1) ],
\r
44 command : commandName
\r
46 CKEDITOR.dialog.add( commandName, dialogFile );
\r
49 var dialogPath = this.path + 'dialogs/';
\r
50 addButtonCommand( 'Form', 'form', dialogPath + 'form.js' );
\r
51 addButtonCommand( 'Checkbox', 'checkbox', dialogPath + 'checkbox.js' );
\r
52 addButtonCommand( 'Radio', 'radio', dialogPath + 'radio.js' );
\r
53 addButtonCommand( 'TextField', 'textfield', dialogPath + 'textfield.js' );
\r
54 addButtonCommand( 'Textarea', 'textarea', dialogPath + 'textarea.js' );
\r
55 addButtonCommand( 'Select', 'select', dialogPath + 'select.js' );
\r
56 addButtonCommand( 'Button', 'button', dialogPath + 'button.js' );
\r
57 addButtonCommand( 'ImageButton', 'imagebutton', CKEDITOR.plugins.getPath('image') + 'dialogs/image.js' );
\r
58 addButtonCommand( 'HiddenField', 'hiddenfield', dialogPath + 'hiddenfield.js' );
\r
60 // If the "menu" plugin is loaded, register the menu items.
\r
61 if ( editor.addMenuItems )
\r
63 editor.addMenuItems(
\r
67 label : lang.form.menu,
\r
74 label : lang.checkboxAndRadio.checkboxTitle,
\r
75 command : 'checkbox',
\r
81 label : lang.checkboxAndRadio.radioTitle,
\r
88 label : lang.textfield.title,
\r
89 command : 'textfield',
\r
95 label : lang.hidden.title,
\r
96 command : 'hiddenfield',
\r
97 group : 'hiddenfield'
\r
102 label : lang.image.titleButton,
\r
103 command : 'imagebutton',
\r
104 group : 'imagebutton'
\r
109 label : lang.button.title,
\r
110 command : 'button',
\r
116 label : lang.select.title,
\r
117 command : 'select',
\r
123 label : lang.textarea.title,
\r
124 command : 'textarea',
\r
130 // If the "contextmenu" plugin is loaded, register the listeners.
\r
131 if ( editor.contextMenu )
\r
133 editor.contextMenu.addListener( function( element )
\r
135 if ( element && element.hasAscendant( 'form', true ) && !element.isReadOnly() )
\r
136 return { form : CKEDITOR.TRISTATE_OFF };
\r
139 editor.contextMenu.addListener( function( element )
\r
141 if ( element && !element.isReadOnly() )
\r
143 var name = element.getName();
\r
145 if ( name == 'select' )
\r
146 return { select : CKEDITOR.TRISTATE_OFF };
\r
148 if ( name == 'textarea' )
\r
149 return { textarea : CKEDITOR.TRISTATE_OFF };
\r
151 if ( name == 'input' )
\r
153 switch( element.getAttribute( 'type' ) )
\r
158 return { button : CKEDITOR.TRISTATE_OFF };
\r
161 return { checkbox : CKEDITOR.TRISTATE_OFF };
\r
164 return { radio : CKEDITOR.TRISTATE_OFF };
\r
167 return { imagebutton : CKEDITOR.TRISTATE_OFF };
\r
170 return { textfield : CKEDITOR.TRISTATE_OFF };
\r
174 if ( name == 'img' && element.data( 'cke-real-element-type' ) == 'hiddenfield' )
\r
175 return { hiddenfield : CKEDITOR.TRISTATE_OFF };
\r
180 editor.on( 'doubleclick', function( evt )
\r
182 var element = evt.data.element;
\r
184 if ( element.is( 'form' ) )
\r
185 evt.data.dialog = 'form';
\r
186 else if ( element.is( 'select' ) )
\r
187 evt.data.dialog = 'select';
\r
188 else if ( element.is( 'textarea' ) )
\r
189 evt.data.dialog = 'textarea';
\r
190 else if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'hiddenfield' )
\r
191 evt.data.dialog = 'hiddenfield';
\r
192 else if ( element.is( 'input' ) )
\r
194 switch ( element.getAttribute( 'type' ) )
\r
199 evt.data.dialog = 'button';
\r
202 evt.data.dialog = 'checkbox';
\r
205 evt.data.dialog = 'radio';
\r
208 evt.data.dialog = 'imagebutton';
\r
211 evt.data.dialog = 'textfield';
\r
218 afterInit : function( editor )
\r
220 var dataProcessor = editor.dataProcessor,
\r
221 htmlFilter = dataProcessor && dataProcessor.htmlFilter,
\r
222 dataFilter = dataProcessor && dataProcessor.dataFilter;
\r
224 // Cleanup certain IE form elements default values.
\r
225 if ( CKEDITOR.env.ie )
\r
227 htmlFilter && htmlFilter.addRules(
\r
231 input : function( input )
\r
233 var attrs = input.attributes,
\r
235 // Old IEs don't provide type for Text inputs #5522
\r
237 attrs.type = 'text';
\r
238 if ( type == 'checkbox' || type == 'radio' )
\r
239 attrs.value == 'on' && delete attrs.value;
\r
247 dataFilter.addRules(
\r
251 input : function( element )
\r
253 if ( element.attributes.type == 'hidden' )
\r
254 return editor.createFakeParserElement( element, 'cke_hidden', 'hiddenfield' );
\r
260 requires : [ 'image', 'fakeobjects' ]
\r
263 if ( CKEDITOR.env.ie )
\r
265 CKEDITOR.dom.element.prototype.hasAttribute = CKEDITOR.tools.override( CKEDITOR.dom.element.prototype.hasAttribute,
\r
266 function( original )
\r
268 return function( name )
\r
270 var $attr = this.$.attributes.getNamedItem( name );
\r
272 if ( this.getName() == 'input' )
\r
277 return this.$.className.length > 0;
\r
279 return !!this.$.checked;
\r
281 var type = this.getAttribute( 'type' );
\r
282 return type == 'checkbox' || type == 'radio' ? this.$.value != 'on' : this.$.value;
\r
286 return original.apply( this, arguments );
\r