5caac871481df9e1fedf0acc3d3332aeac8ade4c
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
10 CKEDITOR
.plugins
.add( 'forms',
12 init : function( editor
)
14 var lang
= editor
.lang
;
19 'border: 1px dotted #FF0000;' +
26 'background-image: url(' + CKEDITOR
.getUrl( this.path
+ 'images/hiddenfield.gif' ) + ');' +
27 'background-position: center center;' +
28 'background-repeat: no-repeat;' +
29 'border: 1px solid #a9a9a9;' +
30 'width: 16px !important;' +
31 'height: 16px !important;' +
34 // All buttons use the same code to register. So, to avoid
35 // duplications, let's use this tool function.
36 var addButtonCommand = function( buttonName
, commandName
, dialogFile
)
38 editor
.addCommand( commandName
, new CKEDITOR
.dialogCommand( commandName
) );
40 editor
.ui
.addButton( buttonName
,
42 label
: lang
.common
[ buttonName
.charAt(0).toLowerCase() + buttonName
.slice(1) ],
45 CKEDITOR
.dialog
.add( commandName
, dialogFile
);
48 var dialogPath
= this.path
+ 'dialogs/';
49 addButtonCommand( 'Form', 'form', dialogPath
+ 'form.js' );
50 addButtonCommand( 'Checkbox', 'checkbox', dialogPath
+ 'checkbox.js' );
51 addButtonCommand( 'Radio', 'radio', dialogPath
+ 'radio.js' );
52 addButtonCommand( 'TextField', 'textfield', dialogPath
+ 'textfield.js' );
53 addButtonCommand( 'Textarea', 'textarea', dialogPath
+ 'textarea.js' );
54 addButtonCommand( 'Select', 'select', dialogPath
+ 'select.js' );
55 addButtonCommand( 'Button', 'button', dialogPath
+ 'button.js' );
56 addButtonCommand( 'ImageButton', 'imagebutton', CKEDITOR
.plugins
.getPath('image') + 'dialogs/image.js' );
57 addButtonCommand( 'HiddenField', 'hiddenfield', dialogPath
+ 'hiddenfield.js' );
59 // If the "menu" plugin is loaded, register the menu items.
60 if ( editor
.addMenuItems
)
66 label
: lang
.form
.menu
,
73 label
: lang
.checkboxAndRadio
.checkboxTitle
,
80 label
: lang
.checkboxAndRadio
.radioTitle
,
87 label
: lang
.textfield
.title
,
88 command
: 'textfield',
94 label
: lang
.hidden
.title
,
95 command
: 'hiddenfield',
101 label
: lang
.image
.titleButton
,
102 command
: 'imagebutton',
103 group
: 'imagebutton'
108 label
: lang
.button
.title
,
115 label
: lang
.select
.title
,
122 label
: lang
.textarea
.title
,
123 command
: 'textarea',
129 // If the "contextmenu" plugin is loaded, register the listeners.
130 if ( editor
.contextMenu
)
132 editor
.contextMenu
.addListener( function( element
)
134 if ( element
&& element
.hasAscendant( 'form', true ) && !element
.isReadOnly() )
135 return { form
: CKEDITOR
.TRISTATE_OFF
};
138 editor
.contextMenu
.addListener( function( element
)
140 if ( element
&& !element
.isReadOnly() )
142 var name
= element
.getName();
144 if ( name
== 'select' )
145 return { select
: CKEDITOR
.TRISTATE_OFF
};
147 if ( name
== 'textarea' )
148 return { textarea
: CKEDITOR
.TRISTATE_OFF
};
150 if ( name
== 'input' )
152 switch( element
.getAttribute( 'type' ) )
157 return { button
: CKEDITOR
.TRISTATE_OFF
};
160 return { checkbox
: CKEDITOR
.TRISTATE_OFF
};
163 return { radio
: CKEDITOR
.TRISTATE_OFF
};
166 return { imagebutton
: CKEDITOR
.TRISTATE_OFF
};
169 return { textfield
: CKEDITOR
.TRISTATE_OFF
};
173 if ( name
== 'img' && element
.data( 'cke-real-element-type' ) == 'hiddenfield' )
174 return { hiddenfield
: CKEDITOR
.TRISTATE_OFF
};
179 editor
.on( 'doubleclick', function( evt
)
181 var element
= evt
.data
.element
;
183 if ( element
.is( 'form' ) )
184 evt
.data
.dialog
= 'form';
185 else if ( element
.is( 'select' ) )
186 evt
.data
.dialog
= 'select';
187 else if ( element
.is( 'textarea' ) )
188 evt
.data
.dialog
= 'textarea';
189 else if ( element
.is( 'img' ) && element
.data( 'cke-real-element-type' ) == 'hiddenfield' )
190 evt
.data
.dialog
= 'hiddenfield';
191 else if ( element
.is( 'input' ) )
193 switch ( element
.getAttribute( 'type' ) )
198 evt
.data
.dialog
= 'button';
201 evt
.data
.dialog
= 'checkbox';
204 evt
.data
.dialog
= 'radio';
207 evt
.data
.dialog
= 'imagebutton';
210 evt
.data
.dialog
= 'textfield';
217 afterInit : function( editor
)
219 var dataProcessor
= editor
.dataProcessor
,
220 htmlFilter
= dataProcessor
&& dataProcessor
.htmlFilter
,
221 dataFilter
= dataProcessor
&& dataProcessor
.dataFilter
;
223 // Cleanup certain IE form elements default values.
224 if ( CKEDITOR
.env
.ie
)
226 htmlFilter
&& htmlFilter
.addRules(
230 input : function( input
)
232 var attrs
= input
.attributes
,
234 // Old IEs don't provide type for Text inputs #5522
237 if ( type
== 'checkbox' || type
== 'radio' )
238 attrs
.value
== 'on' && delete attrs
.value
;
250 input : function( element
)
252 if ( element
.attributes
.type
== 'hidden' )
253 return editor
.createFakeParserElement( element
, 'cke_hidden', 'hiddenfield' );
259 requires
: [ 'image', 'fakeobjects' ]
262 if ( CKEDITOR
.env
.ie
)
264 CKEDITOR
.dom
.element
.prototype.hasAttribute
= CKEDITOR
.tools
.override( CKEDITOR
.dom
.element
.prototype.hasAttribute
,
267 return function( name
)
269 var $attr
= this.$.attributes
.getNamedItem( name
);
271 if ( this.getName() == 'input' )
276 return this.$.className
.length
> 0;
278 return !!this.$.checked
;
280 var type
= this.getAttribute( 'type' );
281 return type
== 'checkbox' || type
== 'radio' ? this.$.value
!= 'on' : this.$.value
;
285 return original
.apply( this, arguments
);