Importation initiale du code de CKEditor 3.6.1.
[ckeditor.git] / _source / plugins / forms / dialogs / radio.js
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
5 CKEDITOR.dialog.add( 'radio', function( editor )
6 {
7 return {
8 title : editor.lang.checkboxAndRadio.radioTitle,
9 minWidth : 350,
10 minHeight : 140,
11 onShow : function()
12 {
13 delete this.radioButton;
14
15 var element = this.getParentEditor().getSelection().getSelectedElement();
16 if ( element && element.getName() == 'input' && element.getAttribute( 'type' ) == 'radio' )
17 {
18 this.radioButton = element;
19 this.setupContent( element );
20 }
21 },
22 onOk : function()
23 {
24 var editor,
25 element = this.radioButton,
26 isInsertMode = !element;
27
28 if ( isInsertMode )
29 {
30 editor = this.getParentEditor();
31 element = editor.document.createElement( 'input' );
32 element.setAttribute( 'type', 'radio' );
33 }
34
35 if ( isInsertMode )
36 editor.insertElement( element );
37 this.commitContent( { element : element } );
38 },
39 contents : [
40 {
41 id : 'info',
42 label : editor.lang.checkboxAndRadio.radioTitle,
43 title : editor.lang.checkboxAndRadio.radioTitle,
44 elements : [
45 {
46 id : 'name',
47 type : 'text',
48 label : editor.lang.common.name,
49 'default' : '',
50 accessKey : 'N',
51 setup : function( element )
52 {
53 this.setValue(
54 element.data( 'cke-saved-name' ) ||
55 element.getAttribute( 'name' ) ||
56 '' );
57 },
58 commit : function( data )
59 {
60 var element = data.element;
61
62 if ( this.getValue() )
63 element.data( 'cke-saved-name', this.getValue() );
64 else
65 {
66 element.data( 'cke-saved-name', false );
67 element.removeAttribute( 'name' );
68 }
69 }
70 },
71 {
72 id : 'value',
73 type : 'text',
74 label : editor.lang.checkboxAndRadio.value,
75 'default' : '',
76 accessKey : 'V',
77 setup : function( element )
78 {
79 this.setValue( element.getAttribute( 'value' ) || '' );
80 },
81 commit : function( data )
82 {
83 var element = data.element;
84
85 if ( this.getValue() )
86 element.setAttribute( 'value', this.getValue() );
87 else
88 element.removeAttribute( 'value' );
89 }
90 },
91 {
92 id : 'checked',
93 type : 'checkbox',
94 label : editor.lang.checkboxAndRadio.selected,
95 'default' : '',
96 accessKey : 'S',
97 value : "checked",
98 setup : function( element )
99 {
100 this.setValue( element.getAttribute( 'checked' ) );
101 },
102 commit : function( data )
103 {
104 var element = data.element;
105
106 if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera ) )
107 {
108 if ( this.getValue() )
109 element.setAttribute( 'checked', 'checked' );
110 else
111 element.removeAttribute( 'checked' );
112 }
113 else
114 {
115 var isElementChecked = element.getAttribute( 'checked' );
116 var isChecked = !!this.getValue();
117
118 if ( isElementChecked != isChecked )
119 {
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;
127 }
128 }
129 }
130 }
131 ]
132 }
133 ]
134 };
135 });