2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
5 CKEDITOR
.dialog
.add( 'checkbox', function( editor
)
8 title
: editor
.lang
.checkboxAndRadio
.checkboxTitle
,
15 var element
= this.getParentEditor().getSelection().getSelectedElement();
17 if ( element
&& element
.getAttribute( 'type' ) == "checkbox" )
19 this.checkbox
= element
;
20 this.setupContent( element
);
26 element
= this.checkbox
,
27 isInsertMode
= !element
;
31 editor
= this.getParentEditor();
32 element
= editor
.document
.createElement( 'input' );
33 element
.setAttribute( 'type', 'checkbox' );
37 editor
.insertElement( element
);
38 this.commitContent( { element
: element
} );
43 label
: editor
.lang
.checkboxAndRadio
.checkboxTitle
,
44 title
: editor
.lang
.checkboxAndRadio
.checkboxTitle
,
45 startupFocus
: 'txtName',
50 label
: editor
.lang
.common
.name
,
53 setup : function( element
)
56 element
.getAttribute( '_cke_saved_name' ) ||
57 element
.getAttribute( 'name' ) ||
60 commit : function( data
)
62 var element
= data
.element
;
64 // IE failed to update 'name' property on input elements, protect it now.
65 if ( this.getValue() )
66 element
.setAttribute( '_cke_saved_name', this.getValue() );
69 element
.removeAttribute( '_cke_saved_name' );
70 element
.removeAttribute( 'name' );
77 label
: editor
.lang
.checkboxAndRadio
.value
,
80 setup : function( element
)
82 var value
= element
.getAttribute( 'value' );
83 // IE Return 'on' as default attr value.
84 this.setValue( CKEDITOR
.env
.ie
&& value
== 'on' ? '' : value
);
86 commit : function( data
)
88 var element
= data
.element
,
89 value
= this.getValue();
91 if ( value
&& !( CKEDITOR
.env
.ie
&& value
== 'on' ) )
92 element
.setAttribute( 'value', value
);
95 if ( CKEDITOR
.env
.ie
)
97 // Remove attribute 'value' of checkbox #4721.
98 var checkbox
= new CKEDITOR
.dom
.element( 'input', element
.getDocument() );
99 element
.copyAttributes( checkbox
, { value
: 1 } );
100 checkbox
.replace( element
);
101 editor
.getSelection().selectElement( checkbox
);
102 data
.element
= checkbox
;
105 element
.removeAttribute( 'value' );
112 label
: editor
.lang
.checkboxAndRadio
.selected
,
116 setup : function( element
)
118 this.setValue( element
.getAttribute( 'checked' ) );
120 commit : function( data
)
122 var element
= data
.element
;
124 if ( CKEDITOR
.env
.ie
)
126 var isElementChecked
= !!element
.getAttribute( 'checked' );
127 var isChecked
= !!this.getValue();
129 if ( isElementChecked
!= isChecked
)
131 var replace
= CKEDITOR
.dom
.element
.createFromHtml( '<input type="checkbox"'
132 + ( isChecked
? ' checked="checked"' : '' )
133 + '/>', editor
.document
);
135 element
.copyAttributes( replace
, { type
: 1, checked
: 1 } );
136 replace
.replace( element
);
137 editor
.getSelection().selectElement( replace
);
138 data
.element
= replace
;
143 var value
= this.getValue();
145 element
.setAttribute( 'checked', 'checked' );
147 element
.removeAttribute( 'checked' );