8c6e4d25d9494f388cbe0c224f15bd0c7d2b0746
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( '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' );
34 editor
.insertElement( element
);
36 this.commitContent( { element
: element
} );
41 label
: editor
.lang
.checkboxAndRadio
.checkboxTitle
,
42 title
: editor
.lang
.checkboxAndRadio
.checkboxTitle
,
43 startupFocus
: 'txtName',
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 // IE failed to update 'name' property on input elements, protect it now.
63 if ( this.getValue() )
64 element
.data( 'cke-saved-name', this.getValue() );
67 element
.data( 'cke-saved-name', false );
68 element
.removeAttribute( 'name' );
75 label
: editor
.lang
.checkboxAndRadio
.value
,
78 setup : function( element
)
80 var value
= element
.getAttribute( 'value' );
81 // IE Return 'on' as default attr value.
82 this.setValue( CKEDITOR
.env
.ie
&& value
== 'on' ? '' : value
);
84 commit : function( data
)
86 var element
= data
.element
,
87 value
= this.getValue();
89 if ( value
&& !( CKEDITOR
.env
.ie
&& value
== 'on' ) )
90 element
.setAttribute( 'value', value
);
93 if ( CKEDITOR
.env
.ie
)
95 // Remove attribute 'value' of checkbox (#4721).
96 var checkbox
= new CKEDITOR
.dom
.element( 'input', element
.getDocument() );
97 element
.copyAttributes( checkbox
, { value
: 1 } );
98 checkbox
.replace( element
);
99 editor
.getSelection().selectElement( checkbox
);
100 data
.element
= checkbox
;
103 element
.removeAttribute( 'value' );
110 label
: editor
.lang
.checkboxAndRadio
.selected
,
114 setup : function( element
)
116 this.setValue( element
.getAttribute( 'checked' ) );
118 commit : function( data
)
120 var element
= data
.element
;
122 if ( CKEDITOR
.env
.ie
)
124 var isElementChecked
= !!element
.getAttribute( 'checked' ),
125 isChecked
= !!this.getValue();
127 if ( isElementChecked
!= isChecked
)
129 var replace
= CKEDITOR
.dom
.element
.createFromHtml( '<input type="checkbox"'
130 + ( isChecked
? ' checked="checked"' : '' )
131 + '/>', editor
.document
);
133 element
.copyAttributes( replace
, { type
: 1, checked
: 1 } );
134 replace
.replace( element
);
135 editor
.getSelection().selectElement( replace
);
136 data
.element
= replace
;
141 var value
= this.getValue();
143 element
.setAttribute( 'checked', 'checked' );
145 element
.removeAttribute( 'checked' );