]> git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/forms/dialogs/checkbox.js
Initial commit
[perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git] / sources / plugins / forms / dialogs / checkbox.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
6 CKEDITOR.dialog.add( 'checkbox', function( editor ) {
7 return {
8 title: editor.lang.forms.checkboxAndRadio.checkboxTitle,
9 minWidth: 350,
10 minHeight: 140,
11 onShow: function() {
12 delete this.checkbox;
13
14 var element = this.getParentEditor().getSelection().getSelectedElement();
15
16 if ( element && element.getAttribute( 'type' ) == 'checkbox' ) {
17 this.checkbox = element;
18 this.setupContent( element );
19 }
20 },
21 onOk: function() {
22 var editor,
23 element = this.checkbox,
24 isInsertMode = !element;
25
26 if ( isInsertMode ) {
27 editor = this.getParentEditor();
28 element = editor.document.createElement( 'input' );
29 element.setAttribute( 'type', 'checkbox' );
30 editor.insertElement( element );
31 }
32 this.commitContent( { element: element } );
33 },
34 contents: [ {
35 id: 'info',
36 label: editor.lang.forms.checkboxAndRadio.checkboxTitle,
37 title: editor.lang.forms.checkboxAndRadio.checkboxTitle,
38 startupFocus: 'txtName',
39 elements: [ {
40 id: 'txtName',
41 type: 'text',
42 label: editor.lang.common.name,
43 'default': '',
44 accessKey: 'N',
45 setup: function( element ) {
46 this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' );
47 },
48 commit: function( data ) {
49 var element = data.element;
50
51 // IE failed to update 'name' property on input elements, protect it now.
52 if ( this.getValue() )
53 element.data( 'cke-saved-name', this.getValue() );
54 else {
55 element.data( 'cke-saved-name', false );
56 element.removeAttribute( 'name' );
57 }
58 }
59 },
60 {
61 id: 'txtValue',
62 type: 'text',
63 label: editor.lang.forms.checkboxAndRadio.value,
64 'default': '',
65 accessKey: 'V',
66 setup: function( element ) {
67 var value = element.getAttribute( 'value' );
68 // IE Return 'on' as default attr value.
69 this.setValue( CKEDITOR.env.ie && value == 'on' ? '' : value );
70 },
71 commit: function( data ) {
72 var element = data.element,
73 value = this.getValue();
74
75 if ( value && !( CKEDITOR.env.ie && value == 'on' ) )
76 element.setAttribute( 'value', value );
77 else {
78 if ( CKEDITOR.env.ie ) {
79 // Remove attribute 'value' of checkbox (#4721).
80 var checkbox = new CKEDITOR.dom.element( 'input', element.getDocument() );
81 element.copyAttributes( checkbox, { value: 1 } );
82 checkbox.replace( element );
83 editor.getSelection().selectElement( checkbox );
84 data.element = checkbox;
85 } else {
86 element.removeAttribute( 'value' );
87 }
88 }
89 }
90 },
91 {
92 id: 'cmbSelected',
93 type: 'checkbox',
94 label: editor.lang.forms.checkboxAndRadio.selected,
95 'default': '',
96 accessKey: 'S',
97 value: 'checked',
98 setup: function( element ) {
99 this.setValue( element.getAttribute( 'checked' ) );
100 },
101 commit: function( data ) {
102 var element = data.element;
103
104 if ( CKEDITOR.env.ie ) {
105 var isElementChecked = !!element.getAttribute( 'checked' ),
106 isChecked = !!this.getValue();
107
108 if ( isElementChecked != isChecked ) {
109 var replace = CKEDITOR.dom.element.createFromHtml( '<input type="checkbox"' + ( isChecked ? ' checked="checked"' : '' ) +
110 '/>', editor.document );
111
112 element.copyAttributes( replace, { type: 1, checked: 1 } );
113 replace.replace( element );
114 editor.getSelection().selectElement( replace );
115 data.element = replace;
116 }
117 } else {
118 var value = this.getValue();
119 if ( value )
120 element.setAttribute( 'checked', 'checked' );
121 else
122 element.removeAttribute( 'checked' );
123 }
124 }
125 },
126 {
127 id: 'required',
128 type: 'checkbox',
129 label: editor.lang.forms.checkboxAndRadio.required,
130 'default': '',
131 accessKey: 'Q',
132 value: 'required',
133 setup: function( element ) {
134 this.setValue( element.getAttribute( 'required' ) );
135 },
136 commit: function( data ) {
137 var element = data.element;
138 if ( this.getValue() )
139 element.setAttribute( 'required', 'required' );
140 else
141 element.removeAttribute( 'required' );
142 }
143 } ]
144 } ]
145 };
146 } );