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