2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
5 CKEDITOR
.dialog
.add( 'radio', function( editor
)
8 title
: editor
.lang
.checkboxAndRadio
.radioTitle
,
13 delete this.radioButton
;
15 var element
= this.getParentEditor().getSelection().getSelectedElement();
16 if ( element
&& element
.getName() == 'input' && element
.getAttribute( 'type' ) == 'radio' )
18 this.radioButton
= element
;
19 this.setupContent( element
);
25 element
= this.radioButton
,
26 isInsertMode
= !element
;
30 editor
= this.getParentEditor();
31 element
= editor
.document
.createElement( 'input' );
32 element
.setAttribute( 'type', 'radio' );
36 editor
.insertElement( element
);
37 this.commitContent( { element
: element
} );
42 label
: editor
.lang
.checkboxAndRadio
.radioTitle
,
43 title
: editor
.lang
.checkboxAndRadio
.radioTitle
,
48 label
: editor
.lang
.common
.name
,
51 setup : function( element
)
54 element
.data( 'cke-saved-name' ) ||
55 element
.getAttribute( 'name' ) ||
58 commit : function( data
)
60 var element
= data
.element
;
62 if ( this.getValue() )
63 element
.data( 'cke-saved-name', this.getValue() );
66 element
.data( 'cke-saved-name', false );
67 element
.removeAttribute( 'name' );
74 label
: editor
.lang
.checkboxAndRadio
.value
,
77 setup : function( element
)
79 this.setValue( element
.getAttribute( 'value' ) || '' );
81 commit : function( data
)
83 var element
= data
.element
;
85 if ( this.getValue() )
86 element
.setAttribute( 'value', this.getValue() );
88 element
.removeAttribute( 'value' );
94 label
: editor
.lang
.checkboxAndRadio
.selected
,
98 setup : function( element
)
100 this.setValue( element
.getAttribute( 'checked' ) );
102 commit : function( data
)
104 var element
= data
.element
;
106 if ( !( CKEDITOR
.env
.ie
|| CKEDITOR
.env
.opera
) )
108 if ( this.getValue() )
109 element
.setAttribute( 'checked', 'checked' );
111 element
.removeAttribute( 'checked' );
115 var isElementChecked
= element
.getAttribute( 'checked' );
116 var isChecked
= !!this.getValue();
118 if ( isElementChecked
!= isChecked
)
120 var replace
= CKEDITOR
.dom
.element
.createFromHtml( '<input type="radio"'
121 + ( isChecked
? ' checked="checked"' : '' )
122 + '></input>', editor
.document
);
123 element
.copyAttributes( replace
, { type
: 1, checked
: 1 } );
124 replace
.replace( element
);
125 editor
.getSelection().selectElement( replace
);
126 data
.element
= replace
;